2006-08-22 Eric Blake <ebb9@byu.net>
* libc/posix/popen.c (popen): Don't close output end of pipe in
        child if stdout was closed on entry.
        [HAVE_FCNTL]: In parent, mark file as close-on-exec, per POSIX.
			
			
This commit is contained in:
		| @@ -1,3 +1,9 @@ | |||||||
|  | 2006-08-22  Eric Blake  <ebb9@byu.net> | ||||||
|  |  | ||||||
|  | 	* libc/posix/popen.c (popen): Don't close output end of pipe in | ||||||
|  | 	child if stdout was closed on entry. | ||||||
|  | 	[HAVE_FCNTL]: In parent, mark file as close-on-exec, per POSIX. | ||||||
|  |  | ||||||
| 2006-08-19  Ramana Radhakrishnan  <ramana.r@gmail.com> | 2006-08-19  Ramana Radhakrishnan  <ramana.r@gmail.com> | ||||||
|  |  | ||||||
| 	* sys/types.h: Correct syntax error caused by missing '\' on #ifdef | 	* sys/types.h: Correct syntax error caused by missing '\' on #ifdef | ||||||
|   | |||||||
| @@ -1,7 +1,7 @@ | |||||||
| /*	$NetBSD: popen.c,v 1.11 1995/06/16 07:05:33 jtc Exp $	*/ | /*	$NetBSD: popen.c,v 1.11 1995/06/16 07:05:33 jtc Exp $	*/ | ||||||
|  |  | ||||||
| /* | /* | ||||||
|  * Copyright (c) 1988, 1993 |  * Copyright (c) 1988, 1993, 2006 | ||||||
|  *	The Regents of the University of California.  All rights reserved. |  *	The Regents of the University of California.  All rights reserved. | ||||||
|  * |  * | ||||||
|  * This code is derived from software written by Ken Arnold and |  * This code is derived from software written by Ken Arnold and | ||||||
| @@ -55,6 +55,7 @@ static char rcsid[] = "$NetBSD: popen.c,v 1.11 1995/06/16 07:05:33 jtc Exp $"; | |||||||
| #include <stdlib.h> | #include <stdlib.h> | ||||||
| #include <string.h> | #include <string.h> | ||||||
| #include <paths.h> | #include <paths.h> | ||||||
|  | #include <fcntl.h> | ||||||
|  |  | ||||||
| static struct pid { | static struct pid { | ||||||
| 	struct pid *next; | 	struct pid *next; | ||||||
| @@ -102,7 +103,9 @@ _DEFUN(popen, (program, type), | |||||||
| 				(void)dup2(pdes[1], STDOUT_FILENO); | 				(void)dup2(pdes[1], STDOUT_FILENO); | ||||||
| 				(void)close(pdes[1]); | 				(void)close(pdes[1]); | ||||||
| 			} | 			} | ||||||
|  | 			if (pdes[0] != STDOUT_FILENO) { | ||||||
| 				(void) close(pdes[0]); | 				(void) close(pdes[0]); | ||||||
|  | 			} | ||||||
| 		} else { | 		} else { | ||||||
| 			if (pdes[0] != STDIN_FILENO) { | 			if (pdes[0] != STDIN_FILENO) { | ||||||
| 				(void)dup2(pdes[0], STDIN_FILENO); | 				(void)dup2(pdes[0], STDIN_FILENO); | ||||||
| @@ -129,6 +132,12 @@ _DEFUN(popen, (program, type), | |||||||
| 		(void)close(pdes[0]); | 		(void)close(pdes[0]); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | #ifdef HAVE_FCNTL | ||||||
|  | 	/* Hide pipe from future popens; assume fcntl can't fail.  */ | ||||||
|  | 	fcntl (fileno (iop), F_SETFD, | ||||||
|  | 	       fcntl (fileno (iop), F_GETFD, 0) | FD_CLOEXEC); | ||||||
|  | #endif /* HAVE_FCNTL */ | ||||||
|  |  | ||||||
| 	/* Link into list of file descriptors. */ | 	/* Link into list of file descriptors. */ | ||||||
| 	cur->fp = iop; | 	cur->fp = iop; | ||||||
| 	cur->pid =  pid; | 	cur->pid =  pid; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user