History

signalfd simplification

This simplifies signalfd code, by avoiding it to remain attached to the sighand during its lifetime. In this way, the signalfd remain attached to the sighand only during poll(2) (and select and epoll) and read(2). This also allows to remove all the custom "tsk == current" checks in kernel/signal.c, since dequeue_signal() will only be called by "current". I think this is also what Ben was suggesting time ago. The external effect of this, is that a thread can extract only its own private signals and the group ones. I think this is an acceptable behaviour, in that those are the signals the thread would be able to fetch w/out signalfd.

Davide Libenzi committed 19 years ago

Commit b8fceee1 parent 9db619e8 files · +39 −217Browse files

Showing the changes to include/linux (3 of 8 files). Show all

Unified · Split

3 files
  1. include/linux/init_task.h +1 −1
  2. include/linux/sched.h +1 −1
  3. include/linux/signalfd.h +4 −36
include/linux/init_task.h+1−1
@@ -86,7 +86,7 @@ extern struct nsproxy init_nsproxy; · 85 unmodified lines
86 .count = ATOMIC_INIT(1), \86 .count = ATOMIC_INIT(1), \
87 .action = { { { .sa_handler = NULL, } }, }, \87 .action = { { { .sa_handler = NULL, } }, }, \
88 .siglock = __SPIN_LOCK_UNLOCKED(sighand.siglock), \88 .siglock = __SPIN_LOCK_UNLOCKED(sighand.siglock), \
89 .signalfd_list = LIST_HEAD_INIT(sighand.signalfd_list), \89 .signalfd_wqh = __WAIT_QUEUE_HEAD_INITIALIZER(sighand.signalfd_wqh), \
90}90}
91 91
92extern struct group_info init_groups;92extern struct group_info init_groups;
include/linux/sched.h+1−1
@@ -438,7 +438,7 @@ struct sighand_struct { · 437 unmodified lines
438 atomic_t count;438 atomic_t count;
439 struct k_sigaction action[_NSIG];439 struct k_sigaction action[_NSIG];
440 spinlock_t siglock;440 spinlock_t siglock;
441 struct list_head signalfd_list;441 wait_queue_head_t signalfd_wqh;
442};442};
443 443
444struct pacct_struct {444struct pacct_struct {
include/linux/signalfd.h+4−36
@@ -45,49 +45,17 @@ struct signalfd_siginfo { · 44 unmodified lines
45#ifdef CONFIG_SIGNALFD45#ifdef CONFIG_SIGNALFD
46 46
47/*47/*
48 * Deliver the signal to listening signalfd. This must be called48 * Deliver the signal to listening signalfd.
49 * with the sighand lock held. Same are the following that end up
50 * calling signalfd_deliver().
51 */
52void signalfd_deliver(struct task_struct *tsk, int sig);
53
54/*
55 * No need to fall inside signalfd_deliver() if no signal listeners
56 * are available.
57 */49 */
58static inline void signalfd_notify(struct task_struct *tsk, int sig)50static inline void signalfd_notify(struct task_struct *tsk, int sig)
59{51{
60 if (unlikely(!list_empty(&tsk->sighand->signalfd_list)))52 if (unlikely(waitqueue_active(&tsk->sighand->signalfd_wqh)))
61 signalfd_deliver(tsk, sig);53 wake_up(&tsk->sighand->signalfd_wqh);
62}
63
64/*
65 * The signal -1 is used to notify the signalfd that the sighand
66 * is on its way to be detached.
67 */
68static inline void signalfd_detach_locked(struct task_struct *tsk)
69{
70 if (unlikely(!list_empty(&tsk->sighand->signalfd_list)))
71 signalfd_deliver(tsk, -1);
72}
73
74static inline void signalfd_detach(struct task_struct *tsk)
75{
76 struct sighand_struct *sighand = tsk->sighand;
77
78 if (unlikely(!list_empty(&sighand->signalfd_list))) {
79 spin_lock_irq(&sighand->siglock);
80 signalfd_deliver(tsk, -1);
81 spin_unlock_irq(&sighand->siglock);
82 }
83}54}
84 55
85#else /* CONFIG_SIGNALFD */56#else /* CONFIG_SIGNALFD */
86 57
87#define signalfd_deliver(t, s) do { } while (0)58static inline void signalfd_notify(struct task_struct *tsk, int sig) { }
88#define signalfd_notify(t, s) do { } while (0)
89#define signalfd_detach_locked(t) do { } while (0)
90#define signalfd_detach(t) do { } while (0)
91 59
92#endif /* CONFIG_SIGNALFD */60#endif /* CONFIG_SIGNALFD */
93 61

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t