[PATCH 3/4] signalfd: add ability to choose a private or shared queue

From: Andrey Vagin
Date: Mon Dec 24 2012 - 03:14:30 EST


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@xxxxxxxxxxxxxxxxxx>
Cc: "Paul E. McKenney" <paulmck@xxxxxxxxxxxxxxxxxx>
Cc: David Howells <dhowells@xxxxxxxxxx>
Cc: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
Cc: Oleg Nesterov <oleg@xxxxxxxxxx>
Cc: Michael Kerrisk <mtk.manpages@xxxxxxxxx>
Cc: Pavel Emelyanov <xemul@xxxxxxxxxxxxx>
CC: Cyrill Gorcunov <gorcunov@xxxxxxxxxx>
Signed-off-by: Andrey Vagin <avagin@xxxxxxxxxx>
---
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

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/