]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/commitdiff
flag parameters: signalfd
authorUlrich Drepper <drepper@redhat.com>
Thu, 24 Jul 2008 04:29:24 +0000 (21:29 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Thu, 24 Jul 2008 17:47:27 +0000 (10:47 -0700)
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>
arch/x86/ia32/ia32entry.S
arch/x86/kernel/syscall_table_32.S
fs/compat.c
fs/signalfd.c
include/asm-x86/unistd_32.h
include/asm-x86/unistd_64.h
include/linux/signalfd.h
include/linux/syscalls.h
kernel/sys_ni.c

index 021d71bc69b5dbc1765f9aadfb3b9629b375e399..c308128b9251d72a16d69300e8746b1b945f7813 100644 (file)
@@ -826,4 +826,5 @@ ia32_sys_call_table:
        .quad sys32_fallocate
        .quad compat_sys_timerfd_settime        /* 325 */
        .quad compat_sys_timerfd_gettime
+       .quad compat_sys_signalfd4
 ia32_syscall_end:
index adff5562f5fd4bbc40965ba8eb5f33d433f9f776..c12a36c9fd51b5411bfbf61f51eb3de86c9fdcde 100644 (file)
@@ -326,3 +326,4 @@ ENTRY(sys_call_table)
        .long sys_fallocate
        .long sys_timerfd_settime       /* 325 */
        .long sys_timerfd_gettime
+       .long sys_signalfd4
index b46604281766fe876031ce776039417204c44e7e..106eba28ec5a8c7a4f05f906f9fea1f7fd421c5c 100644 (file)
@@ -2131,9 +2131,9 @@ asmlinkage long compat_sys_epoll_pwait(int epfd,
 
 #ifdef CONFIG_SIGNALFD
 
-asmlinkage long compat_sys_signalfd(int ufd,
-                                   const compat_sigset_t __user *sigmask,
-                                   compat_size_t sigsetsize)
+asmlinkage long compat_sys_signalfd4(int ufd,
+                                    const compat_sigset_t __user *sigmask,
+                                    compat_size_t sigsetsize, int flags)
 {
        compat_sigset_t ss32;
        sigset_t tmp;
@@ -2148,9 +2148,15 @@ asmlinkage long compat_sys_signalfd(int ufd,
        if (copy_to_user(ksigmask, &tmp, sizeof(sigset_t)))
                return -EFAULT;
 
-       return sys_signalfd(ufd, ksigmask, sizeof(sigset_t));
+       return sys_signalfd4(ufd, ksigmask, sizeof(sigset_t), flags);
 }
 
+asmlinkage long compat_sys_signalfd(int ufd,
+                                   const compat_sigset_t __user *sigmask,
+                                   compat_size_t sigsetsize)
+{
+       return compat_sys_signalfd4(ufd, sigmask, sigsetsize, 0);
+}
 #endif /* CONFIG_SIGNALFD */
 
 #ifdef CONFIG_TIMERFD
index ddb328b74bde68ff4628aafae908f8d38609e708..c8609fa51a130daad2baef38a0fe2584790b625a 100644 (file)
@@ -205,11 +205,15 @@ static const struct file_operations signalfd_fops = {
        .read           = signalfd_read,
 };
 
-asmlinkage long sys_signalfd(int ufd, sigset_t __user *user_mask, size_t sizemask)
+asmlinkage long sys_signalfd4(int ufd, sigset_t __user *user_mask,
+                             size_t sizemask, int flags)
 {
        sigset_t sigmask;
        struct signalfd_ctx *ctx;
 
+       if (flags & ~SFD_CLOEXEC)
+               return -EINVAL;
+
        if (sizemask != sizeof(sigset_t) ||
            copy_from_user(&sigmask, user_mask, sizeof(sigmask)))
                return -EINVAL;
@@ -228,7 +232,7 @@ asmlinkage long sys_signalfd(int ufd, sigset_t __user *user_mask, size_t sizemas
                 * anon_inode_getfd() will install the fd.
                 */
                ufd = anon_inode_getfd("[signalfd]", &signalfd_fops, ctx,
-                                      0);
+                                      flags & O_CLOEXEC);
                if (ufd < 0)
                        kfree(ctx);
        } else {
@@ -250,3 +254,9 @@ asmlinkage long sys_signalfd(int ufd, sigset_t __user *user_mask, size_t sizemas
 
        return ufd;
 }
+
+asmlinkage long sys_signalfd(int ufd, sigset_t __user *user_mask,
+                            size_t sizemask)
+{
+       return sys_signalfd4(ufd, user_mask, sizemask, 0);
+}
index 8317d94771d32622dad406f68d84f77e0823628d..c310371f5613c1961b17f868460744c244326789 100644 (file)
 #define __NR_fallocate         324
 #define __NR_timerfd_settime   325
 #define __NR_timerfd_gettime   326
+#define __NR_signalfd4         327
 
 #ifdef __KERNEL__
 
index e323994a370ff4e1282d41745466e4de60e8c7c3..e0a9b45b234683d4f62042631821bc8e9e4db865 100644 (file)
@@ -641,6 +641,8 @@ __SYSCALL(__NR_timerfd_settime, sys_timerfd_settime)
 __SYSCALL(__NR_timerfd_gettime, sys_timerfd_gettime)
 #define __NR_paccept                           288
 __SYSCALL(__NR_paccept, sys_paccept)
+#define __NR_signalfd4                         289
+__SYSCALL(__NR_signalfd4, sys_signalfd4)
 
 
 #ifndef __NO_STUBS
index ea037f28df91372d208a2e4301b24e21369596ca..8b3f7b7420a1880a54fba1486ebb8619a5f04c51 100644 (file)
@@ -8,6 +8,11 @@
 #ifndef _LINUX_SIGNALFD_H
 #define _LINUX_SIGNALFD_H
 
+/* For O_CLOEXEC */
+#include <linux/fcntl.h>
+
+/* Flags for signalfd4.  */
+#define SFD_CLOEXEC O_CLOEXEC
 
 struct signalfd_siginfo {
        __u32 ssi_signo;
index 2a2a40af6b2c9b252fe3986bde43ee4a98a94472..1c27077978456d1b4a5bb8dc4f859794880486bd 100644 (file)
@@ -610,6 +610,7 @@ asmlinkage long sys_set_robust_list(struct robust_list_head __user *head,
                                    size_t len);
 asmlinkage long sys_getcpu(unsigned __user *cpu, unsigned __user *node, struct getcpu_cache __user *cache);
 asmlinkage long sys_signalfd(int ufd, sigset_t __user *user_mask, size_t sizemask);
+asmlinkage long sys_signalfd4(int ufd, sigset_t __user *user_mask, size_t sizemask, int flags);
 asmlinkage long sys_timerfd_create(int clockid, int flags);
 asmlinkage long sys_timerfd_settime(int ufd, int flags,
                                    const struct itimerspec __user *utmr,
index 2f0b8a2e600f189d3516c5524123cbc6f2cb53d2..8627c89ae9e8d0a570ed6236db5d5c8bb26b8aeb 100644 (file)
@@ -156,6 +156,7 @@ cond_syscall(sys_ioprio_get);
 
 /* New file descriptors */
 cond_syscall(sys_signalfd);
+cond_syscall(sys_signalfd4);
 cond_syscall(compat_sys_signalfd);
 cond_syscall(sys_timerfd_create);
 cond_syscall(sys_timerfd_settime);