fd_noinherit (pipedes[0]);
{
- struct output out;
- out.syncout = 1;
- out.out = pipedes[1];
- out.err = errfd;
+ struct childbase child;
+ child.cmd_name = NULL;
+ child.output.syncout = 1;
+ child.output.out = pipedes[1];
+ child.output.err = errfd;
+ child.environment = envp;
- pid = child_execute_job (&out, 1, command_argv, envp);
+ pid = child_execute_job (&child, 1, command_argv);
+
+ free (child.cmd_name);
}
if (pid < 0)
child->remote = 0;
#ifdef VMS
- if (!child_execute_job (child, argv))
- child->pid = -1;
+ child->pid = child_execute_job ((struct childbase *)child, 1, argv);
#else
jobserver_pre_child (flags & COMMANDS_RECURSE);
- child->pid = child_execute_job (&child->output, child->good_stdin,
- argv, child->environment);
+ child->pid = child_execute_job ((struct childbase *)child,
+ child->good_stdin, argv);
environ = parent_environ; /* Restore value child may have clobbered. */
jobserver_post_child (flags & COMMANDS_RECURSE);
/* EMX: Start a child process. This function returns the new pid. */
# if defined __EMX__
pid_t
-child_execute_job (struct output *out, int good_stdin, char **argv, char **envp)
+child_execute_job (struct childbase *child, int good_stdin, char **argv)
{
pid_t pid;
int fdin = good_stdin ? FD_STDIN : get_bad_stdin ();
int save_fderr = -1;
/* Divert child output if we want to capture output. */
- if (out && out->syncout)
+ if (child->output.syncout)
{
- if (out->out >= 0)
- fdout = out->out;
- if (out->err >= 0)
- fderr = out->err;
+ if (child->output.out >= 0)
+ fdout = child->output.out;
+ if (child->output.err >= 0)
+ fderr = child->output.err;
}
/* For each FD which needs to be redirected first make a dup of the standard
}
/* Run the command. */
- pid = exec_command (argv, envp);
+ pid = exec_command (argv, child->environment);
/* Restore stdout/stdin/stderr of the parent and close temporary FDs. */
if (save_fdin >= 0)
/* POSIX:
Create a child process executing the command in ARGV.
- ENVP is the environment of the new program. Returns the PID or -1. */
+ Returns the PID or -1. */
pid_t
-child_execute_job (struct output *out, int good_stdin, char **argv, char **envp)
+child_execute_job (struct childbase *child, int good_stdin, char **argv)
{
const int fdin = good_stdin ? FD_STDIN : get_bad_stdin ();
int fdout = FD_STDOUT;
#endif
/* Divert child output if we want to capture it. */
- if (out && out->syncout)
+ if (child->output.syncout)
{
- if (out->out >= 0)
- fdout = out->out;
- if (out->err >= 0)
- fderr = out->err;
+ if (child->output.out >= 0)
+ fdout = child->output.out;
+ if (child->output.err >= 0)
+ fderr = child->output.err;
}
#if !defined(USE_POSIX_SPAWN)
EINTRLOOP (r, dup2 (fderr, FD_STDERR));
/* Run the command. */
- exec_command (argv, envp);
+ exec_command (argv, child->environment);
#else /* use posix_spawn() */
goto cleanup;
/* Start the program. */
- while ((r = posix_spawnp (&pid, argv[0], &fa, &attr, argv, envp)) == EINTR)
+ while ((r = posix_spawnp (&pid, argv[0], &fa, &attr, argv, child->environment)) == EINTR)
;
cleanup:
/* Structure describing a running or dead child process. */
+#ifdef VMS
+#define VMSCHILD \
+ char *comname; /* Temporary command file name */ \
+ int efn; /* Completion event flag number */ \
+ int cstatus; /* Completion status */ \
+ int vms_launch_status; /* non-zero if lib$spawn, etc failed */
+#else
+#define VMSCHILD
+#endif
+
+#define CHILDBASE \
+ char *cmd_name; /* Alloced copy of command run. */ \
+ char **environment; /* Environment for commands. */ \
+ VMSCHILD \
+ struct output output /* Output for this child. */
+
+
+struct childbase
+ {
+ CHILDBASE;
+ };
+
struct child
{
+ CHILDBASE;
+
struct child *next; /* Link in the chain. */
struct file *file; /* File being remade. */
- char **environment; /* Environment for commands. */
-
char *sh_batch_file; /* Script file for shell commands */
char **command_lines; /* Array of variable-expanded cmd lines. */
char *command_ptr; /* Ptr into command_lines[command_line]. */
- char *cmd_name; /* Alloced copy of argv[0] that was run. */
-
- struct output output; /* Output for this child. */
-
-#ifdef VMS
- char *comname; /* Temporary command file name */
- int efn; /* Completion event flag number */
- int cstatus; /* Completion status */
- int vms_launch_status; /* non-zero if lib$spawn, etc failed */
-#endif
unsigned int command_line; /* Index into command_lines. */
- pid_t pid; /* Child process's ID number. */
+ pid_t pid; /* Child process's ID number. */
+
unsigned int remote:1; /* Nonzero if executing remotely. */
unsigned int noerror:1; /* Nonzero if commands contained a '-'. */
unsigned int good_stdin:1; /* Nonzero if this child has a good stdin. */
char **construct_command_argv (char *line, char **restp, struct file *file,
int cmd_flags, char** batch_file);
-#ifdef VMS
-int child_execute_job (struct child *child, char *argv);
-#else
-pid_t child_execute_job (struct output *out, int good_stdin,
- char **argv, char **envp);
-#endif
+pid_t child_execute_job (struct childbase *child, int good_stdin, char **argv);
#ifdef _AMIGA
void exec_command (char **argv) __attribute__ ((noreturn));
termination. */
pid_t pid;
int r;
- pid = child_execute_job (NULL, 1, nargv, environ);
+ struct childbase child;
+ child.cmd_name = NULL;
+ child.output.syncout = 0;
+ child.environment = environ;
+
+ pid = child_execute_job (&child, 1, nargv);
/* is this loop really necessary? */
do {
for (i = 0; switches[i].c != '\0'; ++i)
{
long_options[i].name = (char *) (switches[i].long_name == 0 ? "" :
- switches[i].long_name);
+ switches[i].long_name);
long_options[i].flag = 0;
long_options[i].val = switches[i].c;
if (short_option (switches[i].c))
inner mode level AST.
*/
static int
-vmsHandleChildTerm (struct child *child)
+vmsHandleChildTerm (struct childbase *cbase)
{
- int exit_code;
+ struct child *child = (struct child*)cbase;
struct child *lastc, *c;
int child_failed;
+ int exit_code;
/* The child efn is 0 when a built-in or null command is executed
successfully with out actually creating a child.
return cmd_dsc;
}
-int
-child_execute_job (struct child *child, char *argv)
+pid_t
+child_execute_job (struct childbase *child, int good_stdin UNUSED, char *argv)
{
int i;
/* Only a built-in or a null command - Still need to run term AST */
child->cstatus = VMS_POSIX_EXIT_MASK;
child->vms_launch_status = SS$_NORMAL;
- /* TODO what is this "magic number" */
- child->pid = 270163; /* Special built-in */
child->efn = 0;
vmsHandleChildTerm (child);
- return 1;
+ /* TODO what is this "magic number" */
+ return 270163; /* Special built-in */
}
sprintf (procname, "GMAKE_%05x", getpid () & 0xfffff);
free (cmd_tokens[cmd_tkn_index++]);
child->cstatus = VMS_POSIX_EXIT_MASK | (MAKE_TROUBLE << 3);
child->vms_launch_status = SS$_ABORT;
- /* TODO what is this "magic number" */
- child->pid = 270163; /* Special built-in */
child->efn = 0;
errno = token.cmd_errno;
- return 0;
+ return -1;
}
/* Save any redirection to append file */
free (cmd_dsc);
child->cstatus = VMS_POSIX_EXIT_MASK | (MAKE_TROUBLE << 3);
child->vms_launch_status = SS$_ABORT;
- /* TODO what is this "magic number" */
- child->pid = 270163; /* Special built-in */
child->efn = 0;
- return 0;
+ return -1;
}
/* Only a built-in or a null command - Still need to run term AST */
free (cmd_dsc);
child->cstatus = VMS_POSIX_EXIT_MASK;
child->vms_launch_status = SS$_NORMAL;
- /* TODO what is this "magic number" */
- child->pid = 270163; /* Special built-in */
child->efn = 0;
vmsHandleChildTerm (child);
- return 1;
+ /* TODO what is this "magic number" */
+ return 270163; /* Special built-in */
}
if (cmd_dsc->dsc$w_length > MAX_DCL_LINE_LENGTH)
unlink (child->comname);
free (child->comname);
}
- return 0;
+ return -1;
}
}
}
}
- return (status & 1);
+ /* TODO what is this "magic number" */
+ return (status & 1) ? 270163 : -1 ;
}