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 1992 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1984 AT&T */
28 /* All Rights Reserved */
30 #pragma ident "%Z%%M% %I% %E% SMI" /* from S5R2 1.2 */
34 #include <sys/types.h>
47 register void (*istat
)(), (*qstat
)();
51 while (*s
== ' ' || *s
== '\t')
54 if (strncmp(s
, "/usr/ucb", strlen("/usr/ucb")) == 0) {
55 /* check if command is under /usr/ucb, if not
56 * replace /usr/ucb with /usr/bin.
59 if ((c
= strchr(path
, ' ')) != NULL
)
61 if (access(path
, F_OK
) == -1) {
62 strncpy(path
, "/usr/bin", strlen("/usr/bin"));
63 if (c
!= NULL
) *c
= ' ';
67 else if (strncmp(s
, "/bin", strlen("/bin")) == 0 ||
68 strncmp(s
, "/usr/bin", strlen("/usr/bin")) == 0) {
69 /* if /usr/bin is specified, first check if the command
70 * exists under /usr/bin, otherwise try /usr/ucb */
71 if (access(path
, F_OK
) == -1) {
72 strcpy(path
, "/usr/ucb");
73 if (strncmp(s
, "/bin", strlen("/bin")) == 0)
74 strcat(path
, strchr(s
+1, '/'));
77 strcat(path
, strchr(c
+1, '/'));
79 if (c
!= NULL
) *c
= ' ';
84 if ((pid
= vfork()) == 0) {
85 (void) execl("/bin/sh", "sh", "-c", s
, (char *)0);
91 istat
= signal(SIGINT
, SIG_IGN
);
92 qstat
= signal(SIGQUIT
, SIG_IGN
);
93 w
= waitpid(pid
, &status
, 0);
94 (void) signal(SIGINT
, istat
);
95 (void) signal(SIGQUIT
, qstat
);
96 return ((w
== -1) ? -1: status
);