- sync = !(children->action_type & ACTION_ASYNC);
-
- chld_in[0] = chld_in[1] = chld_out[0] = chld_out[1] = chld_err[0]
- = chld_err[1] = chld_status[0] = chld_status[1] = -1;
-
- if (sync) {
- if (pipe(chld_status) || pipe(chld_in) || pipe(chld_out) ||
- pipe(chld_err)) {
- alertpanel_error(_("Command could not be started. "
- "Pipe creation failed.\n%s"),
- g_strerror(errno));
- /* Closing fd = -1 fails silently */
- (void)close(chld_in[0]);
- (void)close(chld_in[1]);
- (void)close(chld_out[0]);
- (void)close(chld_out[1]);
- (void)close(chld_err[0]);
- (void)close(chld_err[1]);
- (void)close(chld_status[0]);
- (void)close(chld_status[1]);
- return NULL; /* Pipe error */
- }
- }
-
- debug_print("Forking child and grandchild.\n");
- debug_print("Executing: /bin/sh -c %s\n", cmd);
-
- pid = fork();
- if (pid == 0) { /* Child */
- int r = 0;
- if (setpgid(0, 0))
- perror("setpgid");
-
- gch_pid = fork();
-
- if (gch_pid == 0) {
- if (setpgid(0, getppid()))
- perror("setpgid");
-
- if (sync) {
- if (children->action_type &
- (ACTION_PIPE_IN |
- ACTION_USER_IN |
- ACTION_USER_HIDDEN_IN)) {
- r |= close(fileno(stdin));
- if (dup(chld_in[0]) < 0)
- r = -1;
- }
- r |= close(chld_in[0]);
- r |= close(chld_in[1]);