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 /fs | |
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 'fs')
-rw-r--r-- | fs/compat.c | 14 | ||||
-rw-r--r-- | fs/signalfd.c | 14 |
2 files changed, 22 insertions, 6 deletions
diff --git a/fs/compat.c b/fs/compat.c index b46604281766..106eba28ec5a 100644 --- a/fs/compat.c +++ b/fs/compat.c | |||
@@ -2131,9 +2131,9 @@ asmlinkage long compat_sys_epoll_pwait(int epfd, | |||
2131 | 2131 | ||
2132 | #ifdef CONFIG_SIGNALFD | 2132 | #ifdef CONFIG_SIGNALFD |
2133 | 2133 | ||
2134 | asmlinkage long compat_sys_signalfd(int ufd, | 2134 | asmlinkage long compat_sys_signalfd4(int ufd, |
2135 | const compat_sigset_t __user *sigmask, | 2135 | const compat_sigset_t __user *sigmask, |
2136 | compat_size_t sigsetsize) | 2136 | compat_size_t sigsetsize, int flags) |
2137 | { | 2137 | { |
2138 | compat_sigset_t ss32; | 2138 | compat_sigset_t ss32; |
2139 | sigset_t tmp; | 2139 | sigset_t tmp; |
@@ -2148,9 +2148,15 @@ asmlinkage long compat_sys_signalfd(int ufd, | |||
2148 | if (copy_to_user(ksigmask, &tmp, sizeof(sigset_t))) | 2148 | if (copy_to_user(ksigmask, &tmp, sizeof(sigset_t))) |
2149 | return -EFAULT; | 2149 | return -EFAULT; |
2150 | 2150 | ||
2151 | return sys_signalfd(ufd, ksigmask, sizeof(sigset_t)); | 2151 | return sys_signalfd4(ufd, ksigmask, sizeof(sigset_t), flags); |
2152 | } | 2152 | } |
2153 | 2153 | ||
2154 | asmlinkage long compat_sys_signalfd(int ufd, | ||
2155 | const compat_sigset_t __user *sigmask, | ||
2156 | compat_size_t sigsetsize) | ||
2157 | { | ||
2158 | return compat_sys_signalfd4(ufd, sigmask, sigsetsize, 0); | ||
2159 | } | ||
2154 | #endif /* CONFIG_SIGNALFD */ | 2160 | #endif /* CONFIG_SIGNALFD */ |
2155 | 2161 | ||
2156 | #ifdef CONFIG_TIMERFD | 2162 | #ifdef CONFIG_TIMERFD |
diff --git a/fs/signalfd.c b/fs/signalfd.c index ddb328b74bde..c8609fa51a13 100644 --- a/fs/signalfd.c +++ b/fs/signalfd.c | |||
@@ -205,11 +205,15 @@ static const struct file_operations signalfd_fops = { | |||
205 | .read = signalfd_read, | 205 | .read = signalfd_read, |
206 | }; | 206 | }; |
207 | 207 | ||
208 | asmlinkage long sys_signalfd(int ufd, sigset_t __user *user_mask, size_t sizemask) | 208 | asmlinkage long sys_signalfd4(int ufd, sigset_t __user *user_mask, |
209 | size_t sizemask, int flags) | ||
209 | { | 210 | { |
210 | sigset_t sigmask; | 211 | sigset_t sigmask; |
211 | struct signalfd_ctx *ctx; | 212 | struct signalfd_ctx *ctx; |
212 | 213 | ||
214 | if (flags & ~SFD_CLOEXEC) | ||
215 | return -EINVAL; | ||
216 | |||
213 | if (sizemask != sizeof(sigset_t) || | 217 | if (sizemask != sizeof(sigset_t) || |
214 | copy_from_user(&sigmask, user_mask, sizeof(sigmask))) | 218 | copy_from_user(&sigmask, user_mask, sizeof(sigmask))) |
215 | return -EINVAL; | 219 | return -EINVAL; |
@@ -228,7 +232,7 @@ asmlinkage long sys_signalfd(int ufd, sigset_t __user *user_mask, size_t sizemas | |||
228 | * anon_inode_getfd() will install the fd. | 232 | * anon_inode_getfd() will install the fd. |
229 | */ | 233 | */ |
230 | ufd = anon_inode_getfd("[signalfd]", &signalfd_fops, ctx, | 234 | ufd = anon_inode_getfd("[signalfd]", &signalfd_fops, ctx, |
231 | 0); | 235 | flags & O_CLOEXEC); |
232 | if (ufd < 0) | 236 | if (ufd < 0) |
233 | kfree(ctx); | 237 | kfree(ctx); |
234 | } else { | 238 | } else { |
@@ -250,3 +254,9 @@ asmlinkage long sys_signalfd(int ufd, sigset_t __user *user_mask, size_t sizemas | |||
250 | 254 | ||
251 | return ufd; | 255 | return ufd; |
252 | } | 256 | } |
257 | |||
258 | asmlinkage long sys_signalfd(int ufd, sigset_t __user *user_mask, | ||
259 | size_t sizemask) | ||
260 | { | ||
261 | return sys_signalfd4(ufd, user_mask, sizemask, 0); | ||
262 | } | ||