diff options
| author | rsc <devnull@localhost> | 2004-10-22 18:45:08 +0000 |
|---|---|---|
| committer | rsc <devnull@localhost> | 2004-10-22 18:45:08 +0000 |
| commit | 5093c3fa40717e78b0a63955640a8ac9071b5c07 (patch) | |
| tree | 10141d54500447e4e4fee9aa0b6f9c8d0bcc7352 /src/libthread/main.c | |
| parent | 048610b7ea50507c6987d5b0cc0c4810cda87d53 (diff) | |
| download | plan9port-5093c3fa40717e78b0a63955640a8ac9071b5c07.tar.gz plan9port-5093c3fa40717e78b0a63955640a8ac9071b5c07.zip | |
try to implement the daemonize hack.
Diffstat (limited to 'src/libthread/main.c')
| -rw-r--r-- | src/libthread/main.c | 44 |
1 files changed, 43 insertions, 1 deletions
diff --git a/src/libthread/main.c b/src/libthread/main.c index 83ee177c..ec085430 100644 --- a/src/libthread/main.c +++ b/src/libthread/main.c @@ -11,7 +11,11 @@ struct Mainarg char **argv; }; +int _threadmainpid; int mainstacksize; +int _callsthreaddaemonize; +static int passtomainpid; + extern void (*_sysfatal)(char*, va_list); static void @@ -25,15 +29,53 @@ mainlauncher(void *arg) threadexits("threadmain"); } +static void +passer(void *x, char *msg) +{ + USED(x); + Waitmsg *w; + + if(strcmp(msg, "sys: usr2") == 0) + _exit(0); /* daemonize */ + else if(strcmp(msg, "sys: child") == 0){ + w = wait(); + if(w == nil) + _exit(1); + _exit(atoi(w->msg)); + }else + postnote(PNPROC, passtomainpid, msg); +} + int main(int argc, char **argv) { + int pid; Mainarg a; Proc *p; + sigset_t mask; /* - * XXX Do daemonize hack here. + * Do daemonize hack here. */ + if(_callsthreaddaemonize){ + passtomainpid = getpid(); + switch(pid = fork()){ + case -1: + sysfatal("fork: %r"); + + case 0: + /* continue executing */ + _threadmainpid = getppid(); + break; + + default: + /* wait for signal USR2 */ + notify(passer); + for(;;) + pause(); + _exit(0); + } + } /* * Instruct QLock et al. to use our scheduling functions |
