s3: signals are processed twice in child.
authorBo Yang <boyang@samba.org>
Tue, 9 Feb 2010 09:02:20 +0000 (17:02 +0800)
committerBo Yang <boyang@samba.org>
Tue, 9 Feb 2010 09:05:58 +0000 (17:05 +0800)
Signed-off-by: Bo Yang <boyang@samba.org>
lib/tevent/tevent.c
lib/tevent/tevent_internal.h
lib/tevent/tevent_signal.c

index 56d0da39276ee3489b59b8d81ab495d601266903..a0ee208663880d0429de3744a2b8c951e6ed183f 100644 (file)
@@ -176,6 +176,13 @@ int tevent_common_context_destructor(struct tevent_context *ev)
                sn = se->next;
                se->event_ctx = NULL;
                DLIST_REMOVE(ev->signal_events, se);
+               /*
+                * This is important, Otherwise signals
+                * are handled twice in child. eg, SIGHUP.
+                * one added in parent, and another one in
+                * the child. -- BoYang
+                */
+               tevent_cleanup_pending_signal_handlers(se);
        }
 
        return 0;
index e10f52e71138ccfd78f4640300096d29aa4d3a32..7f5fd6485406e3033301239e0b17f59459a3728b 100644 (file)
@@ -299,6 +299,7 @@ struct tevent_signal *tevent_common_add_signal(struct tevent_context *ev,
                                               const char *handler_name,
                                               const char *location);
 int tevent_common_check_signal(struct tevent_context *ev);
+void tevent_cleanup_pending_signal_handlers(struct tevent_signal *se);
 
 bool tevent_standard_init(void);
 bool tevent_select_init(void);
index 0f3d83e8775db0d3338e1728ec309911b7d28564..45f65cf6dddf9e3f45cb1554c8e80c75474302ab 100644 (file)
@@ -133,7 +133,9 @@ static void tevent_common_signal_handler_info(int signum, siginfo_t *info,
 
 static int tevent_common_signal_list_destructor(struct tevent_common_signal_list *sl)
 {
-       DLIST_REMOVE(sig_state->sig_handlers[sl->se->signum], sl);
+       if (sig_state->sig_handlers[sl->se->signum]) {
+               DLIST_REMOVE(sig_state->sig_handlers[sl->se->signum], sl);
+       }
        return 0;
 }
 
@@ -154,12 +156,16 @@ static int tevent_signal_destructor(struct tevent_signal *se)
 
        if (sig_state->sig_handlers[se->signum] == NULL) {
                /* restore old handler, if any */
-               sigaction(se->signum, sig_state->oldact[se->signum], NULL);
-               sig_state->oldact[se->signum] = NULL;
+               if (sig_state->oldact[se->signum]) {
+                       sigaction(se->signum, sig_state->oldact[se->signum], NULL);
+                       sig_state->oldact[se->signum] = NULL;
+               }
 #ifdef SA_SIGINFO
                if (se->sa_flags & SA_SIGINFO) {
-                       talloc_free(sig_state->sig_info[se->signum]);
-                       sig_state->sig_info[se->signum] = NULL;
+                       if (sig_state->sig_info[se->signum]) {
+                               talloc_free(sig_state->sig_info[se->signum]);
+                               sig_state->sig_info[se->signum] = NULL;
+                       }
                }
 #endif
        }
@@ -398,3 +404,20 @@ int tevent_common_check_signal(struct tevent_context *ev)
 
        return 1;
 }
+
+void tevent_cleanup_pending_signal_handlers(struct tevent_signal *se)
+{
+       struct tevent_common_signal_list *sl;
+       sl = talloc_get_type(se->additional_data,
+                            struct tevent_common_signal_list);
+
+       tevent_common_signal_list_destructor(sl);
+
+       if (sig_state->sig_handlers[se->signum] == NULL) {
+               if (sig_state->oldact[se->signum]) {
+                       sigaction(se->signum, sig_state->oldact[se->signum], NULL);
+                       sig_state->oldact[se->signum] = NULL;
+               }
+       }
+       return;
+}