[SCM] Samba Shared Repository - branch master updated

Martin Schwenke martins at samba.org
Tue Mar 1 07:57:06 UTC 2016


The branch, master has been updated
       via  27cf686 ctdb-tests: Override local daemon configuration from the environment
       via  6e259ca ctdb-tests: Change local daemon startup to use ctdbd_wrapper
       via  c8bb171 ctdb-tests: Simplify handling of public addresses for local daemons
       via  6fa25f9 ctdb-scripts: Allow configuration file to be overridden
       via  e318bab lib/util: Add strv_util.[ch] containing new function strv_split()
      from  d692020 ctdb: Fix detection of gnukfreebsd

https://git.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit 27cf686bb4ab560c0f188692da4f56962450b972
Author: Martin Schwenke <martin at meltin.net>
Date:   Fri Feb 26 20:08:11 2016 +1100

    ctdb-tests: Override local daemon configuration from the environment
    
    Anything starting with CTDB_ is appended to each node's configuration
    file.
    
    This is made slightly more difficult because the "env" command doesn't
    necessarily quote values for consumption by the shell.  The strategy
    used here is a bit fragile (assumes double-quotes, no nested quotes)
    but this is test code and only developers are expected to use this
    override.
    
    Signed-off-by: Martin Schwenke <martin at meltin.net>
    Reviewed-by: Amitay Isaacs <amitay at gmail.com>
    
    Autobuild-User(master): Martin Schwenke <martins at samba.org>
    Autobuild-Date(master): Tue Mar  1 08:56:09 CET 2016 on sn-devel-144

commit 6e259ca01f3d3aa27580e98f06b1aac82b5e6d3c
Author: Martin Schwenke <martin at meltin.net>
Date:   Fri Feb 26 19:36:25 2016 +1100

    ctdb-tests: Change local daemon startup to use ctdbd_wrapper
    
    This uses a configuration file which can be more easily overridden
    that explicit command-line options.
    
    Signed-off-by: Martin Schwenke <martin at meltin.net>
    Reviewed-by: Amitay Isaacs <amitay at gmail.com>

commit c8bb1711f566fcd9c86ec30f83b512296cc2b03c
Author: Martin Schwenke <martin at meltin.net>
Date:   Fri Feb 26 16:51:50 2016 +1100

    ctdb-tests: Simplify handling of public addresses for local daemons
    
    Signed-off-by: Martin Schwenke <martin at meltin.net>
    Reviewed-by: Amitay Isaacs <amitay at gmail.com>

commit 6fa25f9502102f8a839ea051b3769ff17997f0c9
Author: Martin Schwenke <martin at meltin.net>
Date:   Fri Feb 26 16:47:59 2016 +1100

    ctdb-scripts: Allow configuration file to be overridden
    
    For testing only (so not documented), set CTDBD_CONF.
    
    Signed-off-by: Martin Schwenke <martin at meltin.net>
    Reviewed-by: Amitay Isaacs <amitay at gmail.com>

commit e318babacef0d657699ba40a7fadb95fd6400e2e
Author: Martin Schwenke <martin at meltin.net>
Date:   Mon Feb 29 15:18:52 2016 +1100

    lib/util: Add strv_util.[ch] containing new function strv_split()
    
    strv_split() adds to a strv by splitting a string on separators.
    
    Tests included.
    
    Signed-off-by: Martin Schwenke <martin at meltin.net>
    Reviewed-by: Volker Lendecke <vl at samba.org>

-----------------------------------------------------------------------

Summary of changes:
 ctdb/config/functions                            |   2 +-
 ctdb/tests/simple/scripts/local_daemons.bash     |  50 +++++---
 source3/lib/addrchange.h => lib/util/strv_util.c |  69 +++++++----
 lib/util/{talloc_report.h => strv_util.h}        |  13 +-
 lib/util/tests/strv_util.c                       | 149 +++++++++++++++++++++++
 lib/util/wscript_build                           |   5 +-
 source4/torture/local/local.c                    |   1 +
 source4/torture/local/wscript_build              |   1 +
 8 files changed, 240 insertions(+), 50 deletions(-)
 copy source3/lib/addrchange.h => lib/util/strv_util.c (52%)
 copy lib/util/{talloc_report.h => strv_util.h} (67%)
 create mode 100644 lib/util/tests/strv_util.c


Changeset truncated at 500 lines:

diff --git a/ctdb/config/functions b/ctdb/config/functions
index eab5563..9746895 100755
--- a/ctdb/config/functions
+++ b/ctdb/config/functions
@@ -76,7 +76,7 @@ _loadconfig() {
     fi
 
     if [ "$1" = "ctdb" ] ; then
-	_config="${CTDB_BASE}/ctdbd.conf"
+	_config="${CTDBD_CONF:-${CTDB_BASE}/ctdbd.conf}"
 	if [ -r "$_config" ] ; then
 	    . "$_config"
 	fi
diff --git a/ctdb/tests/simple/scripts/local_daemons.bash b/ctdb/tests/simple/scripts/local_daemons.bash
index 92ec391..06ae3cd 100644
--- a/ctdb/tests/simple/scripts/local_daemons.bash
+++ b/ctdb/tests/simple/scripts/local_daemons.bash
@@ -9,10 +9,11 @@ done
 # Use in-tree binaries if running against local daemons.
 # Otherwise CTDB need to be installed on all nodes.
 if [ -n "$ctdb_dir" -a -d "${ctdb_dir}/bin" ] ; then
-    PATH="${ctdb_dir}/bin:${PATH}"
-    export CTDB_LOCK_HELPER="${ctdb_dir}/bin/ctdb_lock_helper"
-    export CTDB_EVENT_HELPER="${ctdb_dir}/bin/ctdb_event_helper"
-    export CTDB_RECOVERY_HELPER="${ctdb_dir}/bin/ctdb_recovery_helper"
+	# ctdbd_wrapper is in config/ directory
+	PATH="${ctdb_dir}/bin:${ctdb_dir}/config:${PATH}"
+	export CTDB_LOCK_HELPER="${ctdb_dir}/bin/ctdb_lock_helper"
+	export CTDB_EVENT_HELPER="${ctdb_dir}/bin/ctdb_event_helper"
+	export CTDB_RECOVERY_HELPER="${ctdb_dir}/bin/ctdb_recovery_helper"
 fi
 
 export CTDB_NODES="${TEST_VAR_DIR}/nodes.txt"
@@ -27,7 +28,7 @@ daemons_stop ()
     echo "Sleeping for a while..."
     sleep_for 1
 
-    local pat="ctdbd --socket=${TEST_VAR_DIR}/.* --nlist .* --nopublicipcheck"
+    local pat="ctdbd --sloppy-start --nopublicipcheck --nosetsched"
     if pgrep -f "$pat" >/dev/null ; then
 	echo "Killing remaining daemons..."
 	pkill -f "$pat"
@@ -97,27 +98,46 @@ daemons_start_1 ()
     local public_addresses_all="${TEST_VAR_DIR}/public_addresses_all"
     local public_addresses_mine="${TEST_VAR_DIR}/public_addresses.${pnn}"
     local no_public_addresses="${TEST_VAR_DIR}/no_public_addresses.txt"
+    local public_addresses
 
     local no_public_ips=-1
     [ -r $no_public_addresses ] && read no_public_ips <$no_public_addresses
 
     if  [ "$no_public_ips" = $pnn ] ; then
-	echo "Node $no_public_ips will have no public IPs."
+	    echo "Node $no_public_ips will have no public IPs."
+	    public_addresses="/dev/null"
+    else
+	    cp "$public_addresses_all" "$public_addresses_mine"
+	    public_addresses="$public_addresses_mine"
     fi
 
     local node_ip=$(sed -n -e "$(($pnn + 1))p" "$CTDB_NODES")
-    local ctdb_options="--sloppy-start --reclock=${TEST_VAR_DIR}/rec.lock --nlist $CTDB_NODES --nopublicipcheck --listen=${node_ip} --event-script-dir=${TEST_VAR_DIR}/events.d --logging=file:${TEST_VAR_DIR}/daemon.${pnn}.log -d 3 --dbdir=${TEST_VAR_DIR}/test.db --dbdir-persistent=${TEST_VAR_DIR}/test.db/persistent --dbdir-state=${TEST_VAR_DIR}/test.db/state --nosetsched"
 
-    if [ $pnn -eq $no_public_ips ] ; then
-	ctdb_options="$ctdb_options --public-addresses=/dev/null"
-    else
-	cp "$public_addresses_all" "$public_addresses_mine"
-	ctdb_options="$ctdb_options --public-addresses=$public_addresses_mine"
-    fi
+    local pidfile="${TEST_VAR_DIR}/ctdbd.${pnn}.pid"
+    local conf="${TEST_VAR_DIR}/ctdbd.${pnn}.conf"
+    cat >"$conf" <<EOF
+CTDB_RECOVERY_LOCK="${TEST_VAR_DIR}/rec.lock"
+CTDB_NODES="$CTDB_NODES"
+CTDB_NODE_ADDRESS="${node_ip}"
+CTDB_EVENT_SCRIPT_DIR="${TEST_VAR_DIR}/events.d"
+CTDB_LOGGING="file:${TEST_VAR_DIR}/daemon.${pnn}.log"
+CTDB_DEBUGLEVEL=3
+CTDB_DBDIR="${TEST_VAR_DIR}/test.db"
+CTDB_DBDIR_PERSISTENT="${TEST_VAR_DIR}/test.db/persistent"
+CTDB_DBDIR_STATE="${TEST_VAR_DIR}/test.db/state"
+CTDB_PUBLIC_ADDRESSES="${public_addresses}"
+CTDB_SOCKET="${TEST_VAR_DIR}/sock.$pnn"
+EOF
+
+    # Override from the environment.  This would be easier if env was
+    # guaranteed to quote its output so it could be reused.
+    env | grep '^CTDB_' | sed -e 's@=\([^"]\)@="\1@' -e 's@[^"]$@&"@' >>"$conf"
 
     # 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
+    # "ctdbd --sloppy-start --nopublicipcheck --nosetsched" as context.
+    CTDBD="ctdbd --sloppy-start --nopublicipcheck --nosetsched" \
+	 CTDBD_CONF="$conf" \
+	 ctdbd_wrapper "$pidfile" start
 }
 
 daemons_start ()
diff --git a/source3/lib/addrchange.h b/lib/util/strv_util.c
similarity index 52%
copy from source3/lib/addrchange.h
copy to lib/util/strv_util.c
index 1106380..5c914e5 100644
--- a/source3/lib/addrchange.h
+++ b/lib/util/strv_util.c
@@ -1,6 +1,7 @@
 /*
- * Samba Unix/Linux SMB client library
- * Copyright (C) Volker Lendecke 2011
+ * strv-based utilities
+ *
+ * Copyright Martin Schwenke <martin at meltin.net> 2016
  *
  * 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
@@ -16,30 +17,44 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#ifndef __ADDRCHANGE_H__
-#define __ADDRCHANGE_H__
-
-#include "replace.h"
-#include "system/network.h"
+#include <string.h>
 #include <talloc.h>
-#include <tevent.h>
-#include "libcli/util/ntstatus.h"
-
-struct addrchange_context;
-
-NTSTATUS addrchange_context_create(TALLOC_CTX *mem_ctx,
-				   struct addrchange_context **pctx);
 
-struct tevent_req *addrchange_send(TALLOC_CTX *mem_ctx,
-				   struct tevent_context *ev,
-				   struct addrchange_context *ctx);
-
-enum addrchange_type {
-	ADDRCHANGE_ADD,
-	ADDRCHANGE_DEL
-};
-
-NTSTATUS addrchange_recv(struct tevent_req *req, enum addrchange_type *type,
-			 struct sockaddr_storage *addr);
-
-#endif
+#include "replace.h"
+#include "strv.h"
+
+#include "strv_util.h"
+
+int strv_split(TALLOC_CTX *mem_ctx, char **strv,
+	       const char *src, const char *sep)
+{
+	const char *s;
+
+	if (src == NULL) {
+		return 0;
+	}
+
+	s = src;
+	while (*s != '\0') {
+		size_t len;
+
+		/* Skip separators */
+		len = strspn(s, sep);
+		if (len != 0) {
+			s += len;
+		}
+
+		/* Find non-separator substring */
+		len = strcspn(s, sep);
+		if (len != 0) {
+			int ret = strv_addn(mem_ctx, strv, s, len);
+			if (ret != 0) {
+				TALLOC_FREE(*strv);
+				return ret;
+			}
+			s += len;
+		}
+	}
+
+	return 0;
+}
diff --git a/lib/util/talloc_report.h b/lib/util/strv_util.h
similarity index 67%
copy from lib/util/talloc_report.h
copy to lib/util/strv_util.h
index 53d0385..9456d43 100644
--- a/lib/util/talloc_report.h
+++ b/lib/util/strv_util.h
@@ -1,7 +1,7 @@
 /*
- * talloc_report into a string
+ * strv-based utilities
  *
- * Copyright Volker Lendecke <vl at samba.org> 2015
+ * Copyright Martin Schwenke <martin at meltin.net> 2016
  *
  * 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
@@ -17,11 +17,14 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#ifndef _TALLOC_REPORT_H_
-#define _TALLOC_REPORT_H_
+#ifndef _STRV_UTIL_H_
+#define _STRV_UTIL_H_
 
 #include <talloc.h>
 
-char *talloc_report_str(TALLOC_CTX *mem_ctx, TALLOC_CTX *root);
+/* Split string at characters in sep, adding non-separator words to
+ * *strv.  On failure *strv is undefined. */
+int strv_split(TALLOC_CTX *mem_ctx, char **strv,
+	       const char *string, const char *sep);
 
 #endif
diff --git a/lib/util/tests/strv_util.c b/lib/util/tests/strv_util.c
new file mode 100644
index 0000000..3dd93d2
--- /dev/null
+++ b/lib/util/tests/strv_util.c
@@ -0,0 +1,149 @@
+/*
+ * Tests for strv_util
+ *
+ * Copyright Martin Schwenke <martin at meltin.net> 2016
+ *
+ * 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 <talloc.h>
+
+#include "replace.h"
+
+#include "libcli/util/ntstatus.h"
+#include "torture/torture.h"
+#include "lib/util/data_blob.h"
+#include "torture/local/proto.h"
+
+#include "lib/util/strv.h"
+#include "lib/util/strv_util.h"
+
+static bool test_strv_split_none(struct torture_context *tctx)
+{
+	char *strv = NULL;
+	int ret;
+
+	/* NULL has 0 entries */
+	ret = strv_split(tctx, &strv, NULL, " ");
+	torture_assert(tctx, ret == 0, "strv_split() on NULL failed");
+	torture_assert_int_equal(tctx,
+				 strv_count(strv),
+				 0,
+				 "strv_split() on NULL failed");
+	TALLOC_FREE(strv);
+
+	/* Empty string has 0 entries */
+	ret = strv_split(tctx, &strv, "", " ");
+	torture_assert(tctx, ret == 0, "strv_split() on NULL failed");
+	torture_assert_int_equal(tctx,
+				 strv_count(strv),
+				 0,
+				 "strv_split() on \"\" failed");
+	TALLOC_FREE(strv);
+
+	/* String containing only separators has 0 entries */
+	ret = strv_split(tctx, &strv, "abcabcabc", "cba ");
+	torture_assert(tctx, ret == 0, "strv_split() on NULL failed");
+	torture_assert_int_equal(tctx,
+				 strv_count(strv),
+				 0,
+				 "strv_split() on seps-only failed");
+	TALLOC_FREE(strv);
+
+	return true;
+}
+
+struct test_str_split_data {
+	const char *in;
+	const char *sep;
+	const char *out[10]; /* Hardcoded maximum! */
+};
+
+static bool test_strv_split_some(struct torture_context *tctx)
+{
+	const struct test_str_split_data data[] = {
+		{
+			/* Single string */
+			.in = "foo",
+			.sep = " \t",
+			.out = { "foo" }
+		},
+		{
+			/* Single string, single leading separator */
+			.in = " foo",
+			.sep = " \t",
+			.out = { "foo" }
+		},
+		{
+			/* Single string, single trailing separator */
+			.in = " foo",
+			.sep = " \t",
+			.out = { "foo" }
+		},
+		{
+			/* Single string, lots of separators */
+			.in = " \t foo\t ",
+			.sep = " \t",
+			.out = { "foo" }
+		},
+		{
+			/* Multiple strings, many separators */
+			.in = " \t foo   bar\t\tx\t        samba\t ",
+			.sep = " \t",
+			.out = { "foo", "bar", "x", "samba" }
+		},
+	};
+	const char *t;
+	char *strv = NULL;
+	int j;
+
+	for (j = 0; j < ARRAY_SIZE(data); j++) {
+		int i, num, ret;
+		const struct test_str_split_data *d = &data[j];
+
+		num = 0;
+		while (num < ARRAY_SIZE(d->out) && d->out[num] != NULL) {
+			num++;
+		}
+		ret = strv_split(tctx, &strv, d->in, d->sep);
+		torture_assert(tctx, ret == 0, "strv_split() on NULL failed");
+		torture_assert_int_equal(tctx,
+					 strv_count(strv),
+					 num,
+					 "strv_split() failed");
+		t = NULL;
+		for (i = 0; i < num; i++) {
+			t = strv_next(strv, t);
+			torture_assert(tctx,
+				       strcmp(t, d->out[i]) == 0,
+				       "strv_split() failed");
+		}
+		TALLOC_FREE(strv);
+	}
+	return true;
+}
+
+struct torture_suite *torture_local_util_strv_util(TALLOC_CTX *mem_ctx)
+{
+	struct torture_suite *suite =
+		torture_suite_create(mem_ctx, "strv_util");
+
+	torture_suite_add_simple_test(suite,
+				      "strv_split_none",
+				      test_strv_split_none);
+	torture_suite_add_simple_test(suite,
+				      "strv_split_some",
+				      test_strv_split_some);
+	return suite;
+}
diff --git a/lib/util/wscript_build b/lib/util/wscript_build
index 0d237be..aa0586c 100755
--- a/lib/util/wscript_build
+++ b/lib/util/wscript_build
@@ -64,9 +64,10 @@ bld.SAMBA_LIBRARY('talloc_report',
 bld.SAMBA_SUBSYSTEM('samba-util-core',
                     source='''xfile.c data_blob.c util_file.c time.c
                               signal.c util.c idtree.c fault.c
-                              substitute.c util_process.c util_strlist.c ''',
+                              substitute.c util_process.c util_strlist.c
+                              strv_util.c''',
                     deps='''time-basic samba-debug socket-blocking talloc
-                            tevent execinfo pthread''',
+                            tevent execinfo pthread strv''',
                     local_include=False)
 
 bld.SAMBA_LIBRARY('tevent-unix-util',
diff --git a/source4/torture/local/local.c b/source4/torture/local/local.c
index 1f68aac..c23df0d 100644
--- a/source4/torture/local/local.c
+++ b/source4/torture/local/local.c
@@ -42,6 +42,7 @@
 	torture_local_util_asn1,
 	torture_local_util_anonymous_shared,
 	torture_local_util_strv,
+	torture_local_util_strv_util,
 	torture_local_idtree, 
 	torture_local_dlinklist,
 	torture_local_genrand, 
diff --git a/source4/torture/local/wscript_build b/source4/torture/local/wscript_build
index ef1fb30..545544c 100644
--- a/source4/torture/local/wscript_build
+++ b/source4/torture/local/wscript_build
@@ -18,6 +18,7 @@ TORTURE_LOCAL_SOURCE = '''../../../lib/util/charset/tests/iconv.c
 	../../dsdb/schema/tests/schema_syntax.c
 	../../../lib/util/tests/anonymous_shared.c
 	../../../lib/util/tests/strv.c
+	../../../lib/util/tests/strv_util.c
 	verif_trailer.c
 	nss_tests.c
 	fsrvp_state.c'''


-- 
Samba Shared Repository



More information about the samba-cvs mailing list