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
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.
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]
23 * Copyright 1988 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
31 #pragma ident "%Z%%M% %I% %E% SMI"
36 * use shell to execute command with
37 * fi, fo, and fe as standard input/output/error
38 * cmd -> command to execute
39 * fi -> standard input
40 * fo -> standard output
41 * fe -> standard error
44 * non zero -> failure - status from child
45 (Note - -1 means the fork failed)
49 char *cmd
, *fi
, *fo
, *fe
;
51 register pid_t pid
, ret
;
61 DEBUG(3, "shio - %s\n", cmd
);
62 if ((pid
= fork()) == 0) {
63 (void) signal(SIGINT
, SIG_IGN
);
64 (void) signal(SIGHUP
, SIG_IGN
);
65 (void) signal(SIGQUIT
, SIG_IGN
);
67 (void) close(Ifn
); /* close connection fd's */
69 (void) close(0); /* get stdin from file fi */
72 (void) close(1); /* divert stdout to fo */
73 if (creat(fo
, PUB_FILEMODE
) != 1)
75 (void) close(2); /* divert stderr to fe */
76 if (creat(fe
, PUB_FILEMODE
) != 2)
78 (void) execle(SHELL
, "sh", "-c", cmd
, (char *) 0, Env
);
83 * the status returned from wait can never be -1
84 * see man page wait(2)
85 * So we use the -1 value to indicate fork failed
91 while ((ret
= wait(&status
)) != pid
)
92 if (ret
== -1 && errno
!= EINTR
)
94 DEBUG(3, "status %d\n", status
);