lkml.org 
[lkml]   [2012]   [Dec]   [24]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[PATCH 3/4] signalfd: add ability to choose a private or shared queue
    Date
    This patch is added two flags SFD_GROUP and SFD_SHARED.
    SFD_SHARED - read signals from a shared queue
    SFD_PRIVATE - read signals from a private queue

    Without this flags or with both flags signals are read from both queues.

    This functionality is requered for dumping pending signals.

    Cc: Alexander Viro <viro@zeniv.linux.org.uk>
    Cc: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
    Cc: David Howells <dhowells@redhat.com>
    Cc: Thomas Gleixner <tglx@linutronix.de>
    Cc: Oleg Nesterov <oleg@redhat.com>
    Cc: Michael Kerrisk <mtk.manpages@gmail.com>
    Cc: Pavel Emelyanov <xemul@parallels.com>
    CC: Cyrill Gorcunov <gorcunov@openvz.org>
    Signed-off-by: Andrey Vagin <avagin@openvz.org>
    ---
    fs/signalfd.c | 25 +++++++++++++++++++------
    include/uapi/linux/signalfd.h | 2 ++
    2 files changed, 21 insertions(+), 6 deletions(-)

    diff --git a/fs/signalfd.c b/fs/signalfd.c
    index 95f1444..a35aeda 100644
    --- a/fs/signalfd.c
    +++ b/fs/signalfd.c
    @@ -170,13 +170,13 @@ static int signalfd_copyinfo(struct signalfd_siginfo __user *uinfo,
    }

    static ssize_t signalfd_dequeue(struct signalfd_ctx *ctx, siginfo_t *info,
    - int nonblock)
    + int nonblock, int queue)
    {
    ssize_t ret;
    DECLARE_WAITQUEUE(wait, current);

    spin_lock_irq(&current->sighand->siglock);
    - ret = dequeue_signal(current, &ctx->sigmask, info);
    + ret = do_dequeue_signal(current, &ctx->sigmask, info, queue);
    switch (ret) {
    case 0:
    if (!nonblock)
    @@ -223,14 +223,21 @@ static ssize_t signalfd_read(struct file *file, char __user *buf, size_t count,
    bool raw = file->f_flags & SFD_RAW;
    ssize_t ret, total = 0;
    siginfo_t info;
    + int queue = 0;

    count /= sizeof(struct signalfd_siginfo);
    if (!count)
    return -EINVAL;

    + if (file->f_flags & SFD_GROUP)
    + queue++;
    +
    + if (file->f_flags & SFD_PRIVATE)
    + queue--;
    +
    siginfo = (struct signalfd_siginfo __user *) buf;
    do {
    - ret = signalfd_dequeue(ctx, &info, nonblock);
    + ret = signalfd_dequeue(ctx, &info, nonblock, queue);
    if (unlikely(ret <= 0))
    break;

    @@ -274,6 +281,8 @@ static const struct file_operations signalfd_fops = {
    .llseek = noop_llseek,
    };

    +#define SIGNAFD_FLAGS (SFD_RAW | SFD_GROUP | SFD_PRIVATE)
    +
    SYSCALL_DEFINE4(signalfd4, int, ufd, sigset_t __user *, user_mask,
    size_t, sizemask, int, flags)
    {
    @@ -284,7 +293,7 @@ SYSCALL_DEFINE4(signalfd4, int, ufd, sigset_t __user *, user_mask,
    BUILD_BUG_ON(SFD_CLOEXEC != O_CLOEXEC);
    BUILD_BUG_ON(SFD_NONBLOCK != O_NONBLOCK);

    - if (flags & ~(SFD_CLOEXEC | SFD_NONBLOCK | SFD_RAW))
    + if (flags & ~(SFD_CLOEXEC | SFD_NONBLOCK | SIGNAFD_FLAGS))
    return -EINVAL;

    if (sizemask != sizeof(sigset_t) ||
    @@ -308,9 +317,9 @@ SYSCALL_DEFINE4(signalfd4, int, ufd, sigset_t __user *, user_mask,
    O_RDWR | (flags & (O_CLOEXEC | O_NONBLOCK)));
    if (ufd < 0)
    kfree(ctx);
    - else if (flags & SFD_RAW) {
    + else if (flags & SIGNAFD_FLAGS) {
    struct fd f = fdget(ufd);
    - f.file->f_flags |= flags & SFD_RAW;
    + f.file->f_flags |= flags & SIGNAFD_FLAGS;
    fdput(f);
    }
    } else {
    @@ -322,6 +331,10 @@ SYSCALL_DEFINE4(signalfd4, int, ufd, sigset_t __user *, user_mask,
    fdput(f);
    return -EINVAL;
    }
    +
    + f.file->f_flags = (f.file->f_flags & ~SIGNAFD_FLAGS) |
    + (flags & SIGNAFD_FLAGS);
    +
    spin_lock_irq(&current->sighand->siglock);
    ctx->sigmask = sigmask;
    spin_unlock_irq(&current->sighand->siglock);
    diff --git a/include/uapi/linux/signalfd.h b/include/uapi/linux/signalfd.h
    index bc31849..9421321 100644
    --- a/include/uapi/linux/signalfd.h
    +++ b/include/uapi/linux/signalfd.h
    @@ -16,6 +16,8 @@
    #define SFD_CLOEXEC O_CLOEXEC
    #define SFD_NONBLOCK O_NONBLOCK
    #define SFD_RAW O_DIRECT
    +#define SFD_GROUP O_DIRECTORY
    +#define SFD_PRIVATE O_EXCL

    struct signalfd_siginfo {
    __u32 ssi_signo;
    --
    1.7.11.7


    \
     
     \ /
      Last update: 2012-12-24 10:01    [W:3.632 / U:0.036 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site