summaryrefslogtreecommitdiffstats
path: root/usr.bin/make
diff options
context:
space:
mode:
authorharti <harti@FreeBSD.org>2005-05-24 15:41:34 +0000
committerharti <harti@FreeBSD.org>2005-05-24 15:41:34 +0000
commit30f40a9f33deb9ac30a76e5b9b8c3f063f9b2f16 (patch)
tree225c3028eb2888a81c3dfaea4f53b1b4c7a95bd7 /usr.bin/make
parentd54bd1101b4a69648561353138ce0f7808949f51 (diff)
downloadFreeBSD-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')
-rw-r--r--usr.bin/make/Makefile4
-rw-r--r--usr.bin/make/job.c125
-rw-r--r--usr.bin/make/proc.c134
-rw-r--r--usr.bin/make/proc.h53
4 files changed, 193 insertions, 123 deletions
diff --git a/usr.bin/make/Makefile b/usr.bin/make/Makefile
index 7252a25..5aff3086 100644
--- a/usr.bin/make/Makefile
+++ b/usr.bin/make/Makefile
@@ -5,8 +5,8 @@
PROG= make
CFLAGS+=-I${.CURDIR}
SRCS= arch.c buf.c cond.c dir.c for.c hash.c hash_tables.c job.c \
- lst.c main.c make.c parse.c shell.c str.c suff.c targ.c util.c \
- var.c
+ lst.c main.c make.c parse.c proc.c shell.c str.c suff.c targ.c \
+ util.c var.c
NO_WERROR=
WARNS?= 3
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 {
diff --git a/usr.bin/make/proc.c b/usr.bin/make/proc.c
new file mode 100644
index 0000000..711f605
--- /dev/null
+++ b/usr.bin/make/proc.c
@@ -0,0 +1,134 @@
+/*-
+ * Copyright (C) 2005 Max Okumoto.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <unistd.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <fcntl.h>
+
+#include "proc.h"
+#include "shell.h"
+#include "util.h"
+
+/**
+ * Replace the current process.
+ */
+void
+Proc_Exec(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);
+}
diff --git a/usr.bin/make/proc.h b/usr.bin/make/proc.h
new file mode 100644
index 0000000..a4ce6d3
--- /dev/null
+++ b/usr.bin/make/proc.h
@@ -0,0 +1,53 @@
+/*-
+ * Copyright (C) 2005 Max Okumoto.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef proc_h_458845848
+#define proc_h_458845848
+
+/**
+ * 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;
+
+void Proc_Exec(const ProcStuff *) __dead2;
+
+#endif /* proc_h_458845848 */
OpenPOWER on IntegriCloud