ctdb-daemon: Exit with error if a database directory does not exist
[amitay/samba.git] / ctdb / server / ctdbd.c
index 7cfd30b1a8cb9a41ab000e37d6e6ab1be91835f3..7e71d6e82725c9c8b3006e6a31966a6becb870e6 100644 (file)
@@ -152,11 +152,12 @@ static struct ctdb_context *ctdb_init(struct tevent_context *ev)
 int main(int argc, const char *argv[])
 {
        struct ctdb_context *ctdb = NULL;
-       int interactive = 0;
+       int interactive_opt = 0;
+       bool interactive = false;
 
        struct poptOption popt_options[] = {
                POPT_AUTOHELP
-               { "interactive", 'i', POPT_ARG_NONE, &interactive, 0,
+               { "interactive", 'i', POPT_ARG_NONE, &interactive_opt, 0,
                  "don't fork, log to stderr", NULL },
                POPT_TABLEEND
        };
@@ -224,6 +225,8 @@ int main(int argc, const char *argv[])
                }
        }
 
+       interactive = (interactive_opt != 0);
+
        /*
         * Configuration file handling
         */
@@ -308,8 +311,28 @@ int main(int argc, const char *argv[])
         */
 
        ctdb->db_directory = ctdb_config.dbdir_volatile;
+       ok = directory_exist(ctdb->db_directory);
+       if (! ok) {
+               D_ERR("Volatile database directory %s does not exist\n",
+                     ctdb->db_directory);
+               goto fail;
+       }
+
        ctdb->db_directory_persistent = ctdb_config.dbdir_persistent;
+       ok = directory_exist(ctdb->db_directory_persistent);
+       if (! ok) {
+               D_ERR("Persistent database directory %s does not exist\n",
+                     ctdb->db_directory_persistent);
+               goto fail;
+       }
+
        ctdb->db_directory_state = ctdb_config.dbdir_state;
+       ok = directory_exist(ctdb->db_directory_state);
+       if (! ok) {
+               D_ERR("State database directory %s does not exist\n",
+                     ctdb->db_directory_state);
+               goto fail;
+       }
 
        if (ctdb_config.lock_debug_script != NULL) {
                ret = setenv("CTDB_DEBUG_LOCKS",
@@ -371,8 +394,11 @@ int main(int argc, const char *argv[])
                fast_start = true;
        }
 
+       /* Don't fork when running in test mode */
+       interactive = interactive || test_mode != NULL;
+
        /* start the protocol running (as a child) */
-       return ctdb_start_daemon(ctdb, interactive?false:true);
+       return ctdb_start_daemon(ctdb, !interactive);
 
 fail:
        talloc_free(ctdb);