mirror of
https://github.com/fluencelabs/musl
synced 2025-05-19 02:31:29 +00:00
popen: handle issues with fd0/1 being closed
also check for failure of dup2 and abort the child rather than reading/writing the wrong file.
This commit is contained in:
parent
b3d7d062af
commit
f305467aad
@ -31,9 +31,9 @@ FILE *popen(const char *cmd, const char *mode)
|
|||||||
close(p[1]);
|
close(p[1]);
|
||||||
return NULL;
|
return NULL;
|
||||||
case 0:
|
case 0:
|
||||||
dup2(p[1-op], 1-op);
|
if (dup2(p[1-op], 1-op) < 0) _exit(127);
|
||||||
close(p[0]);
|
if (p[0] != 1-op) close(p[0]);
|
||||||
close(p[1]);
|
if (p[1] != 1-op) close(p[1]);
|
||||||
execl("/bin/sh", "sh", "-c", cmd, (char *)0);
|
execl("/bin/sh", "sh", "-c", cmd, (char *)0);
|
||||||
_exit(127);
|
_exit(127);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user