Commit | Line | Data |
---|---|---|
60de5df9 | 1 | /* |
46e9ea25 KB |
2 | * Copyright (c) 1983 Regents of the University of California. |
3 | * All rights reserved. | |
4 | * | |
3dd3a9e5 KB |
5 | * This code is derived from software contributed to Berkeley by |
6 | * Edward Wang at The University of California, Berkeley. | |
7 | * | |
87f529ec | 8 | * %sccs.include.redist.c% |
60de5df9 EW |
9 | */ |
10 | ||
46e9ea25 | 11 | #ifndef lint |
3dd3a9e5 | 12 | static char sccsid[] = "@(#)wwspawn.c 3.15 (Berkeley) %G%"; |
46e9ea25 KB |
13 | #endif /* not lint */ |
14 | ||
2dd7d7a6 | 15 | #include "ww.h" |
7c38ad4d | 16 | #include <sys/signal.h> |
2dd7d7a6 | 17 | |
eec72f58 EW |
18 | /* |
19 | * There is a dead lock with vfork and closing of pseudo-ports. | |
7ecf4dca | 20 | * So we have to be sneaky about error reporting. |
eec72f58 | 21 | */ |
7ecf4dca | 22 | wwspawn(wp, file, argv) |
2dd7d7a6 | 23 | register struct ww *wp; |
7ecf4dca EW |
24 | char *file; |
25 | char **argv; | |
2dd7d7a6 | 26 | { |
ac62cc78 | 27 | int pid; |
7ecf4dca EW |
28 | int ret; |
29 | char erred = 0; | |
7c38ad4d | 30 | int s; |
ac62cc78 | 31 | |
7c38ad4d | 32 | s = sigblock(sigmask(SIGCHLD)); |
ac62cc78 | 33 | switch (pid = vfork()) { |
2dd7d7a6 | 34 | case -1: |
03e75950 | 35 | wwerrno = WWE_SYS; |
7ecf4dca EW |
36 | ret = -1; |
37 | break; | |
2dd7d7a6 | 38 | case 0: |
7ecf4dca EW |
39 | if (wwenviron(wp) >= 0) |
40 | execvp(file, argv); | |
41 | erred = 1; | |
eec72f58 | 42 | _exit(1); |
2dd7d7a6 | 43 | default: |
7ecf4dca | 44 | if (erred) { |
eec72f58 | 45 | wwerrno = WWE_SYS; |
7ecf4dca | 46 | ret = -1; |
eec72f58 EW |
47 | } else { |
48 | wp->ww_pid = pid; | |
49 | wp->ww_state = WWS_HASPROC; | |
7ecf4dca | 50 | ret = pid; |
eec72f58 | 51 | } |
2dd7d7a6 | 52 | } |
7c38ad4d | 53 | (void) sigsetmask(s); |
7ecf4dca EW |
54 | if (wp->ww_socket >= 0) { |
55 | (void) close(wp->ww_socket); | |
56 | wp->ww_socket = -1; | |
57 | } | |
7ecf4dca | 58 | return ret; |
2dd7d7a6 | 59 | } |