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