summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAmitay Isaacs <amitay@gmail.com>2014-06-06 12:55:56 +1000
committerMartin Schwenke <martins@samba.org>2014-06-12 05:40:10 +0200
commit890bd9fb7f11b1236d493770fe635da9cfcad5f7 (patch)
tree802b74d62358f9a5ae8e2142d5279946d94d0b2b
parentdd672431c0b8a3a416f6c244b131074d868250cc (diff)
downloadsamba-890bd9fb7f11b1236d493770fe635da9cfcad5f7.tar.gz
samba-890bd9fb7f11b1236d493770fe635da9cfcad5f7.tar.xz
samba-890bd9fb7f11b1236d493770fe635da9cfcad5f7.zip
ctdb-common: Separate system utilties that are ctdb independent
Routines in system_common and system_<os> are supposed to be ctdb functions with OS specific implementations. Signed-off-by: Amitay Isaacs <amitay@gmail.com> Reviewed-by: Martin Schwenke <martin@meltin.net>
-rwxr-xr-xctdb/Makefile.in2
-rw-r--r--ctdb/common/system_common.c49
-rw-r--r--ctdb/common/system_util.c71
-rw-r--r--ctdb/tests/src/ctdb_test.c1
-rw-r--r--ctdb/tests/src/ctdbd_test.c1
5 files changed, 74 insertions, 50 deletions
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 <libgen.h>
/*
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 <http://www.gnu.org/licenses/>.
+*/
+
+#include "includes.h"
+#include "system/filesys.h"
+
+#include <libgen.h>
+
+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"