aboutsummaryrefslogtreecommitdiff
path: root/usr.bin/make/main.c
diff options
context:
space:
mode:
authorHartmut Brandt <harti@FreeBSD.org>2005-05-10 13:18:58 +0000
committerHartmut Brandt <harti@FreeBSD.org>2005-05-10 13:18:58 +0000
commitc26295ddea669e7a5c836662f940eecf38c1d2d9 (patch)
tree0f0b7bb7b8694f1b5a99997b97103451a561847d /usr.bin/make/main.c
parent90931e9aa82cf72d36d33536d108c896c6726847 (diff)
Notes
Diffstat (limited to 'usr.bin/make/main.c')
-rw-r--r--usr.bin/make/main.c109
1 files changed, 0 insertions, 109 deletions
diff --git a/usr.bin/make/main.c b/usr.bin/make/main.c
index 4059ecb06a65..a6039e844934 100644
--- a/usr.bin/make/main.c
+++ b/usr.bin/make/main.c
@@ -1127,115 +1127,6 @@ found:
return (TRUE);
}
-/**
- * Cmd_Exec
- * Execute the command in cmd, and return the output of that command
- * in a string.
- *
- * Results:
- * A string containing the output of the command, or the empty string
- * If error is not NULL, it contains the reason for the command failure
- *
- * Side Effects:
- * The string must be freed by the caller.
- */
-Buffer *
-Cmd_Exec(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;
-
- *error = NULL;
- buf = Buf_Init(0);
-
- if (shellPath == NULL)
- Shell_Init();
- /*
- * Open a pipe for fetching its output
- */
- if (pipe(fds) == -1) {
- *error = "Couldn't create pipe for \"%s\"";
- return (buf);
- }
-
- /*
- * Fork
- */
- switch (cpid = vfork()) {
- case 0:
- /*
- * Close input side of pipe
- */
- close(fds[0]);
-
- /*
- * Duplicate the output stream to the shell's output, then
- * shut the extra thing down. Note we don't fetch the error
- * stream...why not? Why?
- */
- dup2(fds[1], 1);
- close(fds[1]);
-
- {
- char *args[4];
-
- /* Set up arguments for shell */
- args[0] = shellName;
- args[1] = "-c";
- args[2] = cmd;
- args[3] = NULL;
-
- execv(shellPath, args);
- _exit(1);
- /*NOTREACHED*/
- }
-
- case -1:
- *error = "Couldn't exec \"%s\"";
- return (buf);
-
- default:
- /*
- * No need for the writing half
- */
- close(fds[1]);
-
- do {
- char result[BUFSIZ];
-
- rcnt = read(fds[0], result, sizeof(result));
- if (rcnt != -1)
- Buf_AddBytes(buf, (size_t)rcnt, (Byte *)result);
- } while (rcnt > 0 || (rcnt == -1 && errno == EINTR));
-
- if (rcnt == -1)
- *error = "Error reading shell's output for \"%s\"";
-
- /*
- * Close the input side of the pipe.
- */
- close(fds[0]);
-
- /*
- * Wait for the process to exit.
- */
- while (((pid = wait(&status)) != cpid) && (pid >= 0))
- continue;
-
- if (status)
- *error = "\"%s\" returned non-zero status";
-
- Buf_StripNewlines(buf);
-
- break;
- }
- return (buf);
-}
-
/*
* usage --
* exit with usage message