1 /*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
8 *
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
13 *
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 *
20 * CDDL HEADER END
21 */
22 /*
23 * Copyright 1988 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 */
26
27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
29
30 #include "uucp.h"
31
32 /*
33 * use shell to execute command with
34 * fi, fo, and fe as standard input/output/error
35 * cmd -> command to execute
36 * fi -> standard input
37 * fo -> standard output
38 * fe -> standard error
39 * return:
40 * 0 -> success
41 * non zero -> failure - status from child
42 (Note - -1 means the fork failed)
43 */
44 int
shio(cmd,fi,fo,fe)45 shio(cmd, fi, fo, fe)
46 char *cmd, *fi, *fo, *fe;
47 {
48 register pid_t pid, ret;
49 int status;
50
51 if (fi == NULL)
52 fi = "/dev/null";
53 if (fo == NULL)
54 fo = "/dev/null";
55 if (fe == NULL)
56 fe = "/dev/null";
57
58 DEBUG(3, "shio - %s\n", cmd);
59 if ((pid = fork()) == 0) {
60 (void) signal(SIGINT, SIG_IGN);
61 (void) signal(SIGHUP, SIG_IGN);
62 (void) signal(SIGQUIT, SIG_IGN);
63 ucloselog();
64 (void) close(Ifn); /* close connection fd's */
65 (void) close(Ofn);
66 (void) close(0); /* get stdin from file fi */
67 if (open(fi, 0) != 0)
68 exit(errno);
69 (void) close(1); /* divert stdout to fo */
70 if (creat(fo, PUB_FILEMODE) != 1)
71 exit(errno);
72 (void) close(2); /* divert stderr to fe */
73 if (creat(fe, PUB_FILEMODE) != 2)
74 exit(errno);
75 (void) execle(SHELL, "sh", "-c", cmd, (char *) 0, Env);
76 exit(100);
77 }
78
79 /*
80 * the status returned from wait can never be -1
81 * see man page wait(3C)
82 * So we use the -1 value to indicate fork failed
83 * or the wait failed.
84 */
85 if (pid == -1)
86 return(-1);
87
88 while ((ret = wait(&status)) != pid)
89 if (ret == -1 && errno != EINTR)
90 return(-1);
91 DEBUG(3, "status %d\n", status);
92 return(status);
93 }
94