:: Re: [DNG] Custom OS initiator. In n…
Etusivu
Poista viesti
Vastaa
Lähettäjä: Irrwahn
Päiväys:  
Vastaanottaja: dng
Uudet otsikot: [DNG] kill command does not match manual page.
Aihe: Re: [DNG] Custom OS initiator. In need of some hints...
On Tue, 14 Jun 2016 15:51:23 +0200, Edward Bartolo 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.


What does "man 1 wait" tell you?

> 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.


No. It cannot (better: should not), because it does not.

> The second if
> statement is essentially all the tiny init code.
>
> This is the C code:
> -----------------------------


Now *this* is borderline trolling!

> #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);


BOOOM! I just halted your init by simply using #kill -TSTP 1.
Your process list will soon be the digital equivalent of the
zombie apocalypse. See what can happen when messing with
stuff without having the slightest clue what it does? Did
you really think Felker is an idiot? You remind me of my
granny when she repeatedly "repaired" the radio by poking
around with an uninsulated bread knife. She always survived,
but only by sheer luck.

>     else return execve("/sbin/osloader.sh", (char *[]){
> "/sbin/osloader.sh", 0 }, (char *[]){ 0 });
> }


BTW, the compiler should have warned you about a missing
return statement at the end of main().

Regards
Urban