diff options
author | Rich Felker <dalias@aerifal.cx> | 2013-04-07 23:19:00 -0400 |
---|---|---|
committer | Rich Felker <dalias@aerifal.cx> | 2013-04-07 23:19:00 -0400 |
commit | bcd9302508e5b89cfdcf2a2acebdf05d88d7479e (patch) | |
tree | bbcb967c155de26caecd81153f1518e29fd6f9a6 /src/linux | |
parent | cc11b422864f0eba97f8bc170e2c8275397bdf41 (diff) | |
download | musl-bcd9302508e5b89cfdcf2a2acebdf05d88d7479e.tar.gz musl-bcd9302508e5b89cfdcf2a2acebdf05d88d7479e.tar.xz musl-bcd9302508e5b89cfdcf2a2acebdf05d88d7479e.zip |
fix signalfd not to ignore flags
also include fallback code for broken kernels that don't support the flags. as usual, the fallback has a race condition that can leak file descriptors.
Diffstat (limited to 'src/linux')
-rw-r--r-- | src/linux/signalfd.c | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/src/linux/signalfd.c b/src/linux/signalfd.c index 94de3627..da6bcedb 100644 --- a/src/linux/signalfd.c +++ b/src/linux/signalfd.c @@ -1,8 +1,19 @@ #include <sys/signalfd.h> #include <signal.h> +#include <errno.h> +#include <fcntl.h> #include "syscall.h" int signalfd(int fd, const sigset_t *sigs, int flags) { - return syscall(SYS_signalfd, fd, sigs, _NSIG/8); + int ret = __syscall(SYS_signalfd4, fd, sigs, _NSIG/8, flags); + if (ret != -ENOSYS) return __syscall_ret(ret); + ret = __syscall(SYS_signalfd, fd, sigs, _NSIG/8); + if (ret >= 0) { + if (flags & SFD_CLOEXEC) + __syscall(SYS_fcntl, ret, F_SETFD, FD_CLOEXEC); + if (flags & SFD_NONBLOCK) + __syscall(SYS_fcntl, ret, F_SETFL, O_NONBLOCK); + } + return __syscall_ret(ret); } |