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]
22 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
23 /* All Rights Reserved */
27 * University Copyright- Copyright (c) 1982, 1986, 1988
28 * The Regents of the University of California
31 * University Acknowledgment- Portions of this document are derived from
32 * software developed by the University of California, Berkeley, and its
36 #pragma ident "%Z%%M% %I% %E% SMI"
39 * mailx -- a modified version of a University of California at Berkeley
42 * npopen() and npclose()
44 * stolen from C library, modified to use SHELL variable
52 #define tst(a,b) (*mode == 'r'? (b) : (a))
59 extern void (*sigset())();
62 extern FILE *fdopen();
63 extern int execlp(), fork(), pipe(), close(), fcntl();
71 static pid_t popen_pid
[20];
74 npopen(char *cmd
, char *mode
)
78 register int myside
, yourside
;
79 char *Shell
, *value(char *);
81 if ((Shell
= value("SHELL")) == NULL
|| *Shell
=='\0')
85 Shell
= "/usr/bin/sh";
89 myside
= tst(p
[WTR
], p
[RDR
]);
90 yourside
= tst(p
[RDR
], p
[WTR
]);
91 if((pid
= fork()) == 0) {
92 /* myside and yourside reverse roles in child */
98 (void) fcntl(yourside
, 0, stdio
);
99 (void) close(yourside
);
100 (void) execlp(Shell
, Shell
, "-c", cmd
, (char *)0);
106 popen_pid
[myside
] = pid
;
107 (void) close(yourside
);
108 return(fdopen(myside
, mode
));
117 void (*istat
)(int), (*qstat
)(int);
121 istat
= sigset(SIGINT
, SIG_IGN
);
122 qstat
= sigset(SIGQUIT
, SIG_IGN
);
123 while((r
= wait(&status
)) != popen_pid
[f
] && r
!= (pid_t
)-1)
127 (void) sigset(SIGINT
, istat
);
128 (void) sigset(SIGQUIT
, qstat
);