From 1781c9da1fdbef71dd9c51918c4a9ca345170417 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Thu, 1 Apr 2010 16:23:06 +0200 Subject: [PATCH 1/3] s3:winbindd: fix problems with SIGCHLD handling (bug #7317) 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 e0ece652956292cc67383535a0fa174b5015d91e) --- source3/winbindd/winbindd.c | 14 +++----------- source3/winbindd/winbindd_cm.c | 3 --- source3/winbindd/winbindd_dual.c | 6 +++--- 3 files changed, 6 insertions(+), 17 deletions(-) diff --git a/source3/winbindd/winbindd.c b/source3/winbindd/winbindd.c index 033eea1..46af5c1 100644 --- a/source3/winbindd/winbindd.c +++ b/source3/winbindd/winbindd.c @@ -378,7 +378,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) { @@ -396,16 +395,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)); diff --git a/source3/winbindd/winbindd_cm.c b/source3/winbindd/winbindd_cm.c index 5829718..670e494 100644 --- a/source3/winbindd/winbindd_cm.c +++ b/source3/winbindd/winbindd_cm.c @@ -174,9 +174,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 diff --git a/source3/winbindd/winbindd_dual.c b/source3/winbindd/winbindd_dual.c index ab4807b..72e5607 100644 --- a/source3/winbindd/winbindd_dual.c +++ b/source3/winbindd/winbindd_dual.c @@ -1167,6 +1167,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); @@ -1282,9 +1285,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]); -- 1.6.3.3 From ebf483c1cfb8aa849504019b89fbe0a139b73f14 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Thu, 1 Apr 2010 18:10:47 +0200 Subject: [PATCH 2/3] s3:winbindd: remove unused variables metze (cherry picked from commit e18ddb6036f5e0a2211e89a7c9b5514c30a653cf) (cherry picked from commit c64c867c307d32b8ec17d6e079395e0e9b604f00) --- source3/winbindd/winbindd.c | 2 -- 1 files changed, 0 insertions(+), 2 deletions(-) diff --git a/source3/winbindd/winbindd.c b/source3/winbindd/winbindd.c index 46af5c1..7d4c996 100644 --- a/source3/winbindd/winbindd.c +++ b/source3/winbindd/winbindd.c @@ -367,8 +367,6 @@ static void winbind_msg_validate_cache(struct messaging_context *msg_ctx, { uint8 ret; pid_t child_pid; - struct sigaction act; - struct sigaction oldact; DEBUG(10, ("winbindd_msg_validate_cache: got validate-cache " "message.\n")); -- 1.6.3.3 From 61f40ae3fe46ca33263802d6761e49bc3461d2b9 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Thu, 8 Apr 2010 12:45:54 +0200 Subject: [PATCH 3/3] s3:winbindd: make "smbcontrol winbindd validate-cache" reliable again commit 73577205cf81644e7fe853eaf3e6459f7f443096 (s3:winbindd: fix problems with SIGCHLD handling (bug #7317)) broke this. metze (cherry picked from commit eb9b7d0363669574de8ec380089407890f15eac2) --- source3/winbindd/winbindd.c | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-) diff --git a/source3/winbindd/winbindd.c b/source3/winbindd/winbindd.c index 7d4c996..0443ebf 100644 --- a/source3/winbindd/winbindd.c +++ b/source3/winbindd/winbindd.c @@ -397,6 +397,9 @@ static void winbind_msg_validate_cache(struct messaging_context *msg_ctx, _exit(0); } + /* install default SIGCHLD handler: validation code uses fork/waitpid */ + CatchSignal(SIGCHLD, SIG_DFL); + ret = (uint8)winbindd_validate_cache_nobackup(); DEBUG(10, ("winbindd_msg_validata_cache: got return value %d\n", ret)); messaging_send_buf(msg_ctx, server_id, MSG_WINBIND_VALIDATE_CACHE, &ret, -- 1.6.3.3