21 if((flags&(RFPROC|RFFDG|RFMEM)) == (RFPROC|RFFDG)){
22 /* check other flags before we commit */
23 flags &= ~(RFPROC|RFFDG);
24 n = (flags & ~(RFNOTEG|RFNAMEG|RFNOWAIT));
26 werrstr("unknown flags %08ux in rfork", n);
31 * BUG - should put the signal handler back after we
32 * finish, but I just don't care. If a program calls with
33 * NOWAIT once, they're not likely to want child notes
47 * Parent - wait for child to fork wait-free child.
48 * Then read pid from pipe. Assume pipe buffer can absorb the write.
52 if(wait4(pid, &status, 0, 0) < 0){
53 werrstr("pipe dance - wait4 - %r");
57 n = readn(p[0], buf, sizeof buf-1);
59 if(!WIFEXITED(status) || WEXITSTATUS(status)!=0 || n <= 0){
60 if(!WIFEXITED(status))
61 werrstr("pipe dance - !exited 0x%ux", status);
62 else if(WEXITSTATUS(status) != 0)
63 werrstr("pipe dance - non-zero status 0x%ux", status);
65 werrstr("pipe dance - pipe read error - %r");
67 werrstr("pipe dance - pipe read eof");
69 werrstr("pipe dance - unknown failure");
77 pid = strtol(buf, &q, 0);
80 * Child - fork a new child whose wait message can't
81 * get back to the parent because we're going to exit!
83 signal(SIGCHLD, SIG_IGN);
87 /* Child parent - send status over pipe and exit. */
89 fprint(p[1], "%d", pid);
95 /* Child child - close pipe. */
104 werrstr("cannot use rfork for shared memory -- use ffork");
108 /* XXX set $NAMESPACE to a new directory */
112 setpgid(0, getpid());
116 werrstr("cannot use RFNOWAIT without RFPROC");
120 werrstr("unknown flags %08ux in rfork", flags);