297 default:
298 return;
299 }
300 }
301 if (sticky_errno != 0)
302 errno = sticky_errno;
303 }
304 }
305
306 /**
307 * Child process after a successful fork().
308 * This function must not return, and must be prepared for either all
309 * of its address space to be shared with its parent, or to be a copy.
310 * It must not modify global variables such as "environ".
311 */
312 int
313 childProcess(void *arg)
314 {
315 const ChildStuff* p = (const ChildStuff*) arg;
316
317 /* Close the parent sides of the pipes.
318 Closing pipe fds here is redundant, since closeDescriptors()
319 would do it anyways, but a little paranoia is a good thing. */
320 if ((closeSafely(p->in[1]) == -1) ||
321 (closeSafely(p->out[0]) == -1) ||
322 (closeSafely(p->err[0]) == -1) ||
323 (closeSafely(p->childenv[0]) == -1) ||
324 (closeSafely(p->childenv[1]) == -1) ||
325 (closeSafely(p->fail[0]) == -1))
326 goto WhyCantJohnnyExec;
327
328 /* Give the child sides of the pipes the right fileno's. */
329 /* Note: it is possible for in[0] == 0 */
330 if ((moveDescriptor(p->in[0] != -1 ? p->in[0] : p->fds[0],
331 STDIN_FILENO) == -1) ||
332 (moveDescriptor(p->out[1]!= -1 ? p->out[1] : p->fds[1],
333 STDOUT_FILENO) == -1))
334 goto WhyCantJohnnyExec;
335
336 if (p->redirectErrorStream) {
|
297 default:
298 return;
299 }
300 }
301 if (sticky_errno != 0)
302 errno = sticky_errno;
303 }
304 }
305
306 /**
307 * Child process after a successful fork().
308 * This function must not return, and must be prepared for either all
309 * of its address space to be shared with its parent, or to be a copy.
310 * It must not modify global variables such as "environ".
311 */
312 int
313 childProcess(void *arg)
314 {
315 const ChildStuff* p = (const ChildStuff*) arg;
316
317 if (p->sendAlivePing) {
318 /* Child shall signal aliveness to parent at the very first
319 * moment. */
320 int code = CHILD_IS_ALIVE;
321 restartableWrite(p->fail[1], &code, sizeof(code));
322 }
323
324 /* Close the parent sides of the pipes.
325 Closing pipe fds here is redundant, since closeDescriptors()
326 would do it anyways, but a little paranoia is a good thing. */
327 if ((closeSafely(p->in[1]) == -1) ||
328 (closeSafely(p->out[0]) == -1) ||
329 (closeSafely(p->err[0]) == -1) ||
330 (closeSafely(p->childenv[0]) == -1) ||
331 (closeSafely(p->childenv[1]) == -1) ||
332 (closeSafely(p->fail[0]) == -1))
333 goto WhyCantJohnnyExec;
334
335 /* Give the child sides of the pipes the right fileno's. */
336 /* Note: it is possible for in[0] == 0 */
337 if ((moveDescriptor(p->in[0] != -1 ? p->in[0] : p->fds[0],
338 STDIN_FILENO) == -1) ||
339 (moveDescriptor(p->out[1]!= -1 ? p->out[1] : p->fds[1],
340 STDOUT_FILENO) == -1))
341 goto WhyCantJohnnyExec;
342
343 if (p->redirectErrorStream) {
|