common: New function mkdir_p()
authorMartin Schwenke <martin@meltin.net>
Mon, 21 Oct 2013 08:08:52 +0000 (19:08 +1100)
committerAmitay Isaacs <amitay@gmail.com>
Fri, 25 Oct 2013 01:06:06 +0000 (12:06 +1100)
Behaves like mkdir -p.

Signed-off-by: Martin Schwenke <martin@meltin.net>
Pair-programmed-with: Amitay Isaacs <amitay@gmail.com>

common/system_common.c
include/ctdb_private.h
tests/scripts/integration.bash

index 01ac2bf2d7a980c1834d009e618de160aeb43fa2..7563ff3f1bab08c40547c26e892af7d12e777c43 100644 (file)
@@ -20,6 +20,8 @@
 
 #include "includes.h"
 #include "system/network.h"
+#include "system/filesys.h"
+#include <libgen.h>
 
 /*
   uint16 checksum for n bytes
@@ -157,3 +159,29 @@ char *ctdb_sys_find_ifname(ctdb_sock_addr *addr)
 
        return NULL;
 }
+
+int mkdir_p(const char *dir, int mode)
+{
+       char * t;
+       int ret;
+
+       if (strcmp(dir, "/") == 0) {
+               return 0;
+       }
+
+       t = talloc_strdup(NULL, dir);
+       if (t == NULL) {
+               return ENOMEM;
+       }
+       ret = mkdir_p(dirname(t), mode);
+       talloc_free(t);
+
+       if (ret == 0) {
+               ret = mkdir(dir, mode);
+               if ((ret == -1) &&  (errno == EEXIST)) {
+                       ret = 0;
+               }
+       }
+
+       return ret;
+}
index f261867b3a32e25dd8a93427fb85cb99d1fb715c..bc0b8d52d83356e48b4c1eac030bf7559637bf4f 100644 (file)
@@ -1588,4 +1588,6 @@ struct lock_request *ctdb_lock_alldb(struct ctdb_context *ctdb,
                                     void (*callback)(void *, bool),
                                     void *private_data);
 
+int mkdir_p(const char *dir, int mode);
+
 #endif
index e5f1972a15c2da711044f5513f61a545c9f071fe..59f37c919eafc7dc13f8e5e83420f44f9ea3134b 100644 (file)
@@ -594,10 +594,6 @@ daemons_start_1 ()
        ctdb_options="$ctdb_options --public-addresses=$public_addresses_mine"
     fi
 
-    if [ -n "$VALGRIND" ] ; then
-       ctdb_options="$ctdb_options --valgrinding"
-    fi
-
     # We'll use "pkill -f" to kill the daemons with
     # "--socket=.* --nlist .* --nopublicipcheck" as context.
     $VALGRIND ctdbd --socket="${TEST_VAR_DIR}/sock.$pnn" $ctdb_options "$@" ||return 1