void
Job::startControl(pid_t p, int fd)
{
- if (jci) {
- delete jci;
- jci = NULL;
- }
+ // Order is important here.
+ // 1) We need to guaranted that jci is NULL and not needed, incase
+ // our SIGCHLD comes before we get to delete it.
+ // 2) We want our child pid noted as soon as possible (once we're sure
+ // jci is taken care of)
+ // And then we can worry about deleting and linking fd...
+ JobControlInfo *tmp_jci = jci;
+ jci = NULL;
+ Dispatcher::instance().startChild(pid = p, &ctrlHandler);
+
+ if (tmp_jci)
+ delete tmp_jci;
+
ctrlHandler.fd = fd;
Dispatcher::instance().link(fd, Dispatcher::ReadMask, &ctrlHandler);
- Dispatcher::instance().startChild(pid = p, &ctrlHandler);
}
fxStr
_exit(255);
/*NOTREACHED*/
default: // parent, read from pipe and wait
+ job.startControl(pid, pfd[0]); // First, get our child PID handled
Sys::close(pfd[1]);
-
- job.startControl(pid, pfd[0]);
-
}
}
if (jobCtrlWait)