Author: tridge Date: 2007-01-21 23:37:32 +0000 (Sun, 21 Jan 2007) New Revision: 20941
WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=20941 Log: avoid races in the block/unblock code Modified: branches/SAMBA_4_0/source/lib/events/events_signal.c Changeset: Modified: branches/SAMBA_4_0/source/lib/events/events_signal.c =================================================================== --- branches/SAMBA_4_0/source/lib/events/events_signal.c 2007-01-21 22:14:05 UTC (rev 20940) +++ branches/SAMBA_4_0/source/lib/events/events_signal.c 2007-01-21 23:37:32 UTC (rev 20941) @@ -54,6 +54,7 @@ #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 @@ sigemptyset(&set); sigaddset(&set, signum); sigprocmask(SIG_BLOCK, &set, NULL); + SIG_INCREMENT(sig_state.sig_blocked[signum]); } } #endif @@ -226,7 +228,8 @@ 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 @@ 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) {