>From 2b8b475b39f41ca65e623905b2f7d2d9348bfa84 Mon Sep 17 00:00:00 2001 From: Andrey Vagin <avagin@openvz.org> Date: Thu, 29 Nov 2012 20:51:49 +0400 Subject: [PATCH 1/2] signal: add helper to get siginfo without removing from the queue Signed-off-by: Andrey Vagin <avagin@openvz.org> --- include/linux/sched.h | 2 ++ kernel/signal.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/include/linux/sched.h b/include/linux/sched.h index 206bb08..a907854 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -2222,6 +2222,8 @@ extern void __flush_signals(struct task_struct *); extern void ignore_signals(struct task_struct *); extern void flush_signal_handlers(struct task_struct *, int force_default); extern int dequeue_signal(struct task_struct *tsk, sigset_t *mask, siginfo_t *info); +extern int peek_signal(struct task_struct *tsk, sigset_t *mask, + siginfo_t *info, int offset, bool group); static inline int dequeue_signal_lock(struct task_struct *tsk, sigset_t *mask, siginfo_t *info) { diff --git a/kernel/signal.c b/kernel/signal.c index ac5f5e7..aa71213 100644 --- a/kernel/signal.c +++ b/kernel/signal.c @@ -536,6 +536,34 @@ unblock_all_signals(void) spin_unlock_irqrestore(¤t->sighand->siglock, flags); } +int peek_signal(struct task_struct *tsk, sigset_t *mask, + siginfo_t *info, int offset, bool group) +{ + struct sigpending *pending; + struct sigqueue *q; + int i = 0, ret = 0; + + if (group) + pending = &tsk->signal->shared_pending; + else + pending = &tsk->pending; + + list_for_each_entry(q, &pending->list, list) { + if (sigismember(mask, q->info.si_signo)) + continue; + + if (i == offset) { + copy_siginfo(info, &q->info); + ret = info->si_signo; + break; + } + + i++; + } + + return ret; +} + static void collect_signal(int sig, struct sigpending *list, siginfo_t *info) { struct sigqueue *q, *first = NULL; -- 1.7.11.7