mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
synced 2025-01-01 10:42:11 +00:00
signal: Pass pid and pid type into send_sigqueue
Make the code more maintainable by performing more of the signal related work in send_sigqueue. A quick inspection of do_timer_create will show that this code path does not lookup a thread group by a thread's pid. Making it safe to find the task pointed to by it_pid with "pid_task(it_pid, type)"; This supports the changes needed in fork to tell if a signal was sent to a single process or a group of processes. Having the pid to task transition in signal.c will also make it easier to sort out races with de_thread and and the thread group leader exiting when it comes time to address that. Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
This commit is contained in:
parent
2118e1f53f
commit
24122c7f49
@ -330,7 +330,7 @@ extern int send_sig(int, struct task_struct *, int);
|
|||||||
extern int zap_other_threads(struct task_struct *p);
|
extern int zap_other_threads(struct task_struct *p);
|
||||||
extern struct sigqueue *sigqueue_alloc(void);
|
extern struct sigqueue *sigqueue_alloc(void);
|
||||||
extern void sigqueue_free(struct sigqueue *);
|
extern void sigqueue_free(struct sigqueue *);
|
||||||
extern int send_sigqueue(struct sigqueue *, struct task_struct *, int group);
|
extern int send_sigqueue(struct sigqueue *, struct pid *, enum pid_type);
|
||||||
extern int do_sigaction(int, struct k_sigaction *, struct k_sigaction *);
|
extern int do_sigaction(int, struct k_sigaction *, struct k_sigaction *);
|
||||||
|
|
||||||
static inline int restart_syscall(void)
|
static inline int restart_syscall(void)
|
||||||
|
@ -1664,17 +1664,20 @@ void sigqueue_free(struct sigqueue *q)
|
|||||||
__sigqueue_free(q);
|
__sigqueue_free(q);
|
||||||
}
|
}
|
||||||
|
|
||||||
int send_sigqueue(struct sigqueue *q, struct task_struct *t, int group)
|
int send_sigqueue(struct sigqueue *q, struct pid *pid, enum pid_type type)
|
||||||
{
|
{
|
||||||
int sig = q->info.si_signo;
|
int sig = q->info.si_signo;
|
||||||
struct sigpending *pending;
|
struct sigpending *pending;
|
||||||
|
struct task_struct *t;
|
||||||
unsigned long flags;
|
unsigned long flags;
|
||||||
int ret, result;
|
int ret, result;
|
||||||
|
|
||||||
BUG_ON(!(q->flags & SIGQUEUE_PREALLOC));
|
BUG_ON(!(q->flags & SIGQUEUE_PREALLOC));
|
||||||
|
|
||||||
ret = -1;
|
ret = -1;
|
||||||
if (!likely(lock_task_sighand(t, &flags)))
|
rcu_read_lock();
|
||||||
|
t = pid_task(pid, type);
|
||||||
|
if (!t || !likely(lock_task_sighand(t, &flags)))
|
||||||
goto ret;
|
goto ret;
|
||||||
|
|
||||||
ret = 1; /* the signal is ignored */
|
ret = 1; /* the signal is ignored */
|
||||||
@ -1696,15 +1699,16 @@ int send_sigqueue(struct sigqueue *q, struct task_struct *t, int group)
|
|||||||
q->info.si_overrun = 0;
|
q->info.si_overrun = 0;
|
||||||
|
|
||||||
signalfd_notify(t, sig);
|
signalfd_notify(t, sig);
|
||||||
pending = group ? &t->signal->shared_pending : &t->pending;
|
pending = (type != PIDTYPE_PID) ? &t->signal->shared_pending : &t->pending;
|
||||||
list_add_tail(&q->list, &pending->list);
|
list_add_tail(&q->list, &pending->list);
|
||||||
sigaddset(&pending->signal, sig);
|
sigaddset(&pending->signal, sig);
|
||||||
complete_signal(sig, t, group);
|
complete_signal(sig, t, type != PIDTYPE_PID);
|
||||||
result = TRACE_SIGNAL_DELIVERED;
|
result = TRACE_SIGNAL_DELIVERED;
|
||||||
out:
|
out:
|
||||||
trace_signal_generate(sig, &q->info, t, group, result);
|
trace_signal_generate(sig, &q->info, t, type != PIDTYPE_PID, result);
|
||||||
unlock_task_sighand(t, &flags);
|
unlock_task_sighand(t, &flags);
|
||||||
ret:
|
ret:
|
||||||
|
rcu_read_unlock();
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -332,8 +332,8 @@ void posixtimer_rearm(struct siginfo *info)
|
|||||||
|
|
||||||
int posix_timer_event(struct k_itimer *timr, int si_private)
|
int posix_timer_event(struct k_itimer *timr, int si_private)
|
||||||
{
|
{
|
||||||
struct task_struct *task;
|
enum pid_type type;
|
||||||
int shared, ret = -1;
|
int ret = -1;
|
||||||
/*
|
/*
|
||||||
* FIXME: if ->sigq is queued we can race with
|
* FIXME: if ->sigq is queued we can race with
|
||||||
* dequeue_signal()->posixtimer_rearm().
|
* dequeue_signal()->posixtimer_rearm().
|
||||||
@ -347,13 +347,8 @@ int posix_timer_event(struct k_itimer *timr, int si_private)
|
|||||||
*/
|
*/
|
||||||
timr->sigq->info.si_sys_private = si_private;
|
timr->sigq->info.si_sys_private = si_private;
|
||||||
|
|
||||||
rcu_read_lock();
|
type = !(timr->it_sigev_notify & SIGEV_THREAD_ID) ? PIDTYPE_TGID : PIDTYPE_PID;
|
||||||
task = pid_task(timr->it_pid, PIDTYPE_PID);
|
ret = send_sigqueue(timr->sigq, timr->it_pid, type);
|
||||||
if (task) {
|
|
||||||
shared = !(timr->it_sigev_notify & SIGEV_THREAD_ID);
|
|
||||||
ret = send_sigqueue(timr->sigq, task, shared);
|
|
||||||
}
|
|
||||||
rcu_read_unlock();
|
|
||||||
/* If we failed to send the signal the timer stops. */
|
/* If we failed to send the signal the timer stops. */
|
||||||
return ret > 0;
|
return ret > 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user