Some "ctdb ..." commands can be run without having the main daemon running.
authorRonnie Sahlberg <ronniesahlberg@gmail.com>
Tue, 8 Jun 2010 23:17:35 +0000 (09:17 +1000)
committerRonnie Sahlberg <ronniesahlberg@gmail.com>
Tue, 8 Jun 2010 23:17:35 +0000 (09:17 +1000)
In that case, when the main daemon is not running
the ctdb context will be initialized to NULL, since we can not connect.

Move the calls to read the ctdb socketname and connecting via libctdb to
only happen when we are executing a "ctdb ..." command that requires that we talk to the actual daemon.
Otherwise we will get an ugly SEGV for the "ctdb ..." commandline tool
when trying to run a command that is supposed to work also when the daemon is down.

tools/ctdb.c

index 6299b79f9626c172e94e7b142f042371cfd7e2aa..972a36716553c12d1f7c8b0e2ea8059b3945a49a 100644 (file)
@@ -4555,7 +4555,6 @@ int main(int argc, const char *argv[])
        for (i=0;i<ARRAY_SIZE(ctdb_commands);i++) {
                if (strcmp(control, ctdb_commands[i].name) == 0) {
                        int j;
-                       const char *socket_name;
 
                        if (ctdb_commands[i].without_daemon == true) {
                                close(2);
@@ -4564,21 +4563,23 @@ int main(int argc, const char *argv[])
                        /* initialise ctdb */
                        ctdb = ctdb_cmdline_client(ev);
 
-                       /* initialize a libctdb connection as well */
-                       socket_name = ctdb_get_socketname(ctdb);
-                       ctdb_connection = ctdb_connect(socket_name,
-                                                      ctdb_log_file, stderr);
-                       if (ctdb_connection == NULL) {
-                               fprintf(stderr, "Failed to connect to daemon from libctdb\n");
-                               exit(1);
-                       }                               
-                       
                        if (ctdb_commands[i].without_daemon == false) {
+                               const char *socket_name;
+
                                if (ctdb == NULL) {
                                        DEBUG(DEBUG_ERR, ("Failed to init ctdb\n"));
                                        exit(1);
                                }
 
+                               /* initialize a libctdb connection as well */
+                               socket_name = ctdb_get_socketname(ctdb);
+                               ctdb_connection = ctdb_connect(socket_name,
+                                                      ctdb_log_file, stderr);
+                               if (ctdb_connection == NULL) {
+                                       fprintf(stderr, "Failed to connect to daemon from libctdb\n");
+                                       exit(1);
+                               }                               
+                       
                                /* verify the node exists */
                                verify_node(ctdb);