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 2005 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
31 * Portions of this source code were derived from Berkeley 4.3 BSD
32 * under license from the Regents of the University of California.
35 #pragma ident "%Z%%M% %I% %E% SMI"
37 #if !defined(lint) && defined(SCCSIDS)
38 static char sccsid
[] = "%Z%%M% %I% %E% SMI";
44 * Open two pipes to a child process, one for reading, one for writing.
45 * The pipes are accessed by FILE pointers. This is NOT a public
46 * interface, but for internal use only!
50 extern void *malloc();
51 extern char *strrchr();
53 static char *basename();
54 static char SHELL
[] = "/bin/sh";
62 extern unsigned int strlen();
65 * returns pid, or -1 for failure
68 _openchild(command
, fto
, ffrom
)
83 if (pipe(pdfrom
) < 0) {
86 switch (pid
= fork()) {
92 * child: read from pdto[0], write into pdfrom[1]
97 (void) dup(pdfrom
[1]);
100 * adding this closelog for bug id 1238429
105 com
= malloc((unsigned)strlen(command
) + 6);
109 (void) sprintf(com
, "exec %s", command
);
110 execl(SHELL
, basename(SHELL
), "-c", com
, NULL
);
115 * parent: write into pdto[1], read from pdfrom[0]
117 *fto
= fdopen(pdto
[1], "w");
118 (void) close(pdto
[0]);
119 *ffrom
= fdopen(pdfrom
[0], "r");
120 (void) close(pdfrom
[1]);
126 * error cleanup and return
129 printf("openchild: error3");
130 (void) close(pdfrom
[0]);
131 (void) close(pdfrom
[1]);
133 printf("openchild: error2");
134 (void) close(pdto
[0]);
135 (void) close(pdto
[1]);
137 printf("openchild: error1");
147 p
= strrchr(path
, '/');