:: Re: [DNG] Custom OS initiator. In n…
Αρχική Σελίδα
Delete this message
Reply to this message
Συντάκτης: Steve Litt
Ημερομηνία:  
Προς: dng
Αντικείμενο: Re: [DNG] Custom OS initiator. In need of some hints...
On Tue, 14 Jun 2016 15:51:23 +0200
Edward Bartolo <edbarx@???> wrote:

> Hi,
>
> I am trying to implement a small shell script to serve as an init but
> I am failing to find C equivalent functions to wait(int) and
> fork(void). These two functions are essential to create an init as
> zombies have to be somehow reaped. In a shell script I can append & to
> a statement to make it run in the background. The latter can enable me
> to run the infinite loop in the background but I still need to have an
> equivalent of wait(int) to wait on child processes to reap zombies.
>
> Regarding the C version of Felker's init, I removed even more lines
> from it reducing it to just two if statements. The first one can be
> omitted altogether as it only checks the user is root. The second if
> statement is essentially all the tiny init code.
>
> This is the C code:
> -----------------------------
> #include <stdlib.h>
> #include <unistd.h>
> #include <sys/wait.h>
> //#include <errno.h>
> //#include <stdio.h>
> //#include <signal.h>
>
> int main() {
> if (getpid() != 1) return 1;
>
>   int status;
>   if (fork()) while(1) wait(&status);
>     else return execve("/sbin/osloader.sh", (char *[]){
> "/sbin/osloader.sh", 0 }, (char *[]){ 0 });
> }
> ---------------------------

>
> I tested the above with a different path to a directory inside my home
> directory but the above should work.
>
> Edward


Hi Edward,

When you code your shellscript, I **HIGHLY** suggest you perform all
the functions that Felker did. The fact that you can init without
messing with the signals receivable or the PID and GID is interesting
(and I wouldn't have expected it), but Felker's the guy who created
the MUSL compiler, he's pretty smart, his priority was simplest
possible PID1, so he wouldn't have had that stuff in there without
good reason. I fear that without specifying signals handled or
rejected, PID and GID, your shellscript init will "work", but in corner
cases will do something weird that will be very hard to debug.

If I were you, I'd find /bin/sh statements to substitute for ever
statement Felker puts in his init. That way, when your init works
*every time*, it will make Lennart and the Redhats, and all their
screaming, adoring fans, look like the bozos they are. On the other
hand, if your init sometimes fails, it makes *us* look bad.

SteveT

Steve Litt
June 2016 featured book: Troubleshooting: Why Bother?
http://www.troubleshooters.com/twb