don't open target for writing if we're just verifying the tapes
[unix-history] / usr / src / usr.bin / window / wwspawn.c
CommitLineData
60de5df9 1/*
46e9ea25
KB
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
5e8b0e60
KB
6 * provided that the above copyright notice and this paragraph are
7 * duplicated in all such forms and that any documentation,
8 * advertising materials, and other materials related to such
9 * distribution and use acknowledge that the software was developed
10 * by the University of California, Berkeley. The name of the
11 * University may not be used to endorse or promote products derived
12 * from this software without specific prior written permission.
13 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
60de5df9
EW
16 */
17
46e9ea25 18#ifndef lint
5e8b0e60 19static char sccsid[] = "@(#)wwspawn.c 3.13 (Berkeley) %G%";
46e9ea25
KB
20#endif /* not lint */
21
2dd7d7a6 22#include "ww.h"
7c38ad4d 23#include <sys/signal.h>
2dd7d7a6 24
eec72f58
EW
25/*
26 * There is a dead lock with vfork and closing of pseudo-ports.
7ecf4dca 27 * So we have to be sneaky about error reporting.
eec72f58 28 */
7ecf4dca 29wwspawn(wp, file, argv)
2dd7d7a6 30register struct ww *wp;
7ecf4dca
EW
31char *file;
32char **argv;
2dd7d7a6 33{
ac62cc78 34 int pid;
7ecf4dca
EW
35 int ret;
36 char erred = 0;
7c38ad4d 37 int s;
ac62cc78 38
7c38ad4d 39 s = sigblock(sigmask(SIGCHLD));
ac62cc78 40 switch (pid = vfork()) {
2dd7d7a6 41 case -1:
03e75950 42 wwerrno = WWE_SYS;
7ecf4dca
EW
43 ret = -1;
44 break;
2dd7d7a6 45 case 0:
7ecf4dca
EW
46 if (wwenviron(wp) >= 0)
47 execvp(file, argv);
48 erred = 1;
eec72f58 49 _exit(1);
2dd7d7a6 50 default:
7ecf4dca 51 if (erred) {
eec72f58 52 wwerrno = WWE_SYS;
7ecf4dca 53 ret = -1;
eec72f58
EW
54 } else {
55 wp->ww_pid = pid;
56 wp->ww_state = WWS_HASPROC;
7ecf4dca 57 ret = pid;
eec72f58 58 }
2dd7d7a6 59 }
7c38ad4d 60 (void) sigsetmask(s);
7ecf4dca
EW
61 if (wp->ww_socket >= 0) {
62 (void) close(wp->ww_socket);
63 wp->ww_socket = -1;
64 }
7ecf4dca 65 return ret;
2dd7d7a6 66}