clean event context after child is forked.
authorBo Yang <boyang@novell.com>
Mon, 5 Jan 2009 11:47:45 +0000 (19:47 +0800)
committerStefan Metzmacher <metze@samba.org>
Mon, 5 Jan 2009 14:07:31 +0000 (15:07 +0100)
Signed-off-by: Stefan Metzmacher <metze@samba.org>
source3/include/proto.h
source3/lib/events.c
source3/lib/util.c
source3/nmbd/asyncdns.c
source3/nmbd/nmbd.c
source3/printing/print_cups.c
source3/printing/printing.c
source3/smbd/server.c
source3/winbindd/winbindd.c
source3/winbindd/winbindd_cm.c
source3/winbindd/winbindd_dual.c

index 6238ba3d008c3670efaefe92d21e1cf39ed9ef3e..a361c62f75a4aec36e36e4cbd35e46acb337272a 100644 (file)
@@ -534,6 +534,7 @@ bool run_events(struct event_context *event_ctx,
 struct timeval *get_timed_events_timeout(struct event_context *event_ctx,
                                         struct timeval *to_ret);
 int event_loop_once(struct event_context *ev);
+void event_context_reinit(struct event_context *ev);
 struct event_context *event_context_init(TALLOC_CTX *mem_ctx);
 int set_event_dispatch_time(struct event_context *event_ctx,
                            const char *event_name, struct timeval when);
@@ -1183,6 +1184,7 @@ int set_blocking(int fd, bool set);
 void smb_msleep(unsigned int t);
 void become_daemon(bool Fork, bool no_process_group);
 bool reinit_after_fork(struct messaging_context *msg_ctx,
+                      struct event_context *ev_ctx,
                       bool parent_longlived);
 bool yesno(const char *p);
 void *malloc_(size_t size);
index 8bbc9497ac7ec9642ca55d2c160820ac2050da47..7d4cdc209bd1f97e13799e94776a9ed1ef9453b0 100644 (file)
@@ -369,6 +369,12 @@ static int event_context_destructor(struct event_context *ev)
        return 0;
 }
 
+void event_context_reinit(struct event_context *ev)
+{
+       event_context_destructor(ev);
+       return;
+}
+
 struct event_context *event_context_init(TALLOC_CTX *mem_ctx)
 {
        struct event_context *result;
index d00a764c1d543dbb377cfdd13cdb4a4c51717b6e..08ea5add7a559a0bf83c02fae6ea99c5c7d7397e 100644 (file)
@@ -949,6 +949,7 @@ void become_daemon(bool Fork, bool no_process_group)
 }
 
 bool reinit_after_fork(struct messaging_context *msg_ctx,
+                      struct event_context *ev_ctx,
                       bool parent_longlived)
 {
        NTSTATUS status;
@@ -976,6 +977,8 @@ bool reinit_after_fork(struct messaging_context *msg_ctx,
                return false;
        }
 
+       event_context_reinit(ev_ctx);
+
        return true;
 }
 
index ab9b1ed740eeb1b324e4e506ecf8037a5fd60b74..baa88bc44b5be24d6a392329eb8cbef78f897d17 100644 (file)
@@ -164,7 +164,8 @@ void start_async_dns(void)
        CatchSignal(SIGHUP, SIG_IGN);
         CatchSignal(SIGTERM, SIGNAL_CAST sig_term );
 
-       if (!reinit_after_fork(nmbd_messaging_context(), true)) {
+       if (!reinit_after_fork(nmbd_messaging_context(),
+                              nmbd_event_context(), true)) {
                DEBUG(0,("reinit_after_fork() failed\n"));
                smb_panic("reinit_after_fork() failed");
        }
index d1ab3aaacbd9e43dfefa2e47b9d778137ebbcd3a..659db85e69f480da035444f952a7da387ec86b7b 100644 (file)
@@ -911,7 +911,8 @@ static bool open_sockets(bool isdaemon, int port)
 
        pidfile_create("nmbd");
 
-       if (!reinit_after_fork(nmbd_messaging_context(), false)) {
+       if (!reinit_after_fork(nmbd_messaging_context(),
+                              nmbd_event_context(), false)) {
                DEBUG(0,("reinit_after_fork() failed\n"));
                exit(1);
        }
index 5fb1d379a6322563759a33f79f263924ffe5ba95..d75d635779d05b915db495e5d5dd54aa82435fe7 100644 (file)
@@ -425,7 +425,8 @@ static bool cups_pcap_load_async(int *pfd)
        }
 
        /* Child. */
-       if (!reinit_after_fork(smbd_messaging_context(), true)) {
+       if (!reinit_after_fork(smbd_messaging_context(),
+                              smbd_event_context(), true)) {
                DEBUG(0,("cups_pcap_load_async: reinit_after_fork() failed\n"));
                smb_panic("cups_pcap_load_async: reinit_after_fork() failed");
        }
index ba88f8ee566fe5f19559bed78f9a115e083bbbee..0f38aeab8063356041337b80300096ae6cfb67d8 100644 (file)
@@ -1421,7 +1421,8 @@ void start_background_queue(void)
                close(pause_pipe[0]);
                pause_pipe[0] = -1;
 
-               if (!reinit_after_fork(smbd_messaging_context(), true)) {
+               if (!reinit_after_fork(smbd_messaging_context(),
+                                      smbd_event_context(), true)) {
                        DEBUG(0,("reinit_after_fork() failed\n"));
                        smb_panic("reinit_after_fork() failed");
                }
index 254180ae1ca2603d47ba7f55401a76990a7ea220..a84b58a05287b72f4f828ede8b6bd7b1b65f486e 100644 (file)
@@ -753,7 +753,9 @@ static bool open_sockets_smbd(bool is_daemon, bool interactive, const char *smb_
                                                                false);
 
                                if (!reinit_after_fork(
-                                           smbd_messaging_context(), true)) {
+                                           smbd_messaging_context(),
+                                           smbd_event_context(),
+                                           true)) {
                                        DEBUG(0,("reinit_after_fork() failed\n"));
                                        smb_panic("reinit_after_fork() failed");
                                }
@@ -1327,7 +1329,8 @@ extern void build_options(bool screen);
        if (is_daemon)
                pidfile_create("smbd");
 
-       if (!reinit_after_fork(smbd_messaging_context(), false)) {
+       if (!reinit_after_fork(smbd_messaging_context(),
+                              smbd_event_context(), false)) {
                DEBUG(0,("reinit_after_fork() failed\n"));
                exit(1);
        }
index e881ab412ecafac1ca22fe1f3e950efd810e2c05..b4f3c9c4dc8f6f4aa8083e51bb509e3a47414998 100644 (file)
@@ -1191,7 +1191,8 @@ int main(int argc, char **argv, char **envp)
 
        TimeInit();
 
-       if (!reinit_after_fork(winbind_messaging_context(), false)) {
+       if (!reinit_after_fork(winbind_messaging_context(),
+                              winbind_event_context(), false)) {
                DEBUG(0,("reinit_after_fork() failed\n"));
                exit(1);
        }
index 3135b6a2a3e31693ee6d785b7991b2c9b2b09f7e..14890683bc0564719e6c265560e6c495e2def5c1 100644 (file)
@@ -212,7 +212,8 @@ static bool fork_child_dc_connect(struct winbindd_domain *domain)
 
        /* Leave messages blocked - we will never process one. */
 
-       if (!reinit_after_fork(winbind_messaging_context(), true)) {
+       if (!reinit_after_fork(winbind_messaging_context(),
+                              winbind_event_context(), true)) {
                DEBUG(0,("reinit_after_fork() failed\n"));
                messaging_send_buf(winbind_messaging_context(),
                                   pid_to_procid(parent_pid),
index 4f1e92ed7c15a838e7bd8d557b300203ad8d2d22..169a80d701b00d3f3036a0ae7ac545abe9706c17 100644 (file)
@@ -1177,7 +1177,8 @@ static bool fork_domain_child(struct winbindd_child *child)
        state.sock = fdpair[0];
        close(fdpair[1]);
 
-       if (!reinit_after_fork(winbind_messaging_context(), true)) {
+       if (!reinit_after_fork(winbind_messaging_context(),
+                              winbind_event_context(), true)) {
                DEBUG(0,("reinit_after_fork() failed\n"));
                _exit(0);
        }
@@ -1219,27 +1220,34 @@ static bool fork_domain_child(struct winbindd_child *child)
        messaging_register(winbind_messaging_context(), NULL,
                           MSG_DEBUG, debug_message);
 
+       primary_domain = find_our_domain();
+
+       if (primary_domain == NULL) {
+               smb_panic("no primary domain found");
+       }
+       /* we have destroy all time event in reinit_after_fork()
+        * set check_online_event to NULL */
+       for (domain = domain_list(); domain; domain = domain->next) {
+               domain->check_online_event = NULL;
+       }
+       /* It doesn't matter if we allow cache login,
+        * try to bring domain online after fork. */
        if ( child->domain ) {
                child->domain->startup = True;
                child->domain->startup_time = time(NULL);
-       }
-
-       /* Ensure we have no pending check_online events other
-          than one for this domain or the primary domain. */
-
-       for (domain = domain_list(); domain; domain = domain->next) {
-               if (domain->primary) {
-                       primary_domain = domain;
-               }
-               if ((domain != child->domain) && !domain->primary) {
-                       TALLOC_FREE(domain->check_online_event);
+               /* we can be in primary domain or in trusted domain
+                * If we are in trusted domain, set the primary domain
+                * in start-up mode */
+               if (!(child->domain->internal)) {
+                       set_domain_online_request(child->domain);
+                       if (!(child->domain->primary)) {
+                               primary_domain->startup = True;
+                               primary_domain->startup_time = time(NULL);
+                               set_domain_online_request(primary_domain);
+                       }
                }
        }
 
-       if (primary_domain == NULL) {
-               smb_panic("no primary domain found");
-       }
-
        /* Ensure we're not handling an event inherited from
           our parent. */