mirror of
git://git.musl-libc.org/musl
synced 2025-03-06 20:48:29 +01:00
posix_spawn: fix child spinning on write to a broken pipe
A child process created by posix_spawn reports errors to its parent via a pipe, retrying infinitely on any write error to prevent falsely reporting success. If the (original) parent dies before write is attempted, there is nobody to report to, but the child will remain stuck in the write loop forever if SIGPIPE is blocked or ignored. Fix this by not retrying write if it fails with EPIPE.
This commit is contained in:
parent
80e3b09823
commit
d3a61059c0
1 changed files with 6 additions and 1 deletions
|
@ -4,6 +4,7 @@
|
|||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <sys/wait.h>
|
||||
#include "syscall.h"
|
||||
#include "lock.h"
|
||||
|
@ -156,7 +157,11 @@ static int child(void *args_vp)
|
|||
fail:
|
||||
/* Since sizeof errno < PIPE_BUF, the write is atomic. */
|
||||
ret = -ret;
|
||||
if (ret) while (__syscall(SYS_write, p, &ret, sizeof ret) < 0);
|
||||
if (ret) {
|
||||
int r;
|
||||
do r = __syscall(SYS_write, p, &ret, sizeof ret);
|
||||
while (r<0 && r!=-EPIPE);
|
||||
}
|
||||
_exit(127);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue