提交 599f9736 编写于 作者: R Rich Felker

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.
上级 ebee8c2b
......@@ -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;
......
......@@ -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;
......
......@@ -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) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册