1 /* 2 * Copyright (c) 1983 Regents of the University of California. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms are permitted 6 * provided that this notice is preserved and that due credit is given 7 * to the University of California at Berkeley. The name of the University 8 * may not be used to endorse or promote products derived from this 9 * software without specific prior written permission. This software 10 * is provided ``as is'' without express or implied warranty. 11 */ 12 13 #ifndef lint 14 static char sccsid[] = "@(#)wwspawn.c 3.12 (Berkeley) 02/21/88"; 15 #endif /* not lint */ 16 17 #include "ww.h" 18 #include <sys/signal.h> 19 20 /* 21 * There is a dead lock with vfork and closing of pseudo-ports. 22 * So we have to be sneaky about error reporting. 23 */ 24 wwspawn(wp, file, argv) 25 register struct ww *wp; 26 char *file; 27 char **argv; 28 { 29 int pid; 30 int ret; 31 char erred = 0; 32 int s; 33 34 s = sigblock(sigmask(SIGCHLD)); 35 switch (pid = vfork()) { 36 case -1: 37 wwerrno = WWE_SYS; 38 ret = -1; 39 break; 40 case 0: 41 if (wwenviron(wp) >= 0) 42 execvp(file, argv); 43 erred = 1; 44 _exit(1); 45 default: 46 if (erred) { 47 wwerrno = WWE_SYS; 48 ret = -1; 49 } else { 50 wp->ww_pid = pid; 51 wp->ww_state = WWS_HASPROC; 52 ret = pid; 53 } 54 } 55 (void) sigsetmask(s); 56 if (wp->ww_socket >= 0) { 57 (void) close(wp->ww_socket); 58 wp->ww_socket = -1; 59 } 60 return ret; 61 } 62