]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
saner logfile code
authorAndrew Tridgell <tridge@samba.org>
Sun, 29 Apr 2007 20:42:23 +0000 (22:42 +0200)
committerAndrew Tridgell <tridge@samba.org>
Sun, 29 Apr 2007 20:42:23 +0000 (22:42 +0200)
testing of ctdbd

(This used to be ctdb commit 05789da5818f8b20f04779b0df5125914d9047f6)

ctdb/Makefile.in
ctdb/common/cmdline.c
ctdb/common/ctdb.c
ctdb/direct/ctdbd.c
ctdb/direct/ctdbd.sh
ctdb/include/ctdb.h
ctdb/include/ctdb_private.h
ctdb/tests/run_tests.sh

index 81cf72516d877cc80c1cd11e22242ab1b0c9cb8e..71c45ce6b302fd4647b920ac475e661a20528fa1 100644 (file)
@@ -7,6 +7,7 @@ datarootdir = @datarootdir@
 includedir = @includedir@
 libdir = @libdir@
 bindir = @bindir@
+localstatedir = @localstatedir@
 VPATH = @srcdir@:@tdbdir@:@tallocdir@:@libreplacedir@
 srcdir = @srcdir@
 builddir = @builddir@
@@ -14,7 +15,7 @@ EXTRA_OBJ=@EXTRA_OBJ@
 
 CFLAGS=-g -I$(srcdir)/include -Iinclude -Ilib/util -I$(srcdir) \
        -I@tallocdir@ -I@tdbdir@/include -I@libreplacedir@ \
-       -DLIBDIR=\"$(libdir)\" -DSHLIBEXT=\"@SHLIBEXT@\" -DUSE_MMAP=1 @CFLAGS@
+       -DVARDIR=\"$(localstatedir)\" -DUSE_MMAP=1 @CFLAGS@
 
 LIB_FLAGS=@LDFLAGS@ -Llib @LIBS@ -lpopt @INFINIBAND_LIBS@
 
index 988fee81e84e4be354030d1d33f978a3c945a5bc..4ffb032ed1eb24943c483fbadaf1d693a49575ae 100644 (file)
@@ -36,6 +36,7 @@ static struct {
        int self_connect;
        const char *db_dir;
        int torture;
+       const char *logfile;
 } ctdb_cmdline = {
        .nlist = NULL,
        .transport = "tcp",
@@ -43,7 +44,8 @@ static struct {
        .socketname = CTDB_PATH,
        .self_connect = 0,
        .db_dir = NULL,
-       .torture = 0
+       .torture = 0,
+       .logfile = NULL
 };
 
 
@@ -56,6 +58,7 @@ struct poptOption popt_ctdb_cmdline[] = {
        { "debug", 'd', POPT_ARG_INT, &LogLevel, 0, "debug level"},
        { "dbdir", 0, POPT_ARG_STRING, &ctdb_cmdline.db_dir, 0, "directory for the tdb files", NULL },
        { "torture", 0, POPT_ARG_NONE, &ctdb_cmdline.torture, 0, "enable nastiness in library", NULL },
+       { "logfile", 0, POPT_ARG_STRING, &ctdb_cmdline.logfile, 0, "log file location", "filename" },
        { NULL }
 };
 
@@ -80,6 +83,12 @@ struct ctdb_context *ctdb_cmdline_init(struct event_context *ev)
                exit(1);
        }
 
+       ret = ctdb_set_logfile(ctdb, ctdb_cmdline.logfile);
+       if (ret == -1) {
+               printf("ctdb_set_logfile failed - %s\n", ctdb_errstr(ctdb));
+               exit(1);
+       }
+
        if (ctdb_cmdline.self_connect) {
                ctdb_set_flags(ctdb, CTDB_FLAG_SELF_CONNECT);
        }
index 5c46cd2f65b9d522a6bee75424ee6193e6cb9b4e..f2cc65b52babcd70f1ed994ff97209c1130bbc0b 100644 (file)
@@ -35,6 +35,27 @@ int ctdb_set_transport(struct ctdb_context *ctdb, const char *transport)
        return 0;
 }
 
+/*
+  choose the logfile location
+*/
+int ctdb_set_logfile(struct ctdb_context *ctdb, const char *logfile)
+{
+       ctdb->logfile = talloc_strdup(ctdb, logfile);
+       if (ctdb->logfile != NULL) {
+               int fd;
+               close(1);
+               fd = open(ctdb->logfile, O_WRONLY|O_APPEND|O_CREAT, 0666);
+               if (fd == -1) {
+                       abort();
+               }
+               if (fd != 1) {
+                       dup2(fd, 1);
+                       close(fd);
+               }
+       }
+       return 0;
+}
+
 
 /*
   set some ctdb flags
index 8274c51531475a31ea2395be4d03270140c0de0c..c5b852ae2174577aebdcf0626cc02b82f7f1693b 100644 (file)
@@ -24,6 +24,7 @@
 #include "popt.h"
 #include "system/wait.h"
 #include "cmdline.h"
+#include "../include/ctdb_private.h"
 
 static void block_signal(int signum)
 {
@@ -83,6 +84,13 @@ int main(int argc, const char *argv[])
 
        ctdb = ctdb_cmdline_init(ev);
 
+       /* useful default logfile */
+       if (ctdb->logfile == NULL) {
+               char *name = talloc_asprintf(ctdb, "%s/log.ctdb.%u", VARDIR, ctdb->vnn);
+               ctdb_set_logfile(ctdb, name);
+               talloc_free(name);
+       }
+
        /* attach to the list of databases */
        s = talloc_strdup(ctdb, db_list);
        for (tok=strtok(s, ", "); tok; tok=strtok(NULL, ", ")) {
index 7224bdec6d66fdd0f474bc1bb47bfb33c983ac93..0d484795a38a7a6dc90e422010cabfa3dfd2ef8a 100755 (executable)
@@ -3,6 +3,28 @@
 killall -q ctdbd
 
 echo "Starting 2 ctdb daemons"
-bin/ctdbd --nlist direct/nodes.txt --listen 127.0.0.2:9001 &
-bin/ctdbd --nlist direct/nodes.txt --listen 127.0.0.1:9001 &
+bin/ctdbd --nlist direct/nodes.txt --listen 127.0.0.2:9001
+bin/ctdbd --nlist direct/nodes.txt --listen 127.0.0.1:9001
+
+echo "Testing ping"
+bin/ctdb_control ping || exit 1
+
+echo "Testing status"
+bin/ctdb_control status all || exit 1
+
+echo "Testing statusreset"
+bin/ctdb_control statusreset all || exit 1
+
+echo "Testing debug"
+bin/ctdb_control debug all 5 || exit 1
+bin/ctdb_control debuglevel || exit 1
+bin/ctdb_control debug all 0 || exit 1
+bin/ctdb_control debuglevel || exit 1
+
+echo "Testing map calls"
+bin/ctdb_control getvnnmap 0 || exit 1
+bin/ctdb_control getdbmap 0 || exit 1
+
+killall -q ctdbd
+
 
index c73f211f6b80fec3ec46aebe87a8a79fee297e56..d0af61843170aef47a8422c29bd7d4f7ed20bc21 100644 (file)
@@ -259,4 +259,6 @@ uint32_t *ctdb_get_connected_nodes(struct ctdb_context *ctdb, TALLOC_CTX *mem_ct
 
 int ctdb_status_reset(struct ctdb_context *ctdb, uint32_t destnode);
 
+int ctdb_set_logfile(struct ctdb_context *ctdb, const char *logfile);
+
 #endif
index 8bbc35c9955f31d6f5a875a4c553c4b4ddc8bc62..4850003542739282d6a17612f871c1326dbd2579 100644 (file)
@@ -176,6 +176,7 @@ struct ctdb_context {
        const char *name;
        const char *db_directory;
        const char *transport;
+       const char *logfile;
        uint32_t vnn; /* our own vnn */
        uint32_t num_nodes;
        uint32_t num_connected;
index e628bad80035b53867ea3ad2dabc491907964148..3125ce8d94756dc73eabaab36c46833d8ffd513f 100755 (executable)
@@ -3,6 +3,7 @@
 tests/fetch.sh 4 || exit 1
 tests/bench.sh 4 || exit 1
 tests/test.sh || exit 1
+direct/ctdbd.sh || exit 1
 
 echo "All OK"
 exit 0