* Copyright (c) 1980 Regents of the University of California.
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, Berkeley. The name of the
* University may not be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
static char sccsid
[] = "@(#)popen.c 5.13 (Berkeley) %G%";
int myside
, hisside
, fd0
, fd1
;
pid
= (int *) malloc((unsigned) sizeof (int) * getdtablesize());
hisside
= fd1
= p
[WRITE
];
if ((pid
[myside
] = start_command(cmd
, 0, fd0
, fd1
, NOSTR
)) < 0) {
return fdopen(myside
, mode
);
omask
= sigblock(sigmask(SIGINT
)|sigmask(SIGHUP
));
* Run a command without a shell, with optional arguments and splicing
* of stdin and stdout. The command name can be a sequence of words.
* Signals must be handled by the caller.
* "Mask" contains the signals to ignore in the new process.
* SIGINT is enabled unless it's in the mask.
run_command(cmd
, mask
, infd
, outfd
, a0
, a1
, a2
)
if ((pid
= start_command(cmd
, mask
, infd
, outfd
, a0
, a1
, a2
)) < 0)
return wait_command(pid
);
start_command(cmd
, mask
, infd
, outfd
, a0
, a1
, a2
)
if ((pid
= vfork()) < 0) {
int i
= getrawlist(cmd
, argv
, sizeof argv
/ sizeof *argv
);
if ((argv
[i
++] = a0
) != NOSTR
&&
(argv
[i
++] = a1
) != NOSTR
&&
(argv
[i
++] = a2
) != NOSTR
)
prepare_child(mask
, infd
, outfd
);
prepare_child(mask
, infd
, outfd
)
for (i
= getdtablesize(); --i
> 2;)
for (i
= 1; i
<= NSIG
; i
++)
(void) signal(i
, SIG_IGN
);
if ((mask
& sigmask(SIGINT
)) == 0)
(void) signal(SIGINT
, SIG_DFL
);
if (wait_child(pid
) < 0) {
printf("Fatal error in process.\n");
static struct child
*child
;
register struct child
**cpp
;
for (cpp
= &child
; *cpp
!= NULL
&& (*cpp
)->pid
!= pid
;
*cpp
= (struct child
*) malloc(sizeof (struct child
));
(*cpp
)->done
= (*cpp
)->free
= 0;
register struct child
*cp
;
register struct child
**cpp
;
for (cpp
= &child
; *cpp
!= cp
; cpp
= &(*cpp
)->link
)
register struct child
*cp
;
while ((pid
= wait3(&status
, WNOHANG
, (struct timeval
*)0)) > 0) {
* Wait for a specific child to die.
int mask
= sigblock(sigmask(SIGCHLD
));
register struct child
*cp
= findchild(pid
);
wait_status
= cp
->status
;
return wait_status
.w_status
? -1 : 0;
* Mark a child as don't care.
int mask
= sigblock(sigmask(SIGCHLD
));
register struct child
*cp
= findchild(pid
);