s3:winbindd: fix problems with SIGCHLD handling (bug #7317)
authorStefan Metzmacher <metze@samba.org>
Thu, 1 Apr 2010 14:23:06 +0000 (16:23 +0200)
committerKarolin Seeger <kseeger@samba.org>
Mon, 17 May 2010 07:50:11 +0000 (09:50 +0200)
The main problem is that we call CatchChild() within the
parent winbindd, which overwrites the signal handler
that was registered by winbindd_setup_sig_chld_handler().

That means winbindd_sig_chld_handler() and winbind_child_died()
are never triggered when a winbindd domain child dies.
As a result will get "broken pipe" for all requests to that domain.

To reduce the risk of similar bugs in future we call
CatchChild() in winbindd_reinit_after_fork() now.

We also use a full winbindd_reinit_after_fork() in the
cache validation child now instead instead of just resetting
the SIGCHLD handler by hand. This will also fix possible
tdb problems on systems without pread/pwrite and disabled mmap
as we now correctly reopen the tdb handle for the child.

metze
(cherry picked from commit 73577205cf81644e7fe853eaf3e6459f7f443096)
(cherry picked from commit e7b9c148d6fe155bd8afb8ff9b148eaf4092ff4e)

source3/winbindd/winbindd.c
source3/winbindd/winbindd_cm.c
source3/winbindd/winbindd_dual.c

index 300c78e356ebdac41261fcf709f27ab6775eafcd..0258f3c738800d6ac2b64be45cec70fecae403c3 100644 (file)
@@ -383,7 +383,6 @@ static void winbind_msg_validate_cache(struct messaging_context *msg_ctx,
         * so we don't block the main winbindd and the validation
         * code can safely use fork/waitpid...
         */
-       CatchChild();
        child_pid = sys_fork();
 
        if (child_pid == -1) {
@@ -401,16 +400,9 @@ static void winbind_msg_validate_cache(struct messaging_context *msg_ctx,
 
        /* child */
 
-       /* install default SIGCHLD handler: validation code uses fork/waitpid */
-       ZERO_STRUCT(act);
-       act.sa_handler = SIG_DFL;
-#ifdef SA_RESTART
-       /* We *want* SIGALRM to interrupt a system call. */
-       act.sa_flags = SA_RESTART;
-#endif
-       sigemptyset(&act.sa_mask);
-       sigaddset(&act.sa_mask,SIGCHLD);
-       sigaction(SIGCHLD,&act,&oldact);
+       if (!winbindd_reinit_after_fork(NULL)) {
+               _exit(0);
+       }
 
        ret = (uint8)winbindd_validate_cache_nobackup();
        DEBUG(10, ("winbindd_msg_validata_cache: got return value %d\n", ret));
index 62466f8f02b68cd022506c8e4f6a579521415ebe..34c1a397657f1616416e2088c323ef3f4425e312 100644 (file)
@@ -179,9 +179,6 @@ static bool fork_child_dc_connect(struct winbindd_domain *domain)
        pid_t parent_pid = sys_getpid();
        char *lfile = NULL;
 
-       /* Stop zombies */
-       CatchChild();
-
        if (domain->dc_probe_pid != (pid_t)-1) {
                /*
                 * We might already have a DC probe
index beeeeb29027f2d812ff0fad0b0183743e18ebde0..44e8552e1ac564902a0cd7b60dfb78b5c1f6e059 100644 (file)
@@ -1215,6 +1215,9 @@ bool winbindd_reinit_after_fork(const char *logfilename)
                                            logfilename))
                return false;
 
+       /* Stop zombies in children */
+       CatchChild();
+
        /* Don't handle the same messages as our parent. */
        messaging_deregister(winbind_messaging_context(),
                             MSG_SMB_CONF_UPDATED, NULL);
@@ -1338,9 +1341,6 @@ static bool fork_domain_child(struct winbindd_child *child)
 
        DEBUG(10, ("Child process %d\n", (int)sys_getpid()));
 
-       /* Stop zombies in children */
-       CatchChild();
-
        state.sock = fdpair[0];
        close(fdpair[1]);