Revert "waitpid() can block if it takes a long time before the child terminates"
authorRonnie Sahlberg <ronniesahlberg@gmail.com>
Tue, 8 Jul 2008 07:41:31 +0000 (17:41 +1000)
committerRonnie Sahlberg <ronniesahlberg@gmail.com>
Tue, 8 Jul 2008 07:41:31 +0000 (17:41 +1000)
This reverts commit bfba5c7249eff8a10a43b53c1b89dd44b625fd10.

revert the waitpid changes.   we need to waitpid for some childredn so should
refactor the approach completely

server/ctdb_daemon.c
server/ctdb_freeze.c
server/ctdb_lockwait.c
server/ctdb_persistent.c
server/ctdb_recover.c
server/ctdb_recoverd.c
server/ctdb_traverse.c
server/eventscript.c

index a7f9086e27b5628f96d47116adcfa598732bfae5..326ab60e0d4e2e685e19a87fd7a0db5c55ea844d 100644 (file)
@@ -662,9 +662,6 @@ int ctdb_start_daemon(struct ctdb_context *ctdb, bool do_fork)
                }
        }
        block_signal(SIGPIPE);
-       
-       /* we dont want any SIGCHLD */
-       signal(SIGCHLD, SIG_DFL);
 
        if (ctdb->do_setsched) {
                /* try to set us up as realtime */
index e39332e3859ab9478870f6ce8a5cc3584886a000..8e75f61a1d9bc04cae4f5db8f6c2903091425ed4 100644 (file)
@@ -87,6 +87,7 @@ static int ctdb_freeze_handle_destructor(struct ctdb_freeze_handle *h)
        ctdb->freeze_handle = NULL;
 
        kill(h->child, SIGKILL);
+       waitpid(h->child, NULL, 0);
        return 0;
 }
 
index 03a7eedf46cc4fff7b38f7f6b7e48488739f1d1f..5b0019836e8f097f0ea816222eeee7ed55e74856 100644 (file)
@@ -72,6 +72,7 @@ static void lockwait_handler(struct event_context *ev, struct fd_event *fde,
        tdb_chainlock_unmark(tdb, key);
 
        kill(child, SIGKILL);
+       waitpid(child, NULL, 0);
        talloc_free(tmp_ctx);
 }
 
@@ -79,6 +80,7 @@ static int lockwait_destructor(struct lockwait_handle *h)
 {
        h->ctdb->statistics.pending_lockwait_calls--;
        kill(h->child, SIGKILL);
+       waitpid(h->child, NULL, 0);
        return 0;
 }
 
index 713950a0c9dbe4c603bcdf7452fbd603b84b9654..3ba961eadba5f4e3507a8f58de047b0969541ac1 100644 (file)
@@ -222,6 +222,7 @@ static int childwrite_destructor(struct childwrite_handle *h)
 {
        h->ctdb->statistics.pending_childwrite_calls--;
        kill(h->child, SIGKILL);
+       waitpid(h->child, NULL, 0);
        return 0;
 }
 
@@ -259,6 +260,7 @@ static void childwrite_handler(struct event_context *ev, struct fd_event *fde,
        callback(c, p);
 
        kill(child, SIGKILL);
+       waitpid(child, NULL, 0);
        talloc_free(tmp_ctx);
 }
 
index 7b8d28c58a8f4ce7022569701e2ca90d4891bada..29673eac2e49337449db48768bee3e1653435a21 100644 (file)
@@ -459,6 +459,7 @@ static void ctdb_set_recmode_timeout(struct event_context *ev, struct timed_even
 static int set_recmode_destructor(struct ctdb_set_recmode_state *state)
 {
        kill(state->child, SIGKILL);
+       waitpid(state->child, NULL, 0);
        return 0;
 }
 
index 837c0b154519fe1979b9fb7da0434cab23e54f45..80443bb75ad19efde7ca7518afc5bcc88909a9a4 100644 (file)
@@ -2933,6 +2933,11 @@ static void ctdb_check_recd(struct event_context *ev, struct timed_event *te,
 {
        struct ctdb_context *ctdb = talloc_get_type(p, struct ctdb_context);
 
+       /* make sure we harvest the child if signals are blocked for some
+          reason
+       */
+       waitpid(ctdb->recoverd_pid, 0, WNOHANG);
+
        if (kill(ctdb->recoverd_pid, 0) != 0) {
                DEBUG(DEBUG_ERR,("Recovery daemon (pid:%d) is no longer running. Shutting down main daemon\n", (int)ctdb->recoverd_pid));
 
index 10895ed59e6d91ecdb58d840821caacea4731d1f..6c84d024e625d55962643c785b66e4c7531c9b5b 100644 (file)
@@ -74,6 +74,7 @@ static void ctdb_traverse_local_handler(uint8_t *rawdata, size_t length, void *p
 static int traverse_local_destructor(struct ctdb_traverse_local_handle *h)
 {
        kill(h->child, SIGKILL);
+       waitpid(h->child, NULL, 0);
        return 0;
 }
 
index 90020071432013c36d13f8f80f6e7837ef4dd4ef..54d914b35cf3d3c8f4e8316df0f5b9bb3c1b2b84 100644 (file)
@@ -210,20 +210,18 @@ static void ctdb_event_script_handler(struct event_context *ev, struct fd_event
 {
        struct ctdb_event_script_state *state = 
                talloc_get_type(p, struct ctdb_event_script_state);
+       int status = -1;
        void (*callback)(struct ctdb_context *, int, void *) = state->callback;
        void *private_data = state->private_data;
        struct ctdb_context *ctdb = state->ctdb;
-       signed char rt = -1;
-       int ret;
 
-       ret = read(state->fd[0], &rt, sizeof(rt));
-       if (ret != sizeof(rt)) {
-               DEBUG(DEBUG_ERR, (__location__ " Failed to read from pipe to eventscript child.\n"));
+       waitpid(state->child, &status, 0);
+       if (status != -1) {
+               status = WEXITSTATUS(status);
        }
-
        talloc_set_destructor(state, NULL);
        talloc_free(state);
-       callback(ctdb, rt, private_data);
+       callback(ctdb, status, private_data);
 
        ctdb->event_script_timeouts = 0;
 }
@@ -295,6 +293,7 @@ static int event_script_destructor(struct ctdb_event_script_state *state)
 {
        DEBUG(DEBUG_ERR,(__location__ " Sending SIGTERM to child pid:%d\n", state->child));
        kill(state->child, SIGTERM);
+       waitpid(state->child, NULL, 0);
        return 0;
 }
 
@@ -337,22 +336,13 @@ static int ctdb_event_script_callback_v(struct ctdb_context *ctdb,
        }
 
        if (state->child == 0) {
-               signed char rt;
-
                close(state->fd[0]);
                if (ctdb->do_setsched) {
                        ctdb_restore_scheduler(ctdb);
                }
                set_close_on_exec(state->fd[1]);
-               rt = ctdb_event_script_v(ctdb, state->options);
-               do {
-                       ret = write(state->fd[1], &rt, sizeof(rt));
-                       if (ret != sizeof(rt)) {
-                               DEBUG(DEBUG_ERR, (__location__ " Failed to write to pipe from eventscript child. Trying again in one second\n"));
-                               sleep(1);
-                       }
-               } while (ret != sizeof(rt));
-               _exit(rt);
+               ret = ctdb_event_script_v(ctdb, state->options);
+               _exit(ret);
        }
 
        talloc_set_destructor(state, event_script_destructor);