ctdbd: Remove command-line option --debug-hung-script
authorMartin Schwenke <martin@meltin.net>
Tue, 5 Feb 2013 04:49:52 +0000 (15:49 +1100)
committerAmitay Isaacs <amitay@gmail.com>
Tue, 5 Feb 2013 05:05:13 +0000 (16:05 +1100)
Use an environment variable instead.  This just means that the
initscript exports CTDB_DEBUG_HUNG_SCRIPT and the code checks for the
environment variable.

The justification for this simplification is that more debug options
will be arriving soon and we want to handle them consistently without
needing to add a command-line option for each.  So, the convention
will be to use an environment variable for each debug option.

Signed-off-by: Martin Schwenke <martin@meltin.net>
config/ctdb.init
include/ctdb_private.h
server/ctdbd.c
server/eventscript.c

index 9f9b6865e7c7e081bff6bab9752ee21bafdcd7ca..7bcdd094d54c18553359b54308bcee3638345da9 100755 (executable)
@@ -95,7 +95,6 @@ build_ctdb_options () {
     maybe_set "--event-script-dir"       "$CTDB_EVENT_SCRIPT_DIR"
     maybe_set "--transport"              "$CTDB_TRANSPORT"
     maybe_set "-d"                       "$CTDB_DEBUGLEVEL"
-    maybe_set "--debug-hung-script"      "$CTDB_DEBUG_HUNG_SCRIPT"
     maybe_set "--notification-script"    "$CTDB_NOTIFY_SCRIPT"
     maybe_set "--start-as-disabled"      "$CTDB_START_AS_DISABLED"    "yes"
     maybe_set "--start-as-stopped "      "$CTDB_START_AS_STOPPED"     "yes"
@@ -108,6 +107,11 @@ build_ctdb_options () {
     maybe_set "--max-persistent-check-errors" "$CTDB_MAX_PERSISTENT_CHECK_ERRORS"
 }
 
+export_debug_variables ()
+{
+    export CTDB_DEBUG_HUNG_SCRIPT
+}
+
 # Log given message or stdin to either syslog or a CTDB log file
 do_log ()
 {
@@ -235,6 +239,8 @@ start() {
 
     build_ctdb_options
 
+    export_debug_variables
+
     # make sure we drop any ips that might still be held if previous
     # instance of ctdb got killed with -9 or similar
     drop_all_public_ips
index 26ddc34afebf7b81044563472568bfde24b4116b..cf850aa69158bd7853f4822ad931eda0fc67b197 100644 (file)
@@ -494,7 +494,6 @@ struct ctdb_context {
        bool do_setsched;
        void *saved_scheduler_param;
        const char *event_script_dir;
-       const char *debug_hung_script;
        const char *notification_script;
        const char *default_public_interface;
        pid_t ctdbd_pid;
@@ -1203,7 +1202,6 @@ int ctdb_set_single_public_ip(struct ctdb_context *ctdb,
                              const char *ip);
 int ctdb_set_event_script(struct ctdb_context *ctdb, const char *script);
 int ctdb_set_event_script_dir(struct ctdb_context *ctdb, const char *script_dir);
-int ctdb_set_debug_hung_script(struct ctdb_context *ctdb, const char *script);
 int ctdb_set_notification_script(struct ctdb_context *ctdb, const char *script);
 void lcp2_forcerebalance(struct ctdb_context *ctdb, uint32_t pnn);
 int ctdb_takeover_run(struct ctdb_context *ctdb, struct ctdb_node_map *nodemap, client_async_callback fail_callback, void *callback_data);
index ad1baac62e08ad8cd181ea70e52289c8f17cce72..512a4b7b65ed85a5e091bd50612e719c1bdcee5f 100644 (file)
@@ -33,7 +33,6 @@ static struct {
        const char *public_address_list;
        const char *event_script_dir;
        const char *notification_script;
-       const char *debug_hung_script;
        const char *logfile;
        const char *recovery_lock_file;
        const char *db_dir;
@@ -61,7 +60,6 @@ static struct {
        .db_dir_persistent = VARDIR "/ctdb/persistent",
        .db_dir_state = VARDIR "/ctdb/state",
        .script_log_level = DEBUG_ERR,
-       .debug_hung_script = ETCDIR "/ctdb/debug-hung-script.sh",
 };
 
 int script_log_level;
@@ -126,7 +124,6 @@ int main(int argc, const char *argv[])
                { "logfile", 0, POPT_ARG_STRING, &options.logfile, 0, "log file location", "filename" },
                { "nlist", 0, POPT_ARG_STRING, &options.nlist, 0, "node list file", "filename" },
                { "notification-script", 0, POPT_ARG_STRING, &options.notification_script, 0, "notification script", "filename" },
-               { "debug-hung-script", 0, POPT_ARG_STRING, &options.debug_hung_script, 0, "debug script for hung eventscripts", "filename" },
                { "listen", 0, POPT_ARG_STRING, &options.myaddress, 0, "address to listen on", "address" },
                { "transport", 0, POPT_ARG_STRING, &options.transport, 0, "protocol transport", NULL },
                { "dbdir", 0, POPT_ARG_STRING, &options.db_dir, 0, "directory for the tdb files", NULL },
@@ -310,14 +307,6 @@ int main(int argc, const char *argv[])
                }
        }
 
-       if (options.debug_hung_script != NULL) {
-               ret = ctdb_set_debug_hung_script(ctdb, options.debug_hung_script);
-       }
-       if (ret == -1) {
-               DEBUG(DEBUG_ALERT,("Unable to setup script to debug hung eventscripts\n"));
-               exit(1);
-       }
-
        ctdb->valgrinding = options.valgrinding;
        if (options.valgrinding || options.nosetsched) {
                ctdb->do_setsched = 0;
index 20f16fa156ccf89d78432633a2d170069e389558..24183a41e4c95821da9b903b830f6c45f32fcceb 100644 (file)
@@ -503,21 +503,12 @@ static void ctdb_event_script_handler(struct event_context *ev, struct fd_event
        }
 }
 
-/*
-  setup the script to debug hung eventscripts
-*/
-int ctdb_set_debug_hung_script(struct ctdb_context *ctdb, const char *script)
-{
-       ctdb->debug_hung_script = talloc_strdup(ctdb, script);
-       CTDB_NO_MEMORY(ctdb, ctdb->debug_hung_script);
-       return 0;
-}
-
 static void ctdb_run_debug_hung_script(struct ctdb_context *ctdb, struct ctdb_event_script_state *state)
 {
        struct ctdb_script_wire *current = get_current_script(state);
        char *cmd;
        pid_t pid;
+       const char * debug_hung_script = ETCDIR "/ctdb/debug-hung-script.sh";
 
        cmd = child_command_string(ctdb, state,
                                   state->from_user, current->name,
@@ -543,18 +534,22 @@ static void ctdb_run_debug_hung_script(struct ctdb_context *ctdb, struct ctdb_ev
                struct stat st;
                char buf[200];
 
-               if (stat(ctdb->debug_hung_script, &st) != 0) {
-                       DEBUG(DEBUG_ERR,("Failed to stat the script to debug hung eventscript. Is it not installed correctly? (script:%s)\n", ctdb->debug_hung_script));
+               if (getenv("CTDB_DEBUG_HUNG_SCRIPT") != NULL) {
+                       debug_hung_script = getenv("CTDB_DEBUG_HUNG_SCRIPT");
+               }
+
+               if (stat(debug_hung_script, &st) != 0) {
+                       DEBUG(DEBUG_ERR,("Failed to stat the script to debug hung eventscript. Is it not installed correctly? (script:%s)\n", debug_hung_script));
                        ctdb_kill(state->ctdb, state->child, SIGTERM);
                        _exit(0);
                }               
                if (!(st.st_mode & S_IXUSR)) {
-                       DEBUG(DEBUG_DEBUG,("Debug script %s is not executable.\n", ctdb->debug_hung_script));
+                       DEBUG(DEBUG_DEBUG,("Debug script %s is not executable.\n", debug_hung_script));
                        ctdb_kill(state->ctdb, state->child, SIGTERM);
                        _exit(0);
                }
 
-               sprintf(buf, "%s %d", ctdb->debug_hung_script, state->child);
+               sprintf(buf, "%s %d", debug_hung_script, state->child);
                system(buf);
 
                /* Now we can kill the child */