mirror of
https://git.FreeBSD.org/src.git
synced 2024-12-02 08:42:48 +00:00
Fix the problem in popen that makes correct vfork semantics fail.
Specifically, popen modifies a variable "pdes[1]" in the child in such a way that it breaks code in the parent (due to the address space sharing.)
This commit is contained in:
parent
93d71a483c
commit
1174d9f9df
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=24975
@ -93,14 +93,19 @@ popen(command, type)
|
||||
/* NOTREACHED */
|
||||
case 0: /* Child. */
|
||||
if (*type == 'r') {
|
||||
if (pdes[1] != STDOUT_FILENO) {
|
||||
(void)dup2(pdes[1], STDOUT_FILENO);
|
||||
(void)close(pdes[1]);
|
||||
pdes[1] = STDOUT_FILENO;
|
||||
/*
|
||||
* 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]);
|
||||
if (twoway && (pdes[1] != STDIN_FILENO))
|
||||
(void)dup2(pdes[1], STDIN_FILENO);
|
||||
if (twoway && (tpdes1 != STDIN_FILENO))
|
||||
(void)dup2(tpdes1, STDIN_FILENO);
|
||||
} else {
|
||||
if (pdes[0] != STDIN_FILENO) {
|
||||
(void)dup2(pdes[0], STDIN_FILENO);
|
||||
|
Loading…
Reference in New Issue
Block a user