Revision 9090,
1.1 KB
checked in by ghudson, 28 years ago
(diff) |
This commit was generated by cvs2svn to compensate for changes in r9089,
which included commits to RCS files with non-trunk default branches.
|
Rev | Line | |
---|
[9089] | 1 | /* Copyright Milan Technology, 1991 1992 */ |
---|
| 2 | /* @(#)system.c 2.0 10/9/92 */ |
---|
| 3 | |
---|
| 4 | #include <signal.h> |
---|
| 5 | #include "dp.h" |
---|
| 6 | #include "errors.h" |
---|
| 7 | |
---|
| 8 | #ifdef BSD |
---|
| 9 | #include <sys/wait.h> |
---|
| 10 | #endif |
---|
| 11 | |
---|
| 12 | |
---|
| 13 | #ifdef BSD |
---|
| 14 | void sig_child() |
---|
| 15 | { |
---|
| 16 | int pid; |
---|
| 17 | union wait status; |
---|
| 18 | while ((pid = wait3(&status,WNOHANG,(struct rusage*)0))>0); |
---|
| 19 | } |
---|
| 20 | #endif |
---|
| 21 | |
---|
| 22 | /* Makes a pipe, forks, makes the stdin in child come from |
---|
| 23 | * the read end of the pipe. Returns the write end of the |
---|
| 24 | * pipe to the parent. |
---|
| 25 | */ |
---|
| 26 | |
---|
| 27 | #ifdef ANSI |
---|
| 28 | int initPipes(char *cmd) |
---|
| 29 | #else |
---|
| 30 | int initPipes(cmd) |
---|
| 31 | char* cmd; |
---|
| 32 | #endif |
---|
| 33 | { |
---|
| 34 | int pipe_fd[2], pid; |
---|
| 35 | |
---|
| 36 | if (pipe(pipe_fd) < 0) |
---|
| 37 | error_protect(ERR_PIPE); |
---|
| 38 | if ((pid = fork()) < 0) |
---|
| 39 | error_protect(ERR_FORK); |
---|
| 40 | else if (pid > 0) { |
---|
| 41 | /* parent */ |
---|
| 42 | close(pipe_fd[readEnd]); |
---|
| 43 | return(pipe_fd[writeEnd]); |
---|
| 44 | } |
---|
| 45 | else { |
---|
| 46 | /* child */ |
---|
| 47 | /* make childs stdin come from read end of pipe */ |
---|
| 48 | if (pipe_fd[readEnd] != STDIN_FILENO) { |
---|
| 49 | dup2(pipe_fd[readEnd], STDIN_FILENO); |
---|
| 50 | close(pipe_fd[readEnd]); |
---|
| 51 | } |
---|
| 52 | close(pipe_fd[writeEnd]); |
---|
| 53 | execl("/bin/sh", "sh", "-c", cmd, (char*)0); |
---|
| 54 | } |
---|
| 55 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.