diff options
author | Ulrich Drepper <drepper@redhat.com> | 2008-07-24 00:29:24 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2008-07-24 13:47:27 -0400 |
commit | 9deb27baedb79759c3ab9435a7d8b841842d56e9 (patch) | |
tree | 1c88393ba30db851ca0bb93c4e656d4e5dbb22b9 /include | |
parent | 7d9dbca34240ebb6ff88d8a29c6c7bffd098f0c1 (diff) |
flag parameters: signalfd
This patch adds the new signalfd4 syscall. It extends the old signalfd
syscall by one parameter which is meant to hold a flag value. In this
patch the only flag support is SFD_CLOEXEC which causes the close-on-exec
flag for the returned file descriptor to be set.
A new name SFD_CLOEXEC is introduced which in this implementation must
have the same value as O_CLOEXEC.
The following test must be adjusted for architectures other than x86 and
x86-64 and in case the syscall numbers changed.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#include <fcntl.h>
#include <signal.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/syscall.h>
#ifndef __NR_signalfd4
# ifdef __x86_64__
# define __NR_signalfd4 289
# elif defined __i386__
# define __NR_signalfd4 327
# else
# error "need __NR_signalfd4"
# endif
#endif
#define SFD_CLOEXEC O_CLOEXEC
int
main (void)
{
sigset_t ss;
sigemptyset (&ss);
sigaddset (&ss, SIGUSR1);
int fd = syscall (__NR_signalfd4, -1, &ss, 8, 0);
if (fd == -1)
{
puts ("signalfd4(0) failed");
return 1;
}
int coe = fcntl (fd, F_GETFD);
if (coe == -1)
{
puts ("fcntl failed");
return 1;
}
if (coe & FD_CLOEXEC)
{
puts ("signalfd4(0) set close-on-exec flag");
return 1;
}
close (fd);
fd = syscall (__NR_signalfd4, -1, &ss, 8, SFD_CLOEXEC);
if (fd == -1)
{
puts ("signalfd4(SFD_CLOEXEC) failed");
return 1;
}
coe = fcntl (fd, F_GETFD);
if (coe == -1)
{
puts ("fcntl failed");
return 1;
}
if ((coe & FD_CLOEXEC) == 0)
{
puts ("signalfd4(SFD_CLOEXEC) does not set close-on-exec flag");
return 1;
}
close (fd);
puts ("OK");
return 0;
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[akpm@linux-foundation.org: add sys_ni stub]
Signed-off-by: Ulrich Drepper <drepper@redhat.com>
Acked-by: Davide Libenzi <davidel@xmailserver.org>
Cc: Michael Kerrisk <mtk.manpages@googlemail.com>
Cc: <linux-arch@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'include')
-rw-r--r-- | include/asm-x86/unistd_32.h | 1 | ||||
-rw-r--r-- | include/asm-x86/unistd_64.h | 2 | ||||
-rw-r--r-- | include/linux/signalfd.h | 5 | ||||
-rw-r--r-- | include/linux/syscalls.h | 1 |
4 files changed, 9 insertions, 0 deletions
diff --git a/include/asm-x86/unistd_32.h b/include/asm-x86/unistd_32.h index 8317d94771d3..c310371f5613 100644 --- a/include/asm-x86/unistd_32.h +++ b/include/asm-x86/unistd_32.h | |||
@@ -332,6 +332,7 @@ | |||
332 | #define __NR_fallocate 324 | 332 | #define __NR_fallocate 324 |
333 | #define __NR_timerfd_settime 325 | 333 | #define __NR_timerfd_settime 325 |
334 | #define __NR_timerfd_gettime 326 | 334 | #define __NR_timerfd_gettime 326 |
335 | #define __NR_signalfd4 327 | ||
335 | 336 | ||
336 | #ifdef __KERNEL__ | 337 | #ifdef __KERNEL__ |
337 | 338 | ||
diff --git a/include/asm-x86/unistd_64.h b/include/asm-x86/unistd_64.h index e323994a370f..e0a9b45b2346 100644 --- a/include/asm-x86/unistd_64.h +++ b/include/asm-x86/unistd_64.h | |||
@@ -641,6 +641,8 @@ __SYSCALL(__NR_timerfd_settime, sys_timerfd_settime) | |||
641 | __SYSCALL(__NR_timerfd_gettime, sys_timerfd_gettime) | 641 | __SYSCALL(__NR_timerfd_gettime, sys_timerfd_gettime) |
642 | #define __NR_paccept 288 | 642 | #define __NR_paccept 288 |
643 | __SYSCALL(__NR_paccept, sys_paccept) | 643 | __SYSCALL(__NR_paccept, sys_paccept) |
644 | #define __NR_signalfd4 289 | ||
645 | __SYSCALL(__NR_signalfd4, sys_signalfd4) | ||
644 | 646 | ||
645 | 647 | ||
646 | #ifndef __NO_STUBS | 648 | #ifndef __NO_STUBS |
diff --git a/include/linux/signalfd.h b/include/linux/signalfd.h index ea037f28df91..8b3f7b7420a1 100644 --- a/include/linux/signalfd.h +++ b/include/linux/signalfd.h | |||
@@ -8,6 +8,11 @@ | |||
8 | #ifndef _LINUX_SIGNALFD_H | 8 | #ifndef _LINUX_SIGNALFD_H |
9 | #define _LINUX_SIGNALFD_H | 9 | #define _LINUX_SIGNALFD_H |
10 | 10 | ||
11 | /* For O_CLOEXEC */ | ||
12 | #include <linux/fcntl.h> | ||
13 | |||
14 | /* Flags for signalfd4. */ | ||
15 | #define SFD_CLOEXEC O_CLOEXEC | ||
11 | 16 | ||
12 | struct signalfd_siginfo { | 17 | struct signalfd_siginfo { |
13 | __u32 ssi_signo; | 18 | __u32 ssi_signo; |
diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h index 2a2a40af6b2c..1c2707797845 100644 --- a/include/linux/syscalls.h +++ b/include/linux/syscalls.h | |||
@@ -610,6 +610,7 @@ asmlinkage long sys_set_robust_list(struct robust_list_head __user *head, | |||
610 | size_t len); | 610 | size_t len); |
611 | asmlinkage long sys_getcpu(unsigned __user *cpu, unsigned __user *node, struct getcpu_cache __user *cache); | 611 | asmlinkage long sys_getcpu(unsigned __user *cpu, unsigned __user *node, struct getcpu_cache __user *cache); |
612 | asmlinkage long sys_signalfd(int ufd, sigset_t __user *user_mask, size_t sizemask); | 612 | asmlinkage long sys_signalfd(int ufd, sigset_t __user *user_mask, size_t sizemask); |
613 | asmlinkage long sys_signalfd4(int ufd, sigset_t __user *user_mask, size_t sizemask, int flags); | ||
613 | asmlinkage long sys_timerfd_create(int clockid, int flags); | 614 | asmlinkage long sys_timerfd_create(int clockid, int flags); |
614 | asmlinkage long sys_timerfd_settime(int ufd, int flags, | 615 | asmlinkage long sys_timerfd_settime(int ufd, int flags, |
615 | const struct itimerspec __user *utmr, | 616 | const struct itimerspec __user *utmr, |