aboutsummaryrefslogtreecommitdiff
path: root/src/libthread/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/libthread/main.c')
-rw-r--r--src/libthread/main.c44
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