*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char rcsid[] = "$OpenBSD: popen.c,v 1.3 1996/08/19 08:25:20 tholo Exp $";
+static char rcsid[] = "$OpenBSD: popen.c,v 1.4 1997/04/16 21:59:04 millert Exp $";
#endif /* LIBC_SCCS and not lint */
#include <sys/param.h>
/* NOTREACHED */
case 0: /* Child. */
if (*type == 'r') {
- if (pdes[1] != STDOUT_FILENO) {
- (void)dup2(pdes[1], STDOUT_FILENO);
- (void)close(pdes[1]);
+ /*
+ * We must NOT modify pdes, due to the
+ * semantics of vfork.
+ */
+ int tpdes1 = pdes[1];
+ if (tpdes1 != STDOUT_FILENO) {
+ (void)dup2(tpdes1, STDOUT_FILENO);
+ (void)close(tpdes1);
+ tpdes1 = STDOUT_FILENO;
}
(void) close(pdes[0]);
} else {