summaryrefslogtreecommitdiffstats
path: root/usr.bin/make
diff options
context:
space:
mode:
authorharti <harti@FreeBSD.org>2005-05-12 10:55:37 +0000
committerharti <harti@FreeBSD.org>2005-05-12 10:55:37 +0000
commit99e68afe6ff3b314e25f6c9974c9b661f26d06a8 (patch)
tree5309bc774da77edc25eb83db2dd9f1eea9d718b1 /usr.bin/make
parent64956650a5dc627bf3fa2403cfcb2a83bbe8fc45 (diff)
downloadFreeBSD-src-99e68afe6ff3b314e25f6c9974c9b661f26d06a8.zip
FreeBSD-src-99e68afe6ff3b314e25f6c9974c9b661f26d06a8.tar.gz
Make a function ProcWait() that waits for the given process.
Submitted by: Max Okumoto <okumoto@ucsd.edu> (7.227)
Diffstat (limited to 'usr.bin/make')
-rw-r--r--usr.bin/make/job.c51
1 files changed, 31 insertions, 20 deletions
diff --git a/usr.bin/make/job.c b/usr.bin/make/job.c
index 72498f0..4f4ef61 100644
--- a/usr.bin/make/job.c
+++ b/usr.bin/make/job.c
@@ -475,6 +475,8 @@ typedef struct ProcStuff {
int searchpath; /* true if binary should be found via $PATH */
char **argv;
+
+ pid_t child_pid;
} ProcStuff;
static void JobRestart(Job *);
@@ -578,6 +580,24 @@ ProcExec(const ProcStuff *ps)
}
/**
+ */
+static int
+ProcWait(ProcStuff *ps)
+{
+ pid_t pid;
+ int status;
+
+ /*
+ * Wait for the process to exit.
+ */
+ while (((pid = wait(&status)) != ps->child_pid) && (pid >= 0)) {
+ continue;
+ }
+
+ return (status);
+}
+
+/**
* JobCatchSignal
* Got a signal. Set global variables and hope that someone will
* handle it.
@@ -1279,7 +1299,6 @@ static void
JobExec(Job *job, char **argv)
{
ProcStuff ps;
- pid_t cpid; /* ID of new child */
if (DEBUG(JOB)) {
int i;
@@ -1331,11 +1350,11 @@ JobExec(Job *job, char **argv)
* Fork. Warning since we are doing vfork() instead of fork(),
* do not allocate memory in the child process!
*/
- if ((cpid = vfork()) == -1) {
+ if ((ps.child_pid = vfork()) == -1) {
Punt("Cannot fork");
- }
- if (cpid == 0) {
+
+ } else if (ps.child_pid == 0) {
/*
* Child
*/
@@ -1345,10 +1364,11 @@ JobExec(Job *job, char **argv)
ProcExec(&ps);
/* NOTREACHED */
}
+
/*
* Parent
*/
- job->pid = cpid;
+ job->pid = ps.child_pid;
if (usePipes && (job->flags & JOB_FIRST)) {
/*
@@ -2966,8 +2986,6 @@ Buffer *
Cmd_Exec(const char *cmd, const char **error)
{
int fds[2]; /* Pipe streams */
- int cpid; /* Child PID */
- int pid; /* PID from wait() */
int status; /* command exit status */
Buffer *buf; /* buffer to store the result */
ssize_t rcnt;
@@ -3008,12 +3026,11 @@ Cmd_Exec(const char *cmd, const char **error)
* Fork. Warning since we are doing vfork() instead of fork(),
* do not allocate memory in the child process!
*/
- if ((cpid = vfork()) == -1) {
+ if ((ps.child_pid = vfork()) == -1) {
*error = "Couldn't exec \"%s\"";
return (buf);
- }
- if (cpid == 0) {
+ } else if (ps.child_pid == 0) {
/*
* Child
*/
@@ -3044,11 +3061,7 @@ Cmd_Exec(const char *cmd, const char **error)
*/
close(fds[0]);
- /*
- * Wait for the process to exit.
- */
- while (((pid = wait(&status)) != cpid) && (pid >= 0))
- continue;
+ status = ProcWait(&ps);
if (status)
*error = "\"%s\" returned non-zero status";
@@ -3212,7 +3225,6 @@ Compat_RunCommand(char *cmd, GNode *gn)
Boolean errCheck; /* Check errors */
int reason; /* Reason for child's death */
int status; /* Description of child's death */
- int cpid; /* Child actually found */
ReturnStatus rstat; /* Status of fork */
LstNode *cmdNode; /* Node where current command is located */
char **av; /* Argument vector for thing to exec */
@@ -3322,11 +3334,10 @@ Compat_RunCommand(char *cmd, GNode *gn)
* Warning since we are doing vfork() instead of fork(),
* do not allocate memory in the child process!
*/
- if ((cpid = vfork()) == -1) {
+ if ((ps.child_pid = vfork()) == -1) {
Fatal("Could not fork");
- }
- if (cpid == 0) {
+ } else if (ps.child_pid == 0) {
/*
* Child
*/
@@ -3356,7 +3367,7 @@ Compat_RunCommand(char *cmd, GNode *gn)
* The child is off and running. Now all we can do is wait...
*/
while (1) {
- while ((rstat = wait(&reason)) != cpid) {
+ while ((rstat = wait(&reason)) != ps.child_pid) {
if (interrupted || (rstat == -1 && errno != EINTR)) {
break;
}
OpenPOWER on IntegriCloud