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