3 #include <sys/resource.h>
4 #include "threadimpl.h"
11 static int threadpassfd;
12 static int gotsigchld;
20 notedisable("sys: child");
21 pid = waitpid(sigpid, &status, 0);
23 fprint(2, "%s: wait: %r\n", argv0);
27 _exit(WEXITSTATUS(status));
28 if(WIFSIGNALED(status)){
30 * Make sure we don't scribble over the nice
31 * core file that our child just wrote out.
35 setrlimit(RLIMIT_CORE, &rl);
37 signal(WTERMSIG(status), SIG_DFL);
38 raise(WTERMSIG(status));
39 _exit(98); /* not reached */
41 if(WIFSTOPPED(status)){
42 fprint(2, "%s: wait pid %d stopped\n", argv0, pid);
46 if(WIFCONTINUED(status)){
47 fprint(2, "%s: wait pid %d continued\n", argv0, pid);
51 fprint(2, "%s: wait pid %d status 0x%ux\n", argv0, pid, status);
71 SIGHUP, SIGINT, SIGQUIT, SIGILL,
72 SIGTRAP, SIGABRT, SIGBUS, SIGFPE,
73 SIGUSR1, SIGSEGV, SIGUSR2, SIGPIPE,
74 SIGALRM, SIGTERM, SIGCHLD, SIGSTOP,
75 SIGTSTP, SIGTTIN, SIGTTOU, SIGURG,
76 SIGXCPU, SIGXFSZ, SIGVTALRM, SIGPROF,
91 _threadsetupdaemonize(void)
100 sysfatal("passer pipe: %r");
102 /* hide these somewhere they won't cause harm */
103 /* can't go too high: NetBSD max is 64, for example */
104 if(dup(p[0], 28) < 0 || dup(p[1], 29) < 0)
105 sysfatal("passer pipe dup: %r");
112 if(fcntl(p[0], F_SETFD, 1) < 0 || fcntl(p[1], F_SETFD, 1) < 0)
113 sysfatal("passer pipe pipe fcntl: %r");
115 noteenable("sys: child");
116 signal(SIGCHLD, sigpass);
117 switch(pid = fork()){
119 sysfatal("passer fork: %r");
124 for(i=0; i<100; i++) sched_yield();
125 notedisable("sys: child");
126 signal(SIGCHLD, SIG_DFL);
127 /* rfork(RFNOTEG); */
137 for(i=0; i<nelem(sigs); i++){
140 memset(&sa, 0, sizeof sa);
141 sa.sa_handler = sigpass;
142 sa.sa_flags |= SA_RESTART;
143 sigaction(sigs[i], &sa, nil);
147 n = read(p[0], buf, sizeof buf-1);
148 if(n == 0){ /* program exited */
153 print("passer read: %r\n");
160 _threaddaemonize(void)
162 if(threadpassfd >= 0){
163 write(threadpassfd, "0", 1);