mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Davi Arnaut <davi@haxent.com.br>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Davide Libenzi <davidel@xmailserver.org>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: [patch 04/22] pollfs: pollable signal
Date: Wed, 02 May 2007 02:22:39 -0300	[thread overview]
Message-ID: <20070502053424.789588000@haxent.com.br> (raw)
In-Reply-To: <20070502052235.914764000@haxent.com.br>

[-- Attachment #1: pollfs-signal.patch --]
[-- Type: text/plain, Size: 4313 bytes --]

Retrieve multiple per-process signals through a file descriptor. The mask
of signals can be changed at any time. Also, the compat code can be kept
very simple.

Signed-off-by: Davi E. M. Arnaut <davi@haxent.com.br>

---
 fs/pollfs/Makefile |    2 
 fs/pollfs/signal.c |  144 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 init/Kconfig       |    7 ++
 3 files changed, 153 insertions(+)

Index: linux-2.6/fs/pollfs/signal.c
===================================================================
--- /dev/null
+++ linux-2.6/fs/pollfs/signal.c
@@ -0,0 +1,144 @@
+/*
+ * sigtimedwait4, retrieve multiple signals with one call.
+ *
+ * Copyright (C) 2007 Davi E. M. Arnaut
+ *
+ * Licensed under the GNU GPL. See the file COPYING for details.
+ */
+
+#include <linux/kernel.h>
+#include <linux/sched.h>
+#include <linux/module.h>
+#include <linux/slab.h>
+#include <linux/err.h>
+#include <linux/wait.h>
+#include <asm/uaccess.h>
+#include <linux/poll.h>
+#include <linux/pollfs_fs.h>
+#include <linux/signal.h>
+
+struct pfs_signal {
+	sigset_t set;
+	spinlock_t lock;
+	struct task_struct *task;
+	struct pfs_file file;
+};
+
+static void inline sigset_adjust(sigset_t *set)
+{
+	/* SIGKILL and SIGSTOP cannot be caught, blocked, or ignored */
+	sigdelsetmask(set, sigmask(SIGKILL) | sigmask(SIGSTOP));
+
+	/* Signals we don't want to dequeue */
+	signotset(set);
+}
+
+static ssize_t read(struct pfs_signal *evs, siginfo_t __user *infoup)
+{
+	int signo;
+	siginfo_t info;
+
+	signo = dequeue_signal_lock(evs->task, &evs->set, &info);
+	if (!signo)
+		return -EAGAIN;
+
+	if (copy_siginfo_to_user(infoup, &info))
+		return -EFAULT;
+
+	return 0;
+}
+
+static ssize_t write(struct pfs_signal *evs, const sigset_t __user *uset)
+{
+	sigset_t set;
+
+	if (copy_from_user(&set, uset, sizeof(sigset_t)))
+		return -EFAULT;
+
+	sigset_adjust(&set);
+
+	spin_lock_irq(&evs->lock);
+	sigemptyset(&evs->set);
+	sigorsets(&evs->set, &evs->set, &set);
+	spin_unlock_irq(&evs->lock);
+
+	return 0;
+}
+
+static int poll(struct pfs_signal *evs)
+{
+	int ret = 0;
+	sigset_t pending;
+	unsigned long flags;
+
+	rcu_read_lock();
+
+	if (!lock_task_sighand(evs->task, &flags))
+		goto out_unlock;
+
+	sigorsets(&pending, &evs->task->pending.signal,
+		  &evs->task->signal->shared_pending.signal);
+
+	unlock_task_sighand(evs->task, &flags);
+
+	spin_lock_irqsave(&evs->lock, flags);
+	signandsets(&pending, &pending, &evs->set);
+	spin_unlock_irqrestore(&evs->lock, flags);
+
+	if (!sigisemptyset(&pending))
+		ret = POLLIN;
+
+out_unlock:
+	rcu_read_unlock();
+
+	return ret;
+}
+
+static int release(struct pfs_signal *evs)
+{
+	put_task_struct(evs->task);
+	kfree(evs);
+
+	return 0;
+}
+
+static const struct pfs_operations signal_ops = {
+	.read		= PFS_READ(read, struct pfs_signal, siginfo_t),
+	.write		= PFS_WRITE(write, struct pfs_signal, sigset_t),
+	.poll		= PFS_POLL(poll, struct pfs_signal),
+	.release	= PFS_RELEASE(release, struct pfs_signal),
+	.rsize		= sizeof(siginfo_t),
+	.wsize		= sizeof(sigset_t),
+};
+
+asmlinkage long sys_plsignal(const sigset_t __user *uset)
+{
+	long error;
+	struct pfs_signal *evs;
+
+	evs = kmalloc(sizeof(*evs), GFP_KERNEL);
+	if (!evs)
+		return -ENOMEM;
+
+	if (copy_from_user(&evs->set, uset, sizeof(sigset_t))) {
+		kfree(evs);
+		return -EFAULT;
+	}
+
+	spin_lock_init(&evs->lock);
+
+	evs->task = current;
+	get_task_struct(current);
+
+	sigset_adjust(&evs->set);
+
+	evs->file.data = evs;
+	evs->file.fops = &signal_ops;
+	evs->file.wait = &evs->task->sigwait;
+
+	error = pfs_open(&evs->file);
+	if (error < 0)
+		release(evs);
+
+	return error;
+}
Index: linux-2.6/fs/pollfs/Makefile
===================================================================
--- linux-2.6.orig/fs/pollfs/Makefile
+++ linux-2.6/fs/pollfs/Makefile
@@ -1,2 +1,4 @@
 obj-$(CONFIG_POLLFS) += pollfs.o
 pollfs-y := file.o
+
+pollfs-$(CONFIG_POLLFS_SIGNAL) += signal.o
Index: linux-2.6/init/Kconfig
===================================================================
--- linux-2.6.orig/init/Kconfig
+++ linux-2.6/init/Kconfig
@@ -469,6 +469,13 @@ config POLLFS
 	help
 	 Pollfs support
 
+config POLLFS_SIGNAL
+	bool "Enable pollfs signal" if EMBEDDED
+	default y
+	depends on POLLFS
+	help
+	 Pollable signal support
+
 config SHMEM
 	bool "Use full shmem filesystem" if EMBEDDED
 	default y

--

  parent reply	other threads:[~2007-05-02  5:42 UTC|newest]

Thread overview: 71+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-05-02  5:22 [patch 00/22] pollfs: filesystem abstraction for pollable objects Davi Arnaut
2007-05-02  5:22 ` [patch 01/22] pollfs: kernel-side API header Davi Arnaut
2007-05-02  5:22 ` [patch 02/22] pollfs: file system operations Davi Arnaut
2007-05-02  5:22 ` [patch 03/22] pollfs: asynchronously wait for a signal Davi Arnaut
2007-05-02  5:22 ` Davi Arnaut [this message]
2007-05-02  5:22 ` [patch 05/22] pollfs: pollable signal compat code Davi Arnaut
2007-05-02  5:22 ` [patch 06/22] pollfs: export the plsignal system call Davi Arnaut
2007-05-02  5:22 ` [patch 07/22] pollfs: x86, wire up " Davi Arnaut
2007-05-02  5:22 ` [patch 08/22] pollfs: x86_64, " Davi Arnaut
2007-05-02  5:22 ` [patch 09/22] pollfs: pollable hrtimers Davi Arnaut
2007-05-02 21:16   ` Thomas Gleixner
2007-05-02 23:00     ` Davi Arnaut
2007-05-02  5:22 ` [patch 10/22] pollfs: export the pltimer system call Davi Arnaut
2007-05-02  5:22 ` [patch 11/22] pollfs: x86, wire up " Davi Arnaut
2007-05-02  5:22 ` [patch 12/22] pollfs: x86_64, " Davi Arnaut
2007-05-02  5:22 ` [patch 13/22] pollfs: asynchronous futex wait Davi Arnaut
2007-05-02  5:22 ` [patch 14/22] pollfs: pollable futex Davi Arnaut
2007-05-02  5:54   ` Eric Dumazet
2007-05-02  6:16     ` Davi Arnaut
2007-05-02  6:39       ` Eric Dumazet
2007-05-02  6:54         ` Davi Arnaut
2007-05-02  7:11         ` Davi Arnaut
2007-05-02  7:40   ` Ulrich Drepper
2007-05-02  7:55     ` Eric Dumazet
2007-05-02  8:08       ` Ulrich Drepper
2007-05-02  8:49         ` Eric Dumazet
2007-05-02 16:39           ` Ulrich Drepper
2007-05-02 16:59             ` Davi Arnaut
2007-05-02 17:10               ` Ulrich Drepper
2007-05-02 17:29                 ` Davide Libenzi
2007-05-02 17:53                   ` Ulrich Drepper
2007-05-02 18:21                     ` Davide Libenzi
2007-05-03 13:46                       ` Ulrich Drepper
2007-05-03 18:24                         ` Davide Libenzi
2007-05-03 19:03                           ` Ulrich Drepper
2007-05-03 22:14                             ` Davide Libenzi
2007-05-04 15:28                               ` Ulrich Drepper
2007-05-04 19:15                                 ` Davide Libenzi
2007-05-04 19:20                                   ` 2.6.20.4 / 2.6.21.1 AT91SAM9260-EK oops Ryan Ordway
2007-05-04 23:38                                   ` [patch 14/22] pollfs: pollable futex Ulrich Drepper
2007-05-05 18:54                                     ` Davide Libenzi
2007-05-06  7:50                                       ` Ulrich Drepper
2007-05-06 19:47                                         ` Davide Libenzi
2007-05-06 19:54                                         ` Andrew Morton
2007-05-06 20:18                                           ` Davide Libenzi
2007-05-06 21:57                                           ` Davi Arnaut
2007-05-07  5:33                                           ` Ulrich Drepper
2007-05-07  5:46                                           ` Ulrich Drepper
2007-05-02 17:37                 ` Davi Arnaut
2007-05-02 17:49                   ` Ulrich Drepper
2007-05-02 18:05                     ` Davi Arnaut
2007-05-03 13:40                       ` Ulrich Drepper
2007-05-02 12:20     ` Davi Arnaut
2007-05-02 12:39     ` Davi Arnaut
2007-05-02 16:46       ` Ulrich Drepper
2007-05-02 17:05         ` Davi Arnaut
2007-05-02  5:22 ` [patch 15/22] pollfs: export the plfutex system call Davi Arnaut
2007-05-02  5:22 ` [patch 16/22] pollfs: x86, wire up " Davi Arnaut
2007-05-02  5:22 ` [patch 17/22] pollfs: x86_64, " Davi Arnaut
2007-05-02  5:22 ` [patch 18/22] pollfs: check if a AIO event ring is empty Davi Arnaut
2007-05-02  5:22 ` [patch 19/22] pollfs: pollable aio Davi Arnaut
2007-05-02  5:22 ` [patch 20/22] pollfs: export the plaio system call Davi Arnaut
2007-05-02  5:22 ` [patch 21/22] pollfs: x86, wire up " Davi Arnaut
2007-05-02  5:22 ` [patch 22/22] pollfs: x86_64, " Davi Arnaut
2007-05-02  6:05 ` [patch 00/22] pollfs: filesystem abstraction for pollable objects Andrew Morton
2007-05-02 17:28   ` Davide Libenzi
2007-05-02 17:47     ` Davi Arnaut
2007-05-02 18:23       ` Davide Libenzi
2007-05-02 18:50         ` Davi Arnaut
2007-05-02 19:42           ` Davide Libenzi
2007-05-02 20:11             ` Davi Arnaut

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=20070502053424.789588000@haxent.com.br \
    --to=davi@haxent.com.br \
    --cc=akpm@linux-foundation.org \
    --cc=davidel@xmailserver.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@linux-foundation.org \
    /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

all inboxes | Powered by JetHome®