From 890bd9fb7f11b1236d493770fe635da9cfcad5f7 Mon Sep 17 00:00:00 2001 From: Amitay Isaacs Date: Fri, 6 Jun 2014 12:55:56 +1000 Subject: ctdb-common: Separate system utilties that are ctdb independent Routines in system_common and system_ are supposed to be ctdb functions with OS specific implementations. Signed-off-by: Amitay Isaacs Reviewed-by: Martin Schwenke --- ctdb/Makefile.in | 2 +- ctdb/common/system_common.c | 49 ------------------------------- ctdb/common/system_util.c | 71 +++++++++++++++++++++++++++++++++++++++++++++ ctdb/tests/src/ctdb_test.c | 1 + ctdb/tests/src/ctdbd_test.c | 1 + 5 files changed, 74 insertions(+), 50 deletions(-) create mode 100644 ctdb/common/system_util.c diff --git a/ctdb/Makefile.in b/ctdb/Makefile.in index 0843a9653b8..7222fc4e9b9 100755 --- a/ctdb/Makefile.in +++ b/ctdb/Makefile.in @@ -88,7 +88,7 @@ UTIL_OBJ = lib/util/idtree.o lib/util/db_wrap.o lib/util/strlist.o lib/util/util CTDB_COMMON_OBJ = common/ctdb_io.o common/ctdb_util.o \ common/ctdb_ltdb.o common/ctdb_message.o common/cmdline.o \ lib/util/debug.o common/rb_tree.o @CTDB_SYSTEM_OBJ@ common/system_common.o \ - common/ctdb_logging.o common/ctdb_fork.o + common/ctdb_logging.o common/ctdb_fork.o common/system_util.o CTDB_TCP_OBJ = tcp/tcp_connect.o tcp/tcp_io.o tcp/tcp_init.o diff --git a/ctdb/common/system_common.c b/ctdb/common/system_common.c index 7fc7425b0db..01ac2bf2d7a 100644 --- a/ctdb/common/system_common.c +++ b/ctdb/common/system_common.c @@ -20,8 +20,6 @@ #include "includes.h" #include "system/network.h" -#include "system/filesys.h" -#include /* uint16 checksum for n bytes @@ -159,50 +157,3 @@ char *ctdb_sys_find_ifname(ctdb_sock_addr *addr) return NULL; } - -int mkdir_p(const char *dir, int mode) -{ - char t[PATH_MAX]; - ssize_t len; - int ret; - - if (strcmp(dir, "/") == 0) { - return 0; - } - - if (strcmp(dir, ".") == 0) { - return 0; - } - - /* Try to create directory */ - ret = mkdir(dir, mode); - /* Succeed if that worked or if it already existed */ - if (ret == 0 || errno == EEXIST) { - return 0; - } - /* Fail on anything else except ENOENT */ - if (errno != ENOENT) { - return ret; - } - - /* Create ancestors */ - len = strlen(dir); - if (len >= PATH_MAX) { - errno = ENAMETOOLONG; - return -1; - } - strncpy(t, dir, len+1); - - ret = mkdir_p(dirname(t), mode); - if (ret != 0) { - return ret; - } - - /* Create directory */ - ret = mkdir(dir, mode); - if ((ret == -1) && (errno == EEXIST)) { - ret = 0; - } - - return ret; -} diff --git a/ctdb/common/system_util.c b/ctdb/common/system_util.c new file mode 100644 index 00000000000..3aa9ebaaeef --- /dev/null +++ b/ctdb/common/system_util.c @@ -0,0 +1,71 @@ +/* + common system utilities + + Copyright (C) Amitay Isaacs 2014 + Copyright (C) Martin Schwenke 2014 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, see . +*/ + +#include "includes.h" +#include "system/filesys.h" + +#include + +int mkdir_p(const char *dir, int mode) +{ + char t[PATH_MAX]; + ssize_t len; + int ret; + + if (strcmp(dir, "/") == 0) { + return 0; + } + + if (strcmp(dir, ".") == 0) { + return 0; + } + + /* Try to create directory */ + ret = mkdir(dir, mode); + /* Succeed if that worked or if it already existed */ + if (ret == 0 || errno == EEXIST) { + return 0; + } + /* Fail on anything else except ENOENT */ + if (errno != ENOENT) { + return ret; + } + + /* Create ancestors */ + len = strlen(dir); + if (len >= PATH_MAX) { + errno = ENAMETOOLONG; + return -1; + } + strncpy(t, dir, len+1); + + ret = mkdir_p(dirname(t), mode); + if (ret != 0) { + return ret; + } + + /* Create directory */ + ret = mkdir(dir, mode); + if ((ret == -1) && (errno == EEXIST)) { + ret = 0; + } + + return ret; +} diff --git a/ctdb/tests/src/ctdb_test.c b/ctdb/tests/src/ctdb_test.c index 68a82823b2c..015c9d10ae7 100644 --- a/ctdb/tests/src/ctdb_test.c +++ b/ctdb/tests/src/ctdb_test.c @@ -102,6 +102,7 @@ struct tevent_context *tevent_context_init(TALLOC_CTX *mem_ctx); #include "common/system_common.c" #include "common/ctdb_logging.c" #include "common/ctdb_fork.c" +#include "common/system_util.c" /* CTDB_CLIENT_OBJ */ #include "client/ctdb_client.c" diff --git a/ctdb/tests/src/ctdbd_test.c b/ctdb/tests/src/ctdbd_test.c index fb29ba8f1b3..c20b1657ff6 100644 --- a/ctdb/tests/src/ctdbd_test.c +++ b/ctdb/tests/src/ctdbd_test.c @@ -53,6 +53,7 @@ bool fast_start; #include "common/system_common.c" #include "common/ctdb_logging.c" #include "common/ctdb_fork.c" +#include "common/system_util.c" /* CTDB_SERVER_OBJ */ #include "server/ctdb_daemon.c" -- cgit