diff options
author | harti <harti@FreeBSD.org> | 2005-05-24 15:41:34 +0000 |
---|---|---|
committer | harti <harti@FreeBSD.org> | 2005-05-24 15:41:34 +0000 |
commit | 30f40a9f33deb9ac30a76e5b9b8c3f063f9b2f16 (patch) | |
tree | 225c3028eb2888a81c3dfaea4f53b1b4c7a95bd7 /usr.bin/make/job.c | |
parent | d54bd1101b4a69648561353138ce0f7808949f51 (diff) | |
download | FreeBSD-src-30f40a9f33deb9ac30a76e5b9b8c3f063f9b2f16.zip FreeBSD-src-30f40a9f33deb9ac30a76e5b9b8c3f063f9b2f16.tar.gz |
Factor out ProcExec() into its own file and rename it to Proc_Exec() for
consistency with the rest of make.
Obtained from: DragonFlyBSD (except for the rename)
Diffstat (limited to 'usr.bin/make/job.c')
-rw-r--r-- | usr.bin/make/job.c | 125 |
1 files changed, 4 insertions, 121 deletions
diff --git a/usr.bin/make/job.c b/usr.bin/make/job.c index e4e04e5..71e4136 100644 --- a/usr.bin/make/job.c +++ b/usr.bin/make/job.c @@ -133,7 +133,7 @@ __FBSDID("$FreeBSD$"); #include "job.h" #include "make.h" #include "parse.h" -#include "pathnames.h" +#include "proc.h" #include "shell.h" #include "str.h" #include "suff.h" @@ -378,31 +378,11 @@ static sig_atomic_t interrupted; #define W_SETTERMSIG(st, val) W_SETMASKED(st, val, WTERMSIG) #define W_SETEXITSTATUS(st, val) W_SETMASKED(st, val, WEXITSTATUS) -/** - * Information used to create a new process. - */ -typedef struct ProcStuff { - int in; /* stdin for new process */ - int out; /* stdout for new process */ - int err; /* stderr for new process */ - - int merge_errors; /* true if stderr is redirected to stdin */ - int pgroup; /* true if new process a process leader */ - int searchpath; /* true if binary should be found via $PATH */ - - char **argv; - int argv_free; /* release argv after use */ - int errCheck; - - pid_t child_pid; -} ProcStuff; - static void JobRestart(Job *); static int JobStart(GNode *, int, Job *); static void JobDoOutput(Job *, Boolean); static void JobInterrupt(int, int); static void JobRestartJobs(void); -static void ProcExec(const ProcStuff *) __dead2; static int Compat_RunCommand(char *, struct GNode *); static GNode *curTarg = NULL; @@ -522,103 +502,6 @@ Proc_Init() } /** - * Replace the current process. - */ -static void -ProcExec(const ProcStuff *ps) -{ - - if (ps->in != STDIN_FILENO) { - /* - * Redirect the child's stdin to the input fd - * and reset it to the beginning (again). - */ - if (dup2(ps->in, STDIN_FILENO) == -1) - Punt("Cannot dup2: %s", strerror(errno)); - lseek(STDIN_FILENO, (off_t)0, SEEK_SET); - } - - if (ps->out != STDOUT_FILENO) { - /* - * Redirect the child's stdout to the output fd. - */ - if (dup2(ps->out, STDOUT_FILENO) == -1) - Punt("Cannot dup2: %s", strerror(errno)); - close(ps->out); - } - - if (ps->err != STDERR_FILENO) { - /* - * Redirect the child's stderr to the err fd. - */ - if (dup2(ps->err, STDERR_FILENO) == -1) - Punt("Cannot dup2: %s", strerror(errno)); - close(ps->err); - } - - if (ps->merge_errors) { - /* - * Send stderr to parent process too. - */ - if (dup2(STDOUT_FILENO, STDERR_FILENO) == -1) - Punt("Cannot dup2: %s", strerror(errno)); - } - - if (commandShell->unsetenv) { - /* for the benfit of ksh */ - unsetenv("ENV"); - } - - /* - * The file descriptors for stdin, stdout, or stderr might - * have been marked close-on-exec. Clear the flag on all - * of them. - */ - fcntl(STDIN_FILENO, F_SETFD, - fcntl(STDIN_FILENO, F_GETFD) & (~FD_CLOEXEC)); - fcntl(STDOUT_FILENO, F_SETFD, - fcntl(STDOUT_FILENO, F_GETFD) & (~FD_CLOEXEC)); - fcntl(STDERR_FILENO, F_SETFD, - fcntl(STDERR_FILENO, F_GETFD) & (~FD_CLOEXEC)); - - if (ps->pgroup) { -#ifdef USE_PGRP - /* - * Become a process group leader, so we can kill it and all - * its descendants in one fell swoop, by killing its process - * family, but not commit suicide. - */ -#if defined(SYSV) - setsid(); -#else - setpgid(0, getpid()); -#endif -#endif /* USE_PGRP */ - } - - if (ps->searchpath) { - execvp(ps->argv[0], ps->argv); - - write(STDERR_FILENO, ps->argv[0], strlen(ps->argv[0])); - write(STDERR_FILENO, ":", 1); - write(STDERR_FILENO, strerror(errno), strlen(strerror(errno))); - write(STDERR_FILENO, "\n", 1); - } else { - execv(commandShell->path, ps->argv); - - write(STDERR_FILENO, - "Could not execute shell\n", - sizeof("Could not execute shell")); - } - - /* - * Since we are the child process, exit without flushing buffers. - */ - _exit(1); - /* NOTREACHED */ -} - -/** * Wait for child process to terminate. */ static int @@ -1480,7 +1363,7 @@ JobExec(Job *job, char **argv) if (fifoFd >= 0) close(fifoFd); - ProcExec(&ps); + Proc_Exec(&ps); /* NOTREACHED */ } @@ -2824,7 +2707,7 @@ Cmd_Exec(const char *cmd, const char **error) /* * Child */ - ProcExec(&ps); + Proc_Exec(&ps); /* NOTREACHED */ } @@ -3114,7 +2997,7 @@ Compat_RunCommand(char *cmd, GNode *gn) /* * Child */ - ProcExec(&ps); + Proc_Exec(&ps); /* NOTREACHED */ } else { |