提交 bcd93025 编写于 作者: R Rich Felker

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.
上级 cc11b422
#include <sys/signalfd.h> #include <sys/signalfd.h>
#include <signal.h> #include <signal.h>
#include <errno.h>
#include <fcntl.h>
#include "syscall.h" #include "syscall.h"
int signalfd(int fd, const sigset_t *sigs, int flags) 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);
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册