:: Re: [DNG] Custom OS initiator. In n…
Αρχική Σελίδα
Delete this message
Reply to this message
Συντάκτης: Edward Bartolo
Ημερομηνία:  
Προς: dng, Steve Litt
Αντικείμενο: Re: [DNG] Custom OS initiator. In need of some hints...
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