From: Andrey Vagin <avagin@openvz.org>
To: linux-kernel@vger.kernel.org
Cc: criu@openvz.org, linux-fsdevel@vger.kernel.org,
linux-api@vger.kernel.org, Andrey Vagin <avagin@openvz.org>,
Oleg Nesterov <oleg@redhat.com>,
Alexander Viro <viro@zeniv.linux.org.uk>,
"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>,
David Howells <dhowells@redhat.com>,
Dave Jones <davej@redhat.com>,
Michael Kerrisk <mtk.manpages@gmail.com>,
Pavel Emelyanov <xemul@parallels.com>,
Cyrill Gorcunov <gorcunov@openvz.org>
Subject: [PATCH 3/3] signalfd: add ability to read siginfo-s without dequeuing signals (v2)
Date: Tue, 29 Jan 2013 23:03:01 +0400 [thread overview]
Message-ID: <1359486181-29088-1-git-send-email-avagin@openvz.org> (raw)
In-Reply-To: <1358849741-9611-4-git-send-email-avagin@openvz.org>
If signalfd is created with the flag SFD_PEEK, it reads siginfo-s
without dequeuing signals.
For reading not first siginfo pread(fd, buf, size, pos) can be used,
where ppos / sizeof(signalfd_siginfo) is a sequence number of a signal
in a queue.
This functionality is required for checkpointing pending signals.
v2: * signals can be dumped only from one queue.
* treat pos as offset in bytes, not in elements, so pos should be
aligned to the size of signalfd_siginfo.
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Cc: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
Cc: David Howells <dhowells@redhat.com>
Cc: Dave Jones <davej@redhat.com>
Cc: Andrey Vagin <avagin@openvz.org>
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 | 61 ++++++++++++++++++++++++++++++++++++++++---
include/uapi/linux/signalfd.h | 2 ++
2 files changed, 60 insertions(+), 3 deletions(-)
diff --git a/fs/signalfd.c b/fs/signalfd.c
index 8019ec9..0da6a30 100644
--- a/fs/signalfd.c
+++ b/fs/signalfd.c
@@ -51,6 +51,47 @@ struct signalfd_ctx {
sigset_t sigmask;
};
+static int peek_signal(struct sigpending *pending, sigset_t *mask,
+ siginfo_t *info, loff_t *pseq)
+{
+ struct sigqueue *q;
+ int ret = 0;
+
+ spin_lock_irq(¤t->sighand->siglock);
+
+ list_for_each_entry(q, &pending->list, list) {
+ if (sigismember(mask, q->info.si_signo))
+ continue;
+
+ if ((*pseq)-- == 0) {
+ copy_siginfo(info, &q->info);
+ ret = info->si_signo;
+ break;
+ }
+ }
+
+ spin_unlock_irq(¤t->sighand->siglock);
+
+ return ret;
+}
+
+static ssize_t signalfd_peek(struct signalfd_ctx *ctx,
+ siginfo_t *info, loff_t *ppos, int queue_mask)
+{
+ loff_t seq = *ppos / sizeof(struct signalfd_siginfo);
+ int signr = 0;
+
+ if (queue_mask & SIGQUEUE_PRIVATE)
+ signr = peek_signal(¤t->pending,
+ &ctx->sigmask, info, &seq);
+ else if (queue_mask & SIGQUEUE_SHARED)
+ signr = peek_signal(¤t->signal->shared_pending,
+ &ctx->sigmask, info, &seq);
+ (*ppos) += sizeof(struct signalfd_siginfo);
+
+ return signr;
+}
+
static int signalfd_release(struct inode *inode, struct file *file)
{
kfree(file->private_data);
@@ -257,9 +298,15 @@ static ssize_t signalfd_read(struct file *file, char __user *buf, size_t count,
if (!count)
return -EINVAL;
+ if (*ppos % sizeof(struct signalfd_siginfo))
+ return -EINVAL;
+
siginfo = (struct signalfd_siginfo __user *) buf;
do {
- ret = signalfd_dequeue(ctx, &info, nonblock, qmask);
+ if (file->f_flags & SFD_PEEK)
+ ret = signalfd_peek(ctx, &info, ppos, qmask);
+ else
+ ret = signalfd_dequeue(ctx, &info, nonblock, qmask);
if (unlikely(ret <= 0))
break;
@@ -315,7 +362,12 @@ 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 | SFD_QUEUES))
+ if (flags & ~(SFD_CLOEXEC | SFD_NONBLOCK |
+ SFD_RAW | SFD_PEEK | SFD_QUEUES))
+ return -EINVAL;
+
+ /* SFD_PEEK can be used for one queue only */
+ if ((flags & SFD_PEEK) && ((flags & SFD_QUEUES) == SFD_QUEUES))
return -EINVAL;
if (sizemask != sizeof(sigset_t) ||
@@ -352,7 +404,10 @@ SYSCALL_DEFINE4(signalfd4, int, ufd, sigset_t __user *, user_mask,
}
file->f_flags |= (flags & SFD_QUEUES) ? : SFD_QUEUES;
- file->f_flags |= flags & SFD_RAW;
+ file->f_flags |= flags & (SFD_RAW | SFD_PEEK);
+
+ if (file->f_flags & SFD_PEEK)
+ file->f_mode |= FMODE_PREAD;
fd_install(ufd, file);
} else {
diff --git a/include/uapi/linux/signalfd.h b/include/uapi/linux/signalfd.h
index 481b658..24c5d2d 100644
--- a/include/uapi/linux/signalfd.h
+++ b/include/uapi/linux/signalfd.h
@@ -20,6 +20,8 @@
#define SFD_SHARED_QUEUE O_DIRECTORY
/* Read signals from a per-thread queue */
#define SFD_PER_THREAD_QUEUE O_EXCL
+/* Read signals without removing them from a queue */
+#define SFD_PEEK O_APPEND
struct signalfd_siginfo {
__u32 ssi_signo;
--
1.7.11.7
next prev parent reply other threads:[~2013-01-29 19:06 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-01-22 10:15 [PATCH 0/3] signalfd: a kernel interface for dumping pending signals Andrey Vagin
2013-01-22 10:15 ` [PATCH 1/3] signal: add a helper for dequeuing signals from a specified queue Andrey Vagin
2013-02-05 12:00 ` [PATCH 1/3] signal: add a helper for dequeuing signals from a specified queue (v2) Andrey Vagin
2013-01-22 10:15 ` [PATCH 2/3] signalfd: add ability to choose a private or shared queue Andrey Vagin
2013-02-07 18:17 ` Oleg Nesterov
2013-02-08 0:35 ` Michael Kerrisk (man-pages)
2013-02-08 19:12 ` Oleg Nesterov
2013-01-22 10:15 ` [PATCH 3/3] signalfd: add ability to read siginfo-s without dequeuing signals Andrey Vagin
2013-01-29 19:03 ` Andrey Vagin [this message]
[not found] ` <CAKgNAkgQA=zK=2ZnytPFU=DH6jr0sja0iy6K+j6c7unheLFniQ@mail.gmail.com>
2013-02-02 7:15 ` [PATCH 3/3] signalfd: add ability to read siginfo-s without dequeuing signals (v2) Andrey Wagin
2013-02-07 17:34 ` Oleg Nesterov
2013-02-07 21:13 ` Andrey Wagin
2013-02-08 0:51 ` Michael Kerrisk (man-pages)
2013-02-08 19:10 ` Oleg Nesterov
2013-02-08 20:15 ` Michael Kerrisk (man-pages)
2013-02-09 18:22 ` Oleg Nesterov
2013-02-09 22:53 ` Michael Kerrisk (man-pages)
2013-02-10 10:04 ` [CRIU] " Andrew Vagin
2013-02-11 16:47 ` Oleg Nesterov
2013-02-10 10:07 ` Andrew Vagin
2013-02-11 9:29 ` Denys Vlasenko
2013-02-11 10:59 ` [CRIU] " Andrew Vagin
2013-02-11 14:46 ` Denys Vlasenko
2013-02-11 14:53 ` Pavel Emelyanov
2013-02-11 17:25 ` Denys Vlasenko
2013-02-12 14:50 ` Pavel Emelyanov
2013-01-23 4:19 ` [PATCH 0/3] signalfd: a kernel interface for dumping pending signals Michael Kerrisk (man-pages)
2013-01-23 11:03 ` Andrew Vagin
2013-01-23 12:11 ` Michael Kerrisk (man-pages)
2013-01-23 13:03 ` Andrew Vagin
2013-02-07 18:20 ` Oleg Nesterov
2013-02-08 0:36 ` Michael Kerrisk (man-pages)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1359486181-29088-1-git-send-email-avagin@openvz.org \
--to=avagin@openvz.org \
--cc=criu@openvz.org \
--cc=davej@redhat.com \
--cc=dhowells@redhat.com \
--cc=gorcunov@openvz.org \
--cc=linux-api@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mtk.manpages@gmail.com \
--cc=oleg@redhat.com \
--cc=paulmck@linux.vnet.ibm.com \
--cc=viro@zeniv.linux.org.uk \
--cc=xemul@parallels.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).