3 #include <sys/resource.h>
4 #include "threadimpl.h"
11 static int threadpassfd;
19 notedisable("sys: child");
20 pid = waitpid(sigpid, &status, 0);
22 fprint(2, "%s: wait: %r\n", argv0);
26 _exit(WEXITSTATUS(status));
27 if(WIFSIGNALED(status)){
29 * Make sure we don't scribble over the nice
30 * core file that our child just wrote out.
34 setrlimit(RLIMIT_CORE, &rl);
36 signal(WTERMSIG(status), SIG_DFL);
37 raise(WTERMSIG(status));
38 _exit(98); /* not reached */
40 fprint(2, "%s: wait pid %d status 0x%ux\n", pid, status);
54 _threadsetupdaemonize(void)
65 sysfatal("passer pipe: %r");
67 /* hide these somewhere they won't cause harm */
68 if(dup(p[0], 98) < 0 || dup(p[1], 99) < 0)
69 sysfatal("passer pipe dup: %r");
76 if(fcntl(p[0], F_SETFD, 1) < 0 || fcntl(p[1], F_SETFD, 1) < 0)
77 sysfatal("passer pipe pipe fcntl: %r");
79 noteenable("sys: child");
80 signal(SIGCHLD, sigpass);
83 sysfatal("passer fork: %r");
88 for(i=0; i<100; i++) sched_yield();
89 notedisable("sys: child");
90 signal(SIGCHLD, SIG_DFL);
98 for(i=0; i<NSIG; i++){
101 memset(&sa, 0, sizeof sa);
102 sa.sa_handler = sigpass;
103 sa.sa_flags |= SA_RESTART;
104 sigaction(i, &sa, nil);
108 n = read(p[0], buf, sizeof buf-1);
109 if(n == 0){ /* program exited */
114 print("passer read: %r\n");
121 _threaddaemonize(void)
123 if(threadpassfd >= 0){
124 write(threadpassfd, "0", 1);