signalfd: make it group-wide, fix posix-timers scheduling
authorOleg Nesterov <oleg@tv-sign.ru>
Wed, 22 Aug 2007 21:01:48 +0000 (14:01 -0700)
committerLinus Torvalds <torvalds@woody.linux-foundation.org>
Thu, 23 Aug 2007 02:52:46 +0000 (19:52 -0700)
With this patch any thread can dequeue its own private signals via signalfd,
even if it was created by another sub-thread.

To do so, we pass "current" to dequeue_signal() if the caller is from the same
thread group. This also fixes the scheduling of posix timers broken by the
previous patch.

If the caller doesn't belong to this thread group, we can't handle __SI_TIMER
case properly anyway. Perhaps we should forbid the cross-process signalfd usage
and convert ctx->tsk to ctx->sighand.

Signed-off-by: Oleg Nesterov <oleg@tv-sign.ru>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Davide Libenzi <davidel@xmailserver.org>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Michael Kerrisk <mtk-manpages@gmx.net>
Cc: Roland McGrath <roland@redhat.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: <stable@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
fs/exec.c
fs/signalfd.c

index ce62f7b65f17aa3963c67c8ff095974489b4f033..af4361c927a9250978dcd0dabd98295b481c75c7 100644 (file)
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -779,19 +779,13 @@ static int de_thread(struct task_struct *tsk)
        struct task_struct *leader = NULL;
        int count;
 
-       /*
-        * Tell all the sighand listeners that this sighand has
-        * been detached. The signalfd_detach() function grabs the
-        * sighand lock, if signal listeners are present on the sighand.
-        */
-       signalfd_detach(tsk);
-
        /*
         * If we don't share sighandlers, then we aren't sharing anything
         * and we can just re-use it all.
         */
        if (atomic_read(&oldsighand->count) <= 1) {
                BUG_ON(atomic_read(&sig->count) != 1);
+               signalfd_detach(tsk);
                exit_itimers(sig);
                return 0;
        }
@@ -930,6 +924,7 @@ static int de_thread(struct task_struct *tsk)
        sig->flags = 0;
 
 no_thread_group:
+       signalfd_detach(tsk);
        exit_itimers(sig);
        if (leader)
                release_task(leader);
index 7b941abbcde09401404a73c5298b73611eea23da..a8e293d3003432ff493eff7069f32305fa35006a 100644 (file)
@@ -56,12 +56,18 @@ static int signalfd_lock(struct signalfd_ctx *ctx, struct signalfd_lockctx *lk)
                sighand = lock_task_sighand(lk->tsk, &lk->flags);
        rcu_read_unlock();
 
-       if (sighand && !ctx->tsk) {
+       if (!sighand)
+               return 0;
+
+       if (!ctx->tsk) {
                unlock_task_sighand(lk->tsk, &lk->flags);
-               sighand = NULL;
+               return 0;
        }
 
-       return sighand != NULL;
+       if (lk->tsk->tgid == current->tgid)
+               lk->tsk = current;
+
+       return 1;
 }
 
 static void signalfd_unlock(struct signalfd_lockctx *lk)
@@ -331,7 +337,7 @@ asmlinkage long sys_signalfd(int ufd, sigset_t __user *user_mask, size_t sizemas
 
                init_waitqueue_head(&ctx->wqh);
                ctx->sigmask = sigmask;
-               ctx->tsk = current;
+               ctx->tsk = current->group_leader;
 
                sighand = current->sighand;
                /*