[Debian-ha-commits] [csync2] 01/05: Imported Upstream version 2.0-8-g175a01c

Valentin Vidic vvidic-guest at moszumanska.debian.org
Thu Jun 16 15:23:01 UTC 2016


This is an automated email from the git hooks/post-receive script.

vvidic-guest pushed a commit to branch master
in repository csync2.

commit 60c1f4b9338aa8c8571bfe27661ff383313a8497
Author: Valentin Vidic <Valentin.Vidic at CARNet.hr>
Date:   Wed Jun 15 20:55:59 2016 +0200

    Imported Upstream version 2.0-8-g175a01c
---
 csync2.c            |  24 ++++++++++----
 daemon.c            |   6 ++--
 debian/.prerm.swp   | Bin 12288 -> 0 bytes
 tests/include.sh    |  10 ++++++
 tests/t/0004.diff.t |  90 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 update.c            |   8 +++--
 6 files changed, 126 insertions(+), 12 deletions(-)

diff --git a/csync2.c b/csync2.c
index c0fda6a..785366a 100644
--- a/csync2.c
+++ b/csync2.c
@@ -169,6 +169,11 @@ PACKAGE_STRING " - cluster synchronization tool, 2nd generation\n"
 "		corruption if the operating system crashes or the computer\n"
 "		loses power.\n"
 "\n"
+"	-N address	When running in stand-alone mode with -ii bind to a\n"
+"		specific interface. You can pass either a hostname or ip\n"
+"		address. If used, this value must match exactly the host\n"
+"		value in each csync2.cfg file.\n"
+"\n"
 "	-I	Init-run. Use with care and read the documentation first!\n"
 "		You usually do not need this option unless you are\n"
 "		initializing groups with really large file lists.\n"
@@ -256,7 +261,7 @@ static int csync_server_bind(void)
 	struct addrinfo hints;
 	struct addrinfo *result, *rp;
 	int save_errno;
-	int sfd = -1, s, on = 1;
+	int sfd = -1, s, off = 0, on = 1;
 	memset(&hints, 0, sizeof(struct addrinfo));
 	hints.ai_family = AF_UNSPEC;	/* Allow IPv4 or IPv6 */
 	hints.ai_socktype = SOCK_STREAM;
@@ -284,7 +289,9 @@ static int csync_server_bind(void)
 			goto error;
 		if (setsockopt(sfd, IPPROTO_TCP, TCP_NODELAY, &on, (socklen_t) sizeof(on)) < 0)
 			goto error;
-
+		if (rp->ai_family == AF_INET6)
+			if (setsockopt(sfd, IPPROTO_IPV6, IPV6_V6ONLY, &off, (socklen_t) sizeof(off)) < 0)
+				goto error;
 		if (bind(sfd, rp->ai_addr, rp->ai_addrlen) == 0)
 			break;	/* Success */
 
@@ -571,7 +578,7 @@ int main(int argc, char ** argv)
 
 	/* Some inetd connect stderr to stdout.  The debug level messages on
 	 * stderr would confuse the csync2 protocol. Log to syslog instead. */
-	if ( mode == MODE_INETD && csync_debug_level && !csync_syslog )
+	if ( mode == MODE_INETD && !csync_syslog )
 		csync_openlog();
 
 	if ( *myhostname == 0 ) {
@@ -856,6 +863,7 @@ found_a_group:;
 
 		case MODE_TEST_SYNC: {
 			char *realname;
+			char *pfname;
 			if (init_run && init_run_with_removals)
 				init_run |= 2;
 			if (init_run && init_run_straight)
@@ -866,12 +874,14 @@ found_a_group:;
 				realname = getrealfn(argv[optind+2]);
 				csync_check_usefullness(realname, 0);
 
+				pfname=strdup(prefixencode(realname));
 				if ( mode_test_auto_diff ) {
 					csync_compare_mode = 1;
-					retval = csync_diff(argv[optind], argv[optind+1], realname);
+					retval = csync_diff(argv[optind], argv[optind+1], pfname);
 				} else
-					if ( csync_insynctest(argv[optind], argv[optind+1], init_run, 0, realname) )
+					if ( csync_insynctest(argv[optind], argv[optind+1], init_run, 0, pfname) )
 						retval = 2;
+				free(pfname);
 				break;
 			case 2:
 				if ( csync_insynctest(argv[optind], argv[optind+1], init_run, mode_test_auto_diff, 0) )
@@ -881,10 +891,12 @@ found_a_group:;
 				realname = getrealfn(argv[optind]);
 				csync_check_usefullness(realname, 0);
 
+				pfname=strdup(prefixencode(realname));
 				if ( mode_test_auto_diff )
 					csync_compare_mode = 1;
-				if ( csync_insynctest_all(init_run, mode_test_auto_diff, realname) )
+				if ( csync_insynctest_all(init_run, mode_test_auto_diff, pfname) )
 					retval = 2;
+				free(pfname);
 				break;
 			case 0:
 				if ( csync_insynctest_all(init_run, mode_test_auto_diff, 0) )
diff --git a/daemon.c b/daemon.c
index 553772b..90613a1 100644
--- a/daemon.c
+++ b/daemon.c
@@ -264,13 +264,13 @@ int csync_setBackupFileStatus(char *filename, int backupDirLength)
 	struct stat buf;
 	int rc = stat((filename + backupDirLength), &buf);
 	if (rc == 0) {
-		csync_debug(0, "Stating original file %s rc: %d mode: %o", (filename + backupDirLength), rc, buf.st_mode);
+		csync_debug(1, "Stating original file %s rc: %d mode: %o \n", (filename + backupDirLength), rc, buf.st_mode);
 
 		rc = chown(filename, buf.st_uid, buf.st_gid);
-		csync_debug(0, "Changing owner of %s to user %d and group %d, rc= %d \n", filename, buf.st_uid, buf.st_gid, rc);
+		csync_debug(rc == 0, "Changing owner of %s to user %d and group %d, rc= %d \n", filename, buf.st_uid, buf.st_gid, rc);
 
 		rc = chmod(filename, buf.st_mode);
-		csync_debug(0, "Changing mode of %s to mode %d, rc= %d \n", filename, buf.st_mode, rc);
+		csync_debug(rc == 0, "Changing mode of %s to mode %o, rc= %d \n", filename, buf.st_mode, rc);
 
 	} else {
 		csync_debug(0, "Error getting mode and owner ship from %s \n", (filename + backupDirLength));
diff --git a/debian/.prerm.swp b/debian/.prerm.swp
deleted file mode 100644
index d3e3376..0000000
Binary files a/debian/.prerm.swp and /dev/null differ
diff --git a/tests/include.sh b/tests/include.sh
index 9677345..5f06d8f 100644
--- a/tests/include.sh
+++ b/tests/include.sh
@@ -59,6 +59,16 @@ dbg()
 	>&44 echo "##<$lvl># $*"
 }
 
+# Sometimes (e.g. when doing "-TT"), single shot ("-iii") is not good enough.
+# But we should be able to kill that daemon without using "killall".
+# So several layers of indirection are bad,
+# the caller would not know whom to kill really.
+csync2_daemon()
+{
+	dbg 1 "CSYNC2_SYSTEM_DIR=$CSYNC2_SYSTEM_DIR csync2 -D $CSYNC2_DATABASE $*"
+	exec "$SOURCE_DIR/csync2" -D "$CSYNC2_DATABASE" "$@"
+}
+
 csync2()
 {
 	local ex
diff --git a/tests/t/0004.diff.t b/tests/t/0004.diff.t
new file mode 100644
index 0000000..481585b
--- /dev/null
+++ b/tests/t/0004.diff.t
@@ -0,0 +1,90 @@
+#!/bin/bash
+
+. $(dirname $0)/../include.sh
+
+# That prepared some "node names" ($N1 .. $N9) and corresponding
+# IPv4 addresses in /etc/hosts ($IP1 .. $IP9, 127.2.1.1 -- *.9)
+# as well as variables $D1 .. $D9 to point to the respective sub tree
+# of those "test node" instances.
+
+# Cleanup does clean the data base and the test directories.
+# You probably want to do a cleanup first thing in each test script.
+# You may even do it several times throughout such a script.
+cleanup
+
+# A "Test" needs
+#	* an expectation (exit code)
+#	* a description,
+#	* a "simple command" with optional arguments.
+# TEST is shorthand for TEST_EXPECT_EXIT_CODE 0 
+
+TEST_EXPECT_EXIT_CODE 2 "list non-existent db"	csync2 -L -N $N1
+TEST_EXPECT_EXIT_CODE 2 "list non-existent db"	csync2 -L -N $N2
+
+# You are free to do whatever you want
+# in preparation for the next test,
+# remove some files, create some files, change some content
+
+# populate $D1 
+# ------------
+
+mkdir -p $D1/a
+TEST	"init db 1"	csync2 -N $N1 -cIr $D1
+
+seq 1000 | tee $D1/a/f >/dev/null
+touch -d "last week" $D1/a/f
+TEST	"check"		csync2 -N $N1 -cr $D1
+TEST	"list dirty"	csync2 -N $N1 -M
+
+# compare and sync between both instances
+# ---------------------------------------
+TEST	"csync2 -uv"	csync2_u $N1 $N2
+TEST	"diff -rq"	diff -rq $D1 $D2
+
+# create conflicts
+# ----------------
+
+seq 1000 | tee $D1/a/f >/dev/null
+seq  999 | tee $D2/a/f >/dev/null
+TEST			"check again"	csync2 -N $N1 -cr $D1
+TEST			"list dirty"	csync2 -N $N1 -M
+
+# Verify the current diff:
+csync2_T()
+{
+	csync2 -N $1 -iii &
+	sleep 1
+	tmp=$( csync2 -N $2 -T )
+	[[ "$tmp" = "$3" ]]
+}
+
+csync2_TT()
+{
+	csync2_daemon -N $1 -ii &
+	d_pid=$!
+	sleep 1
+	tmp=$( csync2 -N $2 -TT $2 $1 $3 )
+	kill $d_pid && wait
+	[[ "$tmp" = "$4" ]]
+}
+
+TEST	"csync2 -T"	csync2_T $N1 $N2 "\
+R	2.csync2.test	1.csync2.test	%demodir%
+X	2.csync2.test	1.csync2.test	%demodir%/a/f"
+
+TEST	"csync2 -TT"	csync2_TT $N1 $N2 $D2/a/f "\
+--- 1.csync2.test:%demodir%/a/f
++++ 2.csync2.test:%demodir%/a/f
+@@ -997,4 +997,3 @@
+ 997
+ 998
+ 999
+-1000"
+
+TEST_EXPECT_EXIT_CODE 1	"csync2 -uv"	csync2_u $N1 $N2
+
+# force 1 -> 2
+# ----------------
+TEST	"force"		csync2 -N $N1 -frv $D1
+TEST	"csync2 -uv"	csync2_u $N1 $N2
+TEST	"diff -rq"	diff -rq $D1 $D2
diff --git a/update.c b/update.c
index c9547dc..99fa309 100644
--- a/update.c
+++ b/update.c
@@ -884,7 +884,7 @@ found_host_check:
 	if (!is_ok_response(read_conn_status(NULL, peername)))
 		goto finish;
 
-	conn_printf("TYPE %s %s\n", g->key, filename);
+	conn_printf("TYPE %s %s\n", url_encode(g->key), url_encode(filename));
 	if (!is_ok_response(read_conn_status(NULL, peername)))
 		goto finish;
 
@@ -899,7 +899,7 @@ found_host_check:
 	setenv("my_label",buffer,1);
 	snprintf(buffer,512,"%s:%s",peername,filename);
 	setenv("peer_label",buffer,1);
-	snprintf(buffer,512,"%s",filename);
+	snprintf(buffer,512,"%s",prefixsubst(filename));
 	setenv("diff_file",buffer,1);
 	/* XXX no error check on setenv
 	 * (could be insufficient space in environment) */
@@ -909,11 +909,13 @@ found_host_check:
 	p = popen(buffer, "w");
 
 	while ( (rc=conn_read(buffer, 512)) > 0
-		&& fwrite(buffer, rc, 1, p) == rc)
+		&& fwrite(buffer, 1, rc, p) == rc)
 		;
 
 	fclose(p);
 	signal(SIGPIPE, old_sigpipe_handler);
+	if (rc > 0)
+		fprintf(stdout, "*** output to diff truncated\n");
 
 finish:
 	conn_close();

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-ha/csync2.git



More information about the Debian-HA-Commits mailing list