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

Andrey Vagin avagin at openvz.org
Tue Dec 4 05:05:20 EST 2012


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.

Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
 fs/signalfd.c                 | 19 ++++++++++++++++---
 include/uapi/linux/signalfd.h |  2 ++
 2 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/fs/signalfd.c b/fs/signalfd.c
index 95f1444..7e56ac1 100644
--- a/fs/signalfd.c
+++ b/fs/signalfd.c
@@ -223,11 +223,18 @@ 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);
@@ -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



More information about the CRIU mailing list