summaryrefslogtreecommitdiff
path: root/source4/lib
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2007-01-21 23:37:32 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 14:43:56 -0500
commitfa5e920a7b4a2eba450189af35e0b5eeab80cdbc (patch)
tree4203765d0b953d7a65948e6545e3ae9f5e2cd2c4 /source4/lib
parent0c846b1b2db4054914a7275f9bff6155b68720b6 (diff)
downloadsamba-fa5e920a7b4a2eba450189af35e0b5eeab80cdbc.tar.gz
samba-fa5e920a7b4a2eba450189af35e0b5eeab80cdbc.tar.bz2
samba-fa5e920a7b4a2eba450189af35e0b5eeab80cdbc.zip
r20941: avoid races in the block/unblock code
(This used to be commit 83353ec0cd05464abb581f51d8c26ade7f0876fe)
Diffstat (limited to 'source4/lib')
-rw-r--r--source4/lib/events/events_signal.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/source4/lib/events/events_signal.c b/source4/lib/events/events_signal.c
index 28702cecc9..21542d863b 100644
--- a/source4/lib/events/events_signal.c
+++ b/source4/lib/events/events_signal.c
@@ -54,6 +54,7 @@ static struct {
#ifdef SA_SIGINFO
/* with SA_SIGINFO we get quite a lot of info per signal */
siginfo_t *sig_info[NUM_SIGNALS];
+ struct sigcounter sig_blocked[NUM_SIGNALS];
#endif
} sig_state;
@@ -99,6 +100,7 @@ static void signal_handler_info(int signum, siginfo_t *info, void *uctx)
sigemptyset(&set);
sigaddset(&set, signum);
sigprocmask(SIG_BLOCK, &set, NULL);
+ SIG_INCREMENT(sig_state.sig_blocked[signum]);
}
}
#endif
@@ -226,7 +228,8 @@ int common_event_check_signal(struct event_context *ev)
for (i=0;i<NUM_SIGNALS+1;i++) {
struct signal_event *se, *next;
- uint32_t count = sig_count(sig_state.signal_count[i]);
+ struct sigcounter counter = sig_state.signal_count[i];
+ uint32_t count = sig_count(counter);
if (count == 0) {
continue;
@@ -237,16 +240,21 @@ int common_event_check_signal(struct event_context *ev)
if (se->sa_flags & SA_SIGINFO) {
int j;
for (j=0;j<count;j++) {
+ /* note the use of the sig_info array as a
+ ring buffer */
+ int ofs = (counter.count + j) % SA_INFO_QUEUE_COUNT;
se->handler(ev, se, i, 1,
- (void*)&sig_state.sig_info[i][j],
+ (void*)&sig_state.sig_info[i][ofs],
se->private_data);
}
- if (count == SA_INFO_QUEUE_COUNT) {
+ if (SIG_PENDING(sig_state.sig_blocked[i])) {
/* we'd filled the queue, unblock the
signal now */
sigset_t set;
sigemptyset(&set);
sigaddset(&set, i);
+ SIG_SEEN(sig_state.sig_blocked[i],
+ sig_count(sig_state.sig_blocked[i]));
sigprocmask(SIG_UNBLOCK, &set, NULL);
}
if (se->sa_flags & SA_RESETHAND) {