From: Rich Felker Date: Mon, 8 Apr 2013 03:19:00 +0000 (-0400) Subject: fix signalfd not to ignore flags X-Git-Url: http://nsz.repo.hu/git/?p=musl;a=commitdiff_plain;h=bcd9302508e5b89cfdcf2a2acebdf05d88d7479e 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. --- 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 #include +#include +#include #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); }