summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2012-10-19 15:02:37 -0400
committerRich Felker <dalias@aerifal.cx>2012-10-19 15:02:37 -0400
commit599f97360389911c293e0ca4c5eb49e007377fba (patch)
tree9df3f1e50357956c4cc76cd8e2872f342c80bf3c
parentebee8c2b477807fe58fd35d35783633ea08b049c (diff)
downloadmusl-599f97360389911c293e0ca4c5eb49e007377fba.tar.gz
fix usage of locks with vfork
__release_ptc() is only valid in the parent; if it's performed in the child, the lock will be unlocked early then double-unlocked later, corrupting the lock state.
-rw-r--r--src/process/posix_spawn.c2
-rw-r--r--src/process/system.c3
-rw-r--r--src/stdio/popen.c2
3 files changed, 4 insertions, 3 deletions
diff --git a/src/process/posix_spawn.c b/src/process/posix_spawn.c
index c3e800b8..5eb516b0 100644
--- a/src/process/posix_spawn.c
+++ b/src/process/posix_spawn.c
@@ -35,9 +35,9 @@ int __posix_spawnx(pid_t *restrict res, const char *restrict path,
__acquire_ptc();
pid = __vfork();
- __release_ptc();
if (pid) {
+ __release_ptc();
sigprocmask(SIG_SETMASK, &oldmask, 0);
if (pid < 0) return -pid;
*res = pid;
diff --git a/src/process/system.c b/src/process/system.c
index c8f26008..ebe207f5 100644
--- a/src/process/system.c
+++ b/src/process/system.c
@@ -29,7 +29,8 @@ int system(const char *cmd)
__acquire_ptc();
pid = __vfork();
- __release_ptc();
+
+ if (pid) __release_ptc();
if (pid > 0) {
sigset_t new = old;
diff --git a/src/stdio/popen.c b/src/stdio/popen.c
index 0c9f24e3..5a47509e 100644
--- a/src/stdio/popen.c
+++ b/src/stdio/popen.c
@@ -38,9 +38,9 @@ FILE *popen(const char *cmd, const char *mode)
__acquire_ptc();
pid = __vfork();
- __release_ptc();
if (pid) {
+ __release_ptc();
__syscall(SYS_close, p[1-op]);
sigprocmask(SIG_BLOCK, SIGALL_SET, &old);
if (pid < 0) {