:: Re: [DNG] Custom OS initiator. In n…
Página Principal
Delete this message
Reply to this message
Autor: Edward Bartolo
Data:  
Para: dng
Assunto: Re: [DNG] Custom OS initiator. In need of some hints...
Hi,

I wrote a small shell script, nothing special, mind you, that calls rc
S and then rc 2 if rc S is successful. With Felker's minimal init,
which I edited to call my script version, I was able to load a useable
XFCE4 session through which I am sending this email.

I am attaching both Felker's C code as I modified it and my little
shell script.

Now I would like to ask what is the need of the fork() call in
Felker's code. Yes, I know, it creates a child that continues
execution just after the fork call.

My reasoning goes like this. Since the parent process calling fork()
gets a return value consisting of the child's PID, the infinite loop
executes to reap zombies. Hence, the parent's execution end point is
the infinite loop. The created child inherits many aspects of its
parent and STARTS execution just after the fork() call but it gets a
return value of ZERO. This means, the child will not enter the
infinite loop and will call execve at the end. On termination, I
expect the child to exit. In the end, according to my reasoning, only
the parent should remain.

I checked with XFCE4 loaded how many instances of felker2.bin existed
and found that only one existed.

Edward
#define _XOPEN_SOURCE 700
#include <stdlib.h>
#include <signal.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>

int main() {
sigset_t set;
int status;

if (getpid() != 1) return 1;
sigfillset(&set);

  sigprocmask(SIG_BLOCK, &set, 0);   
  if (fork()) { 
    while(1) wait(&status);
  }  


sigprocmask(SIG_UNBLOCK, &set, 0);
setsid();
setpgid(0, 0);
return execve("/home/edbarx/init.mine/osloader.sh", (char *[]){ "osloader.sh", 0 }, (char *[]){ 0 });
}