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"
41 * Open two pipes to a child process, one for reading, one for writing.
42 * The pipes are accessed by FILE pointers. This is NOT a public
43 * interface, but for internal use only!
47 extern void *malloc();
48 extern char *strrchr();
50 static char *basename();
51 static char SHELL
[] = "/bin/sh";
59 extern unsigned int strlen();
62 * returns pid, or -1 for failure
65 _openchild(command
, fto
, ffrom
)
80 if (pipe(pdfrom
) < 0) {
83 switch (pid
= fork()) {
89 * child: read from pdto[0], write into pdfrom[1]
94 (void) dup(pdfrom
[1]);
97 * adding this closelog for bug id 1238429
102 com
= malloc((unsigned)strlen(command
) + 6);
106 (void) sprintf(com
, "exec %s", command
);
107 execl(SHELL
, basename(SHELL
), "-c", com
, NULL
);
112 * parent: write into pdto[1], read from pdfrom[0]
114 *fto
= fdopen(pdto
[1], "w");
115 (void) close(pdto
[0]);
116 *ffrom
= fdopen(pdfrom
[0], "r");
117 (void) close(pdfrom
[1]);
123 * error cleanup and return
126 printf("openchild: error3");
127 (void) close(pdfrom
[0]);
128 (void) close(pdfrom
[1]);
130 printf("openchild: error2");
131 (void) close(pdto
[0]);
132 (void) close(pdto
[1]);
134 printf("openchild: error1");
144 p
= strrchr(path
, '/');