From boxbackup-dev@fluffy.co.uk  Sat Dec  8 21:29:30 2007
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Sat,  8 Dec 2007 21:29:30 +0000 (UTC)
Subject: [Box Backup-commit] COMMIT r1944 - box/chris/general/lib/win32
Message-ID: <20071208212930.A2DE0325A0D@www.boxbackup.org>

Author: chris
Date: 2007-12-08 21:29:30 +0000 (Sat, 08 Dec 2007)
New Revision: 1944

Modified:
   box/chris/general/lib/win32/emu.cpp
Log:
Fix memory leak in [1942].


Modified: box/chris/general/lib/win32/emu.cpp
===================================================================
--- box/chris/general/lib/win32/emu.cpp	2007-12-08 18:34:19 UTC (rev 1943)
+++ box/chris/general/lib/win32/emu.cpp	2007-12-08 21:29:30 UTC (rev 1944)
@@ -1527,6 +1527,7 @@
 			0,                     // no data 
 			strings,               // pointer to string array 
 			NULL);                 // pointer to data 
+		delete [] pWide;
 	}
 		
 	if (result == 0)


From boxbackup-dev@fluffy.co.uk  Sat Dec  8 21:29:51 2007
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Sat,  8 Dec 2007 21:29:51 +0000 (UTC)
Subject: [Box Backup-commit] COMMIT r1945 - box/chris/general/infrastructure
Message-ID: <20071208212951.A21BB325A0D@www.boxbackup.org>

Author: chris
Date: 2007-12-08 21:29:51 +0000 (Sat, 08 Dec 2007)
New Revision: 1945

Modified:
   box/chris/general/infrastructure/buildenv-testmain-template.cpp
Log:
Reduce console verbosity in tests.


Modified: box/chris/general/infrastructure/buildenv-testmain-template.cpp
===================================================================
--- box/chris/general/infrastructure/buildenv-testmain-template.cpp	2007-12-08 21:29:30 UTC (rev 1944)
+++ box/chris/general/infrastructure/buildenv-testmain-template.cpp	2007-12-08 21:29:51 UTC (rev 1945)
@@ -109,6 +109,11 @@
 	// Start memory leak testing
 	MEMLEAKFINDER_START
 
+	Logging::SetGlobalLevel(Log::NOTICE);
+	Logging::SetProgramName("test");
+	Logging::ToConsole(true);
+	Logging::ToSyslog(false);
+
 #ifdef HAVE_GETOPT_H
 	struct option longopts[] = 
 	{


From boxbackup-dev@fluffy.co.uk  Sat Dec  8 21:30:20 2007
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Sat,  8 Dec 2007 21:30:20 +0000 (UTC)
Subject: [Box Backup-commit] COMMIT r1946 - box/chris/general/test/backupdiff
Message-ID: <20071208213020.BF44D326969@www.boxbackup.org>

Author: chris
Date: 2007-12-08 21:30:20 +0000 (Sat, 08 Dec 2007)
New Revision: 1946

Modified:
   box/chris/general/test/backupdiff/testbackupdiff.cpp
Log:
Improve debugging when failing to create the large file for diff speed
tests.


Modified: box/chris/general/test/backupdiff/testbackupdiff.cpp
===================================================================
--- box/chris/general/test/backupdiff/testbackupdiff.cpp	2007-12-08 21:29:51 UTC (rev 1945)
+++ box/chris/general/test/backupdiff/testbackupdiff.cpp	2007-12-08 21:30:20 UTC (rev 1946)
@@ -64,7 +64,7 @@
 	return true;
 }
 
-void make_file_of_zeros(const char *filename, size_t size)
+bool make_file_of_zeros(const char *filename, size_t size)
 {
 	#ifdef WIN32
 	HANDLE handle = openfile(filename, O_WRONLY | O_CREAT | O_EXCL, 0);
@@ -75,7 +75,9 @@
 	BOOL result = SetEndOfFile(handle);
 	if (result != TRUE)
 	{
-		printf("Error %u\n", GetLastError());
+		BOX_ERROR("Failed to create large file " << filename <<
+			" (" << (size >> 20) << " MB): " <<
+			GetErrorMessage(GetLastError()));
 	}
 	TEST_THAT(result == TRUE);
 	TEST_THAT(CloseHandle(handle) == TRUE);
@@ -87,7 +89,16 @@
 	TEST_THAT(close(fd) == 0);
 	#endif
 
-	TEST_THAT((size_t)TestGetFileSize(filename) == size);
+	bool correct_size = ((size_t)TestGetFileSize(filename) == size);
+	TEST_THAT(correct_size);
+	if (!correct_size)
+	{
+		BOX_ERROR("Failed to create large file " << filename <<
+			" (" << (size >> 20) << " MB): " <<
+			"got " << (TestGetFileSize(filename) >> 20) <<
+			" MB instead");
+	}
+	return correct_size;
 }
 
 
@@ -512,14 +523,21 @@
 	// found. Check this out!
 
 	#ifdef WIN32
-	::fprintf(stdout, "Testing diffing two large streams, "
-		"may take a while!\n");
-	::fflush(stdout);
+	BOX_WARNING("Testing diffing two large streams, may take a while!");
+	::fflush(stderr);
 	#endif
 
-	make_file_of_zeros("testfiles/zero.0", 20*1024*1024);
-	make_file_of_zeros("testfiles/zero.1", 200*1024*1024);
+	if (!make_file_of_zeros("testfiles/zero.0", 20*1024*1024))
+	{
+		return 1;
+	}
 
+	if (!make_file_of_zeros("testfiles/zero.1", 200*1024*1024))
+	{
+		remove("testfiles/zero.0");
+		return 1;
+	}
+
 	// Generate a first encoded file
 	{
 		BackupStoreFilenameClear f0name("zero.0");


From boxbackup-dev@fluffy.co.uk  Sat Dec  8 21:41:38 2007
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Sat,  8 Dec 2007 21:41:38 +0000 (UTC)
Subject: [Box Backup-commit] COMMIT r1947 - box/chris/general/lib/common
Message-ID: <20071208214138.B42F9325A0D@www.boxbackup.org>

Author: chris
Date: 2007-12-08 21:41:38 +0000 (Sat, 08 Dec 2007)
New Revision: 1947

Modified:
   box/chris/general/lib/common/Timer.cpp
Log:
Bite the bullet and use sigaction() instead, since [1803] shows that
signal() works badly on Solaris, and James reports that BSD doesn't
have sigset(). (merges [1900] and [1902])


Modified: box/chris/general/lib/common/Timer.cpp
===================================================================
--- box/chris/general/lib/common/Timer.cpp	2007-12-08 21:30:20 UTC (rev 1946)
+++ box/chris/general/lib/common/Timer.cpp	2007-12-08 21:41:38 UTC (rev 1947)
@@ -39,9 +39,16 @@
 		InitTimer();
 		SetTimerHandler(Timers::SignalHandler);
 	#else
-		sighandler_t oldHandler = ::signal(SIGALRM, 
-			Timers::SignalHandler);
-		ASSERT(oldHandler == 0);
+		struct sigaction newact, oldact;
+		newact.sa_handler = Timers::SignalHandler;
+		newact.sa_flags = SA_RESTART;
+		sigemptyset(&newact.sa_mask);
+		if (::sigaction(SIGALRM, &newact, &oldact) != 0)
+		{
+			BOX_ERROR("Failed to install signal handler");
+			THROW_EXCEPTION(CommonException, Internal);
+		}
+		ASSERT(oldact.sa_handler == 0);
 	#endif // WIN32 && !PLATFORM_CYGWIN
 	
 	spTimers = new std::vector<Timer*>;
@@ -70,8 +77,16 @@
 		int result = ::setitimer(ITIMER_REAL, &timeout, NULL);
 		ASSERT(result == 0);
 
-		sighandler_t oldHandler = ::signal(SIGALRM, NULL);
-		ASSERT(oldHandler == Timers::SignalHandler);
+		struct sigaction newact, oldact;
+		newact.sa_handler = SIG_DFL;
+		newact.sa_flags = SA_RESTART;
+		sigemptyset(&(newact.sa_mask));
+		if (::sigaction(SIGALRM, &newact, &oldact) != 0)
+		{
+			BOX_ERROR("Failed to remove signal handler");
+			THROW_EXCEPTION(CommonException, Internal);
+		}
+		ASSERT(oldact.sa_handler == Timers::SignalHandler);
 	#endif // WIN32 && !PLATFORM_CYGWIN
 
 	spTimers->clear();
@@ -154,10 +169,21 @@
 	}
 
 	#ifndef WIN32
-	if (::signal(SIGALRM, Timers::SignalHandler) != Timers::SignalHandler)
-	{
-		THROW_EXCEPTION(CommonException, Internal)
-	}
+		struct sigaction oldact;
+		if (::sigaction(SIGALRM, NULL, &oldact) != 0)
+		{
+			BOX_ERROR("Failed to check signal handler");
+			THROW_EXCEPTION(CommonException, Internal)
+		}
+
+		ASSERT(oldact.sa_handler == Timers::SignalHandler);
+
+		if (oldact.sa_handler != Timers::SignalHandler)
+		{
+			printf("Signal handler was %p, expected %p\n", 
+				oldact.sa_handler, Timers::SignalHandler);
+			THROW_EXCEPTION(CommonException, Internal)
+		}
 	#endif
 
 	// Clear the reschedule-needed flag to false before we start.


From boxbackup-dev@fluffy.co.uk  Sat Dec  8 21:45:06 2007
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Sat,  8 Dec 2007 21:45:06 +0000 (UTC)
Subject: [Box Backup-commit] COMMIT r1948 - box/chris/general/infrastructure
Message-ID: <20071208214506.CB70C325A0D@www.boxbackup.org>

Author: chris
Date: 2007-12-08 21:45:06 +0000 (Sat, 08 Dec 2007)
New Revision: 1948

Modified:
   box/chris/general/infrastructure/buildenv-testmain-template.cpp
Log:
Log exactly which file descriptors have been left open and what they are.
(merges [1903], [1916])


Modified: box/chris/general/infrastructure/buildenv-testmain-template.cpp
===================================================================
--- box/chris/general/infrastructure/buildenv-testmain-template.cpp	2007-12-08 21:41:38 UTC (rev 1947)
+++ box/chris/general/infrastructure/buildenv-testmain-template.cpp	2007-12-08 21:45:06 UTC (rev 1948)
@@ -64,26 +64,78 @@
 #ifdef WIN32
 
 // any way to check for open file descriptors on Win32?
-inline int  count_filedes()      { return 0;     }
-inline bool checkfilesleftopen() { return false; }
+inline bool check_filedes(bool x) { return 0;     }
+inline bool checkfilesleftopen()  { return false; }
 
 #else // !WIN32
 
-int count_filedes()
+#define FILEDES_MAX 256
+
+bool filedes_open[FILEDES_MAX];
+
+bool check_filedes(bool report)
 {
-	int c = 0;
+	bool allOk = true;
 
 	// See how many file descriptors there are with values < 256
-	for(int d = 0; d < 256; ++d)
+	for(int d = 0; d < FILEDES_MAX; ++d)
 	{
 		if(::fcntl(d, F_GETFD) != -1)
 		{
 			// File descriptor obviously exists
-			++c;
+			if (report && !filedes_open[d])
+			{
+				struct stat st;
+				if (fstat(d, &st) == 0)
+				{
+					int m = st.st_mode;
+					#define flag(x) ((m & x) ? #x " " : "")
+					BOX_FATAL("File descriptor " << d << 
+						" left open (type == " <<
+						flag(S_IFIFO) <<
+						flag(S_IFCHR) <<
+						flag(S_IFDIR) <<
+						flag(S_IFBLK) <<
+						flag(S_IFREG) <<
+						flag(S_IFLNK) <<
+						flag(S_IFSOCK) <<
+						flag(S_IFWHT) << " plus " <<							m << ")");
+				}
+				else
+				{
+					BOX_FATAL("File descriptor " << d << 
+						" left open (and stat failed)");
+				}
+	
+				allOk = false;
+				
+			}
+			else if (!report)
+			{
+				filedes_open[d] = true;
+			}
 		}
+		else 
+		{
+			if (report && filedes_open[d])
+			{
+				BOX_FATAL("File descriptor " << d << 
+					" was open, now closed");
+				allOk = false;
+			}
+			else
+			{
+				filedes_open[d] = false;
+			}
+		}
 	}
+
+	if (!report && allOk)
+	{
+		filedes_open_at_beginning = 0;
+	}
 	
-	return c;
+	return !allOk;
 }
 
 bool checkfilesleftopen()
@@ -92,6 +144,7 @@
 	{
 		// Not used correctly, pretend that there were things 
 		// left open so this gets investigated
+		BOX_FATAL("File descriptor test was not initialised");
 		return true;
 	}
 
@@ -99,7 +152,7 @@
 	::closelog();
 
 	// Count the file descriptors open
-	return filedes_open_at_beginning != count_filedes();
+	return check_filedes(true);
 }
 
 #endif
@@ -181,7 +234,7 @@
 	if(fulltestmode)
 	{
 		// Count open file descriptors for a very crude "files left open" test
-		filedes_open_at_beginning = count_filedes();
+		check_filedes(false);
 
 		// banner
 		printf("Running test TEST_NAME in " MODE_TEXT " mode...\n");


From boxbackup-dev@fluffy.co.uk  Sat Dec  8 21:46:53 2007
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Sat,  8 Dec 2007 21:46:53 +0000 (UTC)
Subject: [Box Backup-commit] COMMIT r1949 - box/chris/general
Message-ID: <20071208214653.AD122325A0D@www.boxbackup.org>

Author: chris
Date: 2007-12-08 21:46:53 +0000 (Sat, 08 Dec 2007)
New Revision: 1949

Modified:
   box/chris/general/runtest.pl.in
Log:
Log stderr output in the test log file, and don't delete it at the
end of the test. It might be useful later, and will be overwritten
automatically next run.

Keep each test's log in a separate file for later review.

(merges [1904], [1907])


Modified: box/chris/general/runtest.pl.in
===================================================================
--- box/chris/general/runtest.pl.in	2007-12-08 21:45:06 UTC (rev 1948)
+++ box/chris/general/runtest.pl.in	2007-12-08 21:46:53 UTC (rev 1949)
@@ -86,12 +86,15 @@
 		$exit_code = 2;
 		return;
 	}
+
+	my $logfile = "test-$t.log";
 	
 	# run it
-	my $test_res = system("cd $test_mode/test/$t ; ./t | tee ../../../temp.runtest");
+	my $test_res = system("cd $test_mode/test/$t ; ./t 2>&1 " .
+		"| tee ../../../$logfile");
 
 	# open test results
-	if(open RESULTS,'temp.runtest')
+	if(open RESULTS, $logfile)
 	{
 		my $last;
 		while(<RESULTS>)
@@ -101,7 +104,7 @@
 		close RESULTS;
 
 		chomp $last;
-		push @results,"$t: $last";
+		push @results, "$t: $last";
 
 		if ($last ne "PASSED") 
 		{ 
@@ -110,10 +113,11 @@
 	}
 	else
 	{
-		push @results,"$t: output not found";
+		push @results, 
+			"$t: failed to open test log file: $logfile: $!";
 	}
 	
 	# delete test results
-	unlink 'temp.runtest';
+	# unlink $logfile;
 }
 


From boxbackup-dev@fluffy.co.uk  Sat Dec  8 21:47:43 2007
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Sat,  8 Dec 2007 21:47:43 +0000 (UTC)
Subject: [Box Backup-commit] COMMIT r1950 - box/chris/general/infrastructure
Message-ID: <20071208214743.7E7B9325A0D@www.boxbackup.org>

Author: chris
Date: 2007-12-08 21:47:43 +0000 (Sat, 08 Dec 2007)
New Revision: 1950

Modified:
   box/chris/general/infrastructure/buildenv-testmain-template.cpp
Log:
Log something before checking open file descriptors, to ensure that
the notification socket is open already on MacOS X, as it will be at
the end of the test because you can't close it. (merges [1905])


Modified: box/chris/general/infrastructure/buildenv-testmain-template.cpp
===================================================================
--- box/chris/general/infrastructure/buildenv-testmain-template.cpp	2007-12-08 21:46:53 UTC (rev 1949)
+++ box/chris/general/infrastructure/buildenv-testmain-template.cpp	2007-12-08 21:47:43 UTC (rev 1950)
@@ -148,9 +148,6 @@
 		return true;
 	}
 
-	// make sure syslog log file is closed, if it was opened
-	::closelog();
-
 	// Count the file descriptors open
 	return check_filedes(true);
 }
@@ -233,12 +230,12 @@
 
 	if(fulltestmode)
 	{
+		// banner
+		BOX_NOTICE("Running test TEST_NAME in " MODE_TEXT " mode...");
+
 		// Count open file descriptors for a very crude "files left open" test
 		check_filedes(false);
 
-		// banner
-		printf("Running test TEST_NAME in " MODE_TEXT " mode...\n");
-
 		#ifdef WIN32
 			// Under win32 we must initialise the Winsock library
 			// before using sockets


From boxbackup-dev@fluffy.co.uk  Sat Dec  8 21:48:11 2007
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Sat,  8 Dec 2007 21:48:11 +0000 (UTC)
Subject: [Box Backup-commit] COMMIT r1951 - box/chris/general/infrastructure
Message-ID: <20071208214811.93107326969@www.boxbackup.org>

Author: chris
Date: 2007-12-08 21:48:11 +0000 (Sat, 08 Dec 2007)
New Revision: 1951

Modified:
   box/chris/general/infrastructure/BoxPlatform.pm.in
Log:
Remove all the extra newlines after the Fink message. (merges [1906])


Modified: box/chris/general/infrastructure/BoxPlatform.pm.in
===================================================================
--- box/chris/general/infrastructure/BoxPlatform.pm.in	2007-12-08 21:47:43 UTC (rev 1950)
+++ box/chris/general/infrastructure/BoxPlatform.pm.in	2007-12-08 21:48:11 UTC (rev 1951)
@@ -92,7 +92,7 @@
 		# test for fink installation
 		if(-d '/sw/include' && -d '/sw/lib')
 		{
-			print "Fink installation detected, will use headers and libraries\n\n\n";
+			print "Fink installation detected, will use headers and libraries\n";
 			$platform_compile_line_extra = '-I/sw/include ';
 			$platform_link_line_extra = '-L/sw/lib ';
 		}


From boxbackup-dev@fluffy.co.uk  Sat Dec  8 21:50:20 2007
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Sat,  8 Dec 2007 21:50:20 +0000 (UTC)
Subject: [Box Backup-commit] COMMIT r1952 - in box/chris/general: lib/common test/bbackupd
Message-ID: <20071208215020.2E7C3325A0D@www.boxbackup.org>

Author: chris
Date: 2007-12-08 21:50:19 +0000 (Sat, 08 Dec 2007)
New Revision: 1952

Modified:
   box/chris/general/lib/common/Test.h
   box/chris/general/test/bbackupd/testbbackupd.cpp
Log:
Move sync helper functions from test/bbackupd to Test.h to share with
other tests, particularly test/backupstorefix. (merges [1908], [1910])


Modified: box/chris/general/lib/common/Test.h
===================================================================
--- box/chris/general/lib/common/Test.h	2007-12-08 21:48:11 UTC (rev 1951)
+++ box/chris/general/lib/common/Test.h	2007-12-08 21:50:19 UTC (rev 1952)
@@ -24,6 +24,22 @@
 
 #include <string>
 
+#ifdef WIN32
+#define BBACKUPCTL      "..\\..\\bin\\bbackupctl\\bbackupctl.exe"
+#define BBACKUPD        "..\\..\\bin\\bbackupd\\bbackupd.exe"
+#define BBSTORED        "..\\..\\bin\\bbstored\\bbstored.exe"
+#define BBACKUPQUERY    "..\\..\\bin\\bbackupquery\\bbackupquery.exe"
+#define BBSTOREACCOUNTS "..\\..\\bin\\bbstoreaccounts\\bbstoreaccounts.exe"
+#define TEST_RETURN(actual, expected) TEST_THAT(actual == expected);
+#else
+#define BBACKUPCTL      "../../bin/bbackupctl/bbackupctl"
+#define BBACKUPD        "../../bin/bbackupd/bbackupd"
+#define BBSTORED        "../../bin/bbstored/bbstored"
+#define BBACKUPQUERY    "../../bin/bbackupquery/bbackupquery"
+#define BBSTOREACCOUNTS "../../bin/bbstoreaccounts/bbstoreaccounts"
+#define TEST_RETURN(actual, expected) TEST_THAT(actual == expected*256);
+#endif
+
 extern int failures;
 extern int first_fail_line;
 extern std::string first_fail_file;
@@ -353,22 +369,34 @@
 #endif
 }
 
-#ifdef WIN32
-#define BBACKUPCTL      "..\\..\\bin\\bbackupctl\\bbackupctl.exe"
-#define BBACKUPD        "..\\..\\bin\\bbackupd\\bbackupd.exe"
-#define BBSTORED        "..\\..\\bin\\bbstored\\bbstored.exe"
-#define BBACKUPQUERY    "..\\..\\bin\\bbackupquery\\bbackupquery.exe"
-#define BBSTOREACCOUNTS "..\\..\\bin\\bbstoreaccounts\\bbstoreaccounts.exe"
-#define TEST_RETURN(actual, expected) TEST_THAT(actual == expected);
-#else
-#define BBACKUPCTL      "../../bin/bbackupctl/bbackupctl"
-#define BBACKUPD        "../../bin/bbackupd/bbackupd"
-#define BBSTORED        "../../bin/bbstored/bbstored"
-#define BBACKUPQUERY    "../../bin/bbackupquery/bbackupquery"
-#define BBSTOREACCOUNTS "../../bin/bbstoreaccounts/bbstoreaccounts"
-#define TEST_RETURN(actual, expected) TEST_THAT(actual == expected*256);
-#endif
+inline void force_sync()
+{
+	TEST_THAT(::system(BBACKUPCTL " -q -c testfiles/bbackupd.conf "
+		"force-sync") == 0);
+	TestRemoteProcessMemLeaks("bbackupctl.memleaks");
+}
 
+inline void wait_for_sync_start()
+{
+	TEST_THAT(::system(BBACKUPCTL " -q -c testfiles/bbackupd.conf "
+		"wait-for-sync") == 0);
+	TestRemoteProcessMemLeaks("bbackupctl.memleaks");
+}
+
+inline void wait_for_sync_end()
+{
+	TEST_THAT(::system(BBACKUPCTL " -q -c testfiles/bbackupd.conf "
+		"wait-for-end") == 0);
+	TestRemoteProcessMemLeaks("bbackupctl.memleaks");
+}
+
+inline void sync_and_wait()
+{
+	TEST_THAT(::system(BBACKUPCTL " -q -c testfiles/bbackupd.conf "
+		"force-sync") == 0);
+	TestRemoteProcessMemLeaks("bbackupctl.memleaks");
+}
+
 inline void terminate_bbackupd(int pid)
 {
 	TEST_THAT(::system(BBACKUPCTL " -q -c testfiles/bbackupd.conf "

Modified: box/chris/general/test/bbackupd/testbbackupd.cpp
===================================================================
--- box/chris/general/test/bbackupd/testbbackupd.cpp	2007-12-08 21:48:11 UTC (rev 1951)
+++ box/chris/general/test/bbackupd/testbbackupd.cpp	2007-12-08 21:50:19 UTC (rev 1952)
@@ -544,34 +544,6 @@
 }
 #endif // !WIN32
 
-void force_sync()
-{
-	TEST_THAT(::system(BBACKUPCTL " -q -c testfiles/bbackupd.conf "
-		"force-sync") == 0);
-	TestRemoteProcessMemLeaks("bbackupctl.memleaks");
-}
-
-void wait_for_sync_start()
-{
-	TEST_THAT(::system(BBACKUPCTL " -q -c testfiles/bbackupd.conf "
-		"wait-for-sync") == 0);
-	TestRemoteProcessMemLeaks("bbackupctl.memleaks");
-}
-
-void wait_for_sync_end()
-{
-	TEST_THAT(::system(BBACKUPCTL " -q -c testfiles/bbackupd.conf "
-		"wait-for-end") == 0);
-	TestRemoteProcessMemLeaks("bbackupctl.memleaks");
-}
-
-void sync_and_wait()
-{
-	TEST_THAT(::system(BBACKUPCTL " -q -c testfiles/bbackupd.conf "
-		"force-sync") == 0);
-	TestRemoteProcessMemLeaks("bbackupctl.memleaks");
-}
-
 #ifdef WIN32
 bool set_file_time(const char* filename, FILETIME creationTime, 
 	FILETIME lastModTime, FILETIME lastAccessTime)


From boxbackup-dev@fluffy.co.uk  Sat Dec  8 21:52:00 2007
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Sat,  8 Dec 2007 21:52:00 +0000 (UTC)
Subject: [Box Backup-commit] COMMIT r1953 - box/chris/general/test/backupstorefix
Message-ID: <20071208215200.2A689325A0D@www.boxbackup.org>

Author: chris
Date: 2007-12-08 21:51:59 +0000 (Sat, 08 Dec 2007)
New Revision: 1953

Modified:
   box/chris/general/test/backupstorefix/testbackupstorefix.cpp
Log:
Explicitly wait for sync to finish instead of assuming that 14 seconds
is enough time. (merges [1909])


Modified: box/chris/general/test/backupstorefix/testbackupstorefix.cpp
===================================================================
--- box/chris/general/test/backupstorefix/testbackupstorefix.cpp	2007-12-08 21:50:19 UTC (rev 1952)
+++ box/chris/general/test/backupstorefix/testbackupstorefix.cpp	2007-12-08 21:51:59 UTC (rev 1953)
@@ -316,11 +316,11 @@
 
 		if(bbackupd_pid > 0)
 		{
-			::sleep(1);
+			::safe_sleep(1);
 			TEST_THAT(ServerIsAlive(bbackupd_pid));
 	
 			// Create a nice store directory
-			wait_for_operation(14);
+			::sync_and_wait();
 
 			// That'll do nicely, stop the server	
 			#ifdef WIN32


From boxbackup-dev@fluffy.co.uk  Sat Dec  8 21:52:46 2007
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Sat,  8 Dec 2007 21:52:46 +0000 (UTC)
Subject: [Box Backup-commit] COMMIT r1954 - box/chris/general/bin/bbackupquery
Message-ID: <20071208215246.15B29326969@www.boxbackup.org>

Author: chris
Date: 2007-12-08 21:52:45 +0000 (Sat, 08 Dec 2007)
New Revision: 1954

Modified:
   box/chris/general/bin/bbackupquery/BackupQueries.cpp
Log:
Fix compare output for missing local files which are on the store.
(merges [1911])


Modified: box/chris/general/bin/bbackupquery/BackupQueries.cpp
===================================================================
--- box/chris/general/bin/bbackupquery/BackupQueries.cpp	2007-12-08 21:51:59 UTC (rev 1953)
+++ box/chris/general/bin/bbackupquery/BackupQueries.cpp	2007-12-08 21:52:45 UTC (rev 1954)
@@ -1580,7 +1580,7 @@
 			{
 				// Not found -- report
 				BOX_WARNING("Local file '" << 
-					localDirDisplay << "' does not exist, "
+					localPathDisplay << "' does not exist, "
 					"but store file '" <<
 					storePathDisplay << "' does.");
 				rParams.mDifferences ++;


From boxbackup-dev@fluffy.co.uk  Sat Dec  8 22:00:03 2007
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Sat,  8 Dec 2007 22:00:03 +0000 (UTC)
Subject: [Box Backup-commit] COMMIT r1955 - box/chris/general/lib/server
Message-ID: <20071208220003.958FF325A0D@www.boxbackup.org>

Author: chris
Date: 2007-12-08 22:00:03 +0000 (Sat, 08 Dec 2007)
New Revision: 1955

Modified:
   box/chris/general/lib/server/ServerStream.h
Log:
Receiving a connection is not an error. (merges [1912] plus local change)


Modified: box/chris/general/lib/server/ServerStream.h
===================================================================
--- box/chris/general/lib/server/ServerStream.h	2007-12-08 21:52:45 UTC (rev 1954)
+++ box/chris/general/lib/server/ServerStream.h	2007-12-08 22:00:03 UTC (rev 1955)
@@ -227,13 +227,17 @@
 
 				if(psocket)
 				{
-					// Get the incomming connection (with zero wait time)
+					// Get the incoming connection
+					// (with zero wait time)
 					std::string logMessage;
 					std::auto_ptr<StreamType> connection(psocket->Accept(0, &logMessage));
 
 					// Was there one (there should be...)
 					if(connection.get())
 					{
+						// Log who connected
+						BOX_NOTICE(logMessage);
+
 						// Since this is a template parameter, the if() will be optimised out by the compiler
 						#ifndef WIN32 // no fork on Win32
 						if(ForkToHandleRequests && !IsSingleProcess())
@@ -270,9 +274,6 @@
 								// parent daemon process
 								break;
 							}
-							
-							// Log it
-							BOX_WARNING("Error message from child process " << pid << ": " << logMessage);
 						}
 						else
 						{


From boxbackup-dev@fluffy.co.uk  Sat Dec  8 22:00:40 2007
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Sat,  8 Dec 2007 22:00:40 +0000 (UTC)
Subject: [Box Backup-commit] COMMIT r1956 - box/chris/general/test/bbackupd
Message-ID: <20071208220040.C25B6325A0D@www.boxbackup.org>

Author: chris
Date: 2007-12-08 22:00:40 +0000 (Sat, 08 Dec 2007)
New Revision: 1956

Modified:
   box/chris/general/test/bbackupd/testbbackupd.cpp
Log:
Include the time taken by bbackupquery compare in the time between
syncs, used to check that the SyncAllowScript pauses backup for the
correct length of time. (merges [1913])


Modified: box/chris/general/test/bbackupd/testbbackupd.cpp
===================================================================
--- box/chris/general/test/bbackupd/testbbackupd.cpp	2007-12-08 22:00:03 UTC (rev 1955)
+++ box/chris/general/test/bbackupd/testbbackupd.cpp	2007-12-08 22:00:40 UTC (rev 1956)
@@ -1529,6 +1529,10 @@
 			TEST_THAT(stat("testfiles" DIRECTORY_SEPARATOR 
 				"syncallowscript.notifyran.2", &st) == 0);
 
+			// bbackupquery compare might take a while
+			// on slow machines, so start the timer now
+			long start_time = time(NULL);
+
 			// check that no backup has run (compare fails)
 			compareReturnValue = ::system(BBACKUPQUERY " -q "
 				"-c testfiles/bbackupd.conf "
@@ -1537,7 +1541,6 @@
 			TEST_RETURN(compareReturnValue, 2);
 			TestRemoteProcessMemLeaks("bbackupquery.memleaks");
 
-			long start_time = time(NULL);
 			TEST_THAT(unlink(sync_control_file) == 0);
 			wait_for_sync_start();
 			long end_time = time(NULL);


From boxbackup-dev@fluffy.co.uk  Sat Dec  8 22:01:04 2007
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Sat,  8 Dec 2007 22:01:04 +0000 (UTC)
Subject: [Box Backup-commit] COMMIT r1957 - box/chris/general/lib/backupclient
Message-ID: <20071208220104.BC909326969@www.boxbackup.org>

Author: chris
Date: 2007-12-08 22:01:04 +0000 (Sat, 08 Dec 2007)
New Revision: 1957

Modified:
   box/chris/general/lib/backupclient/BackupClientFileAttributes.cpp
Log:
Ignore time differences less than 1 second when comparing attributes,
as not all filesystems can store times that accurately (e.g. OSX).
(merges [1914])


Modified: box/chris/general/lib/backupclient/BackupClientFileAttributes.cpp
===================================================================
--- box/chris/general/lib/backupclient/BackupClientFileAttributes.cpp	2007-12-08 22:00:40 UTC (rev 1956)
+++ box/chris/general/lib/backupclient/BackupClientFileAttributes.cpp	2007-12-08 22:01:04 UTC (rev 1957)
@@ -248,7 +248,9 @@
 	
 	if(!IgnoreModTime)
 	{
-		if(a1->ModificationTime != a2->ModificationTime)
+		int t1 = a1->ModificationTime / 1000000;
+		int t2 = a2->ModificationTime / 1000000;
+		if(t1 != t2)
 		{
 			return false;
 		}
@@ -256,7 +258,9 @@
 
 	if(!IgnoreAttrModTime)
 	{
-		if(a1->AttrModificationTime != a2->AttrModificationTime)
+		int t1 = a1->AttrModificationTime / 1000000;
+		int t2 = a2->AttrModificationTime / 1000000;
+		if(t1 != t2)
 		{
 			return false;
 		}


From boxbackup-dev@fluffy.co.uk  Sat Dec  8 22:02:44 2007
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Sat,  8 Dec 2007 22:02:44 +0000 (UTC)
Subject: [Box Backup-commit] COMMIT r1958 - box/chris/general/lib/common
Message-ID: <20071208220244.49FFB325A0D@www.boxbackup.org>

Author: chris
Date: 2007-12-08 22:02:44 +0000 (Sat, 08 Dec 2007)
New Revision: 1958

Modified:
   box/chris/general/lib/common/NamedLock.cpp
Log:
Log an error if we fail to open the lockfile. (merges [1915] plus local
change).


Modified: box/chris/general/lib/common/NamedLock.cpp
===================================================================
--- box/chris/general/lib/common/NamedLock.cpp	2007-12-08 22:01:04 UTC (rev 1957)
+++ box/chris/general/lib/common/NamedLock.cpp	2007-12-08 22:02:44 UTC (rev 1958)
@@ -2,7 +2,8 @@
 //
 // File
 //		Name:    NamedLock.cpp
-//		Purpose: A global named lock, implemented as a lock file in file system
+//		Purpose: A global named lock, implemented as a lock file in
+//			 file system
 //		Created: 2003/08/28
 //
 // --------------------------------------------------------------------------
@@ -58,8 +59,9 @@
 //
 // Function
 //		Name:    NamedLock::TryAndGetLock(const char *, int)
-//		Purpose: Trys to get a lock on the name in the file system.
-//				 IMPORTANT NOTE: If a file exists with this name, it will be deleted.
+//		Purpose: Tries to get a lock on the name in the file system.
+//			 IMPORTANT NOTE: If a file exists with this name, it
+//			 will be deleted.
 //		Created: 2003/08/28
 //
 // --------------------------------------------------------------------------
@@ -93,6 +95,7 @@
 	int fd = ::open(Filename, O_WRONLY | O_CREAT | O_TRUNC, mode);
 	if(fd == -1)
 	{
+		BOX_WARNING("Failed to open lockfile: " << Filename);
 		THROW_EXCEPTION(CommonException, OSFileError)
 	}
 


From boxbackup-dev@fluffy.co.uk  Sat Dec  8 22:03:16 2007
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Sat,  8 Dec 2007 22:03:16 +0000 (UTC)
Subject: [Box Backup-commit] COMMIT r1959 - box/chris/general/lib/common
Message-ID: <20071208220316.CB0FA326969@www.boxbackup.org>

Author: chris
Date: 2007-12-08 22:03:16 +0000 (Sat, 08 Dec 2007)
New Revision: 1959

Modified:
   box/chris/general/lib/common/Test.h
Log:
Make sync_and_wait() do what it's supposed to, not just force a sync.
(merges [1917])


Modified: box/chris/general/lib/common/Test.h
===================================================================
--- box/chris/general/lib/common/Test.h	2007-12-08 22:02:44 UTC (rev 1958)
+++ box/chris/general/lib/common/Test.h	2007-12-08 22:03:16 UTC (rev 1959)
@@ -393,7 +393,7 @@
 inline void sync_and_wait()
 {
 	TEST_THAT(::system(BBACKUPCTL " -q -c testfiles/bbackupd.conf "
-		"force-sync") == 0);
+		"sync-and-wait") == 0);
 	TestRemoteProcessMemLeaks("bbackupctl.memleaks");
 }
 


From boxbackup-dev@fluffy.co.uk  Sat Dec  8 22:04:25 2007
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Sat,  8 Dec 2007 22:04:25 +0000 (UTC)
Subject: [Box Backup-commit] COMMIT r1960 - box/chris/general/test/backupstorefix
Message-ID: <20071208220425.F24ED325A0D@www.boxbackup.org>

Author: chris
Date: 2007-12-08 22:04:25 +0000 (Sat, 08 Dec 2007)
New Revision: 1960

Modified:
   box/chris/general/test/backupstorefix/testbackupstorefix.cpp
Log:
Wait for long enough after creating test files that they will actually
be seen as old enough to upload by bbackupd. (merges [1918])


Modified: box/chris/general/test/backupstorefix/testbackupstorefix.cpp
===================================================================
--- box/chris/general/test/backupstorefix/testbackupstorefix.cpp	2007-12-08 22:03:16 UTC (rev 1959)
+++ box/chris/general/test/backupstorefix/testbackupstorefix.cpp	2007-12-08 22:04:25 UTC (rev 1960)
@@ -310,19 +310,24 @@
 		TEST_THAT_ABORTONFAIL(::system(PERL_EXECUTABLE 
 			" testfiles/testbackupstorefix.pl init") == 0);
 
-		int bbackupd_pid = LaunchServer(BBACKUPD 
-			" testfiles/bbackupd.conf", "testfiles/bbackupd.pid");
+		std::string cmd = BBACKUPD + bbackupd_args +
+			" testfiles/bbackupd.conf";
+		int bbackupd_pid = LaunchServer(cmd, "testfiles/bbackupd.pid");
 		TEST_THAT(bbackupd_pid != -1 && bbackupd_pid != 0);
 
 		if(bbackupd_pid > 0)
 		{
 			::safe_sleep(1);
 			TEST_THAT(ServerIsAlive(bbackupd_pid));
+
+			// Wait 4 more seconds for the files to be old enough
+			// to upload
+			::safe_sleep(4);
 	
-			// Create a nice store directory
+			// Upload files to create a nice store directory
 			::sync_and_wait();
 
-			// That'll do nicely, stop the server	
+			// Stop bbackupd
 			#ifdef WIN32
 				terminate_bbackupd(bbackupd_pid);
 				// implicit check for memory leaks


From boxbackup-dev@fluffy.co.uk  Sat Dec  8 22:04:49 2007
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Sat,  8 Dec 2007 22:04:49 +0000 (UTC)
Subject: [Box Backup-commit] COMMIT r1961 - box/chris/general/test/backupstore
Message-ID: <20071208220449.7979F326969@www.boxbackup.org>

Author: chris
Date: 2007-12-08 22:04:49 +0000 (Sat, 08 Dec 2007)
New Revision: 1961

Modified:
   box/chris/general/test/backupstore/testbackupstore.cpp
Log:
Add some sleeps to ensure that timestamps change enough to invalidate
the directory cache in the store on filesystem with low timestamp
resolution (e.g. OSX). (merges [1922])


Modified: box/chris/general/test/backupstore/testbackupstore.cpp
===================================================================
--- box/chris/general/test/backupstore/testbackupstore.cpp	2007-12-08 22:04:25 UTC (rev 1960)
+++ box/chris/general/test/backupstore/testbackupstore.cpp	2007-12-08 22:04:49 UTC (rev 1961)
@@ -1211,6 +1211,7 @@
 			StreamableMemBlock attr(attr1, sizeof(attr1));
 			TEST_THAT(dir.GetAttributes() == attr);
 		}
+
 		// Check that we don't get attributes if we don't ask for them
 		{
 			// Command
@@ -1224,6 +1225,10 @@
 			dir.ReadFromStream(*dirstream, IOStream::TimeOutInfinite);
 			TEST_THAT(!dir.HasAttributes());
 		}
+
+		// sleep to ensure that the timestamp on the file will change
+		::safe_sleep(1);
+
 		// Change attributes on the directory
 		{
 			MemBlockStream attrnew(attr2, sizeof(attr2));
@@ -1262,6 +1267,7 @@
 				subdirid, BackupProtocolClientMoveObject::Flags_MoveAllWithSameName, newName));
 			TEST_THAT(rep->GetObjectID() == uploads[UPLOAD_FILE_TO_MOVE].allocated_objid);
 		}
+
 		// Try some dodgy renames
 		{
 			BackupStoreFilenameClear newName("moved-files");
@@ -1274,6 +1280,10 @@
 					subdirid, BackupProtocolClientMoveObject::Flags_MoveAllWithSameName, newName),
 				ConnectionException, Conn_Protocol_UnexpectedReply);
 		}
+
+		// sleep to ensure that the timestamp on the file will change
+		::safe_sleep(1);
+
 		// Rename within a directory
 		{
 			BackupStoreFilenameClear newName("moved-files-x");
@@ -1281,6 +1291,7 @@
 				subdirid,
 				subdirid, BackupProtocolClientMoveObject::Flags_MoveAllWithSameName, newName);
 		}
+
 		// Check it's all gone from the root directory...
 		{
 			// Command
@@ -1300,6 +1311,7 @@
 				TEST_THAT(en->GetName() != uploads[UPLOAD_FILE_TO_MOVE].name);
 			}
 		}
+
 		// Check the old and new versions are in the other directory
 		{
 			BackupStoreFilenameClear lookFor("moved-files-x");
@@ -1329,6 +1341,7 @@
 			TEST_THAT(foundCurrent);
 			TEST_THAT(foundOld);
 		}
+
 		// make a little bit more of a thing to look at
 		int64_t subsubdirid = 0;
 		int64_t subsubfileid = 0;
@@ -1352,6 +1365,7 @@
 				upload));
 			subsubfileid = stored->GetObjectID();
 		}
+
 		// Query names -- test that invalid stuff returns not found OK
 		{
 			std::auto_ptr<BackupProtocolClientObjectName> nameRep(protocol.QueryGetObjectName(3248972347823478927LL, subsubdirid));
@@ -1369,6 +1383,7 @@
 			std::auto_ptr<BackupProtocolClientObjectName> nameRep(protocol.QueryGetObjectName(BackupProtocolClientGetObjectName::ObjectID_DirectoryOnly, 2234342378424LL));
 			TEST_THAT(nameRep->GetNumNameElements() == 0);		
 		}
+
 		// Query names... first, get info for the file
 		{
 			std::auto_ptr<BackupProtocolClientObjectName> nameRep(protocol.QueryGetObjectName(subsubfileid, subsubdirid));
@@ -1386,6 +1401,7 @@
 				TEST_THAT(fn.GetClearFilename() == testnames[l]);
 			}
 		}
+
 		// Query names... secondly, for the directory
 		{
 			std::auto_ptr<BackupProtocolClientObjectName> nameRep(protocol.QueryGetObjectName(BackupProtocolClientGetObjectName::ObjectID_DirectoryOnly, subsubdirid));
@@ -1685,8 +1701,9 @@
 
 	// First, try logging in without an account having been created... just make sure login fails.
 
-	int pid = LaunchServer(BBSTORED " testfiles/bbstored.conf",
-		"testfiles/bbstored.pid");
+	std::string cmd = BBSTORED " " + bbstored_args + 
+		" testfiles/bbstored.conf";
+	int pid = LaunchServer(cmd.c_str(), "testfiles/bbstored.pid");
 
 	TEST_THAT(pid != -1 && pid != 0);
 	if(pid > 0)


From boxbackup-dev@fluffy.co.uk  Sat Dec  8 22:07:35 2007
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Sat,  8 Dec 2007 22:07:35 +0000 (UTC)
Subject: [Box Backup-commit] COMMIT r1962 - box/chris/general/lib/common
Message-ID: <20071208220735.D37BB325A0D@www.boxbackup.org>

Author: chris
Date: 2007-12-08 22:07:35 +0000 (Sat, 08 Dec 2007)
New Revision: 1962

Modified:
   box/chris/general/lib/common/Utils.cpp
   box/chris/general/lib/common/Utils.h
Log:
Allow ObjectExists() to take a std::string instead of just char *.
(merges [1920])


Modified: box/chris/general/lib/common/Utils.cpp
===================================================================
--- box/chris/general/lib/common/Utils.cpp	2007-12-08 22:04:49 UTC (rev 1961)
+++ box/chris/general/lib/common/Utils.cpp	2007-12-08 22:07:35 UTC (rev 1962)
@@ -135,15 +135,15 @@
 // --------------------------------------------------------------------------
 //
 // Function
-//		Name:    ObjectExists(const char *)
+//		Name:    ObjectExists(const std::string& rFilename)
 //		Purpose: Does a object exist, and if so, is it a file or a directory?
 //		Created: 23/11/03
 //
 // --------------------------------------------------------------------------
-int ObjectExists(const char *Filename)
+int ObjectExists(const std::string& rFilename)
 {
 	struct stat st;
-	if(::stat(Filename, &st) != 0)
+	if(::stat(rFilename.c_str(), &st) != 0)
 	{
 		if(errno == ENOENT)
 		{

Modified: box/chris/general/lib/common/Utils.h
===================================================================
--- box/chris/general/lib/common/Utils.h	2007-12-08 22:04:49 UTC (rev 1961)
+++ box/chris/general/lib/common/Utils.h	2007-12-08 22:07:35 UTC (rev 1962)
@@ -29,7 +29,7 @@
 	ObjectExists_File = 1,
 	ObjectExists_Dir = 2
 };
-int ObjectExists(const char *Filename);
+int ObjectExists(const std::string& rFilename);
 
 #include "MemLeakFindOff.h"
 


From boxbackup-dev@fluffy.co.uk  Sat Dec  8 22:08:55 2007
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Sat,  8 Dec 2007 22:08:55 +0000 (UTC)
Subject: [Box Backup-commit] COMMIT r1963 - box/chris/general/lib/backupclient
Message-ID: <20071208220855.DD90B325A0D@www.boxbackup.org>

Author: chris
Date: 2007-12-08 22:08:55 +0000 (Sat, 08 Dec 2007)
New Revision: 1963

Modified:
   box/chris/general/lib/backupclient/BackupClientRestore.cpp
Log:
Fix restoring over existing files (merges [1919], [1921])


Modified: box/chris/general/lib/backupclient/BackupClientRestore.cpp
===================================================================
--- box/chris/general/lib/backupclient/BackupClientRestore.cpp	2007-12-08 22:07:35 UTC (rev 1962)
+++ box/chris/general/lib/backupclient/BackupClientRestore.cpp	2007-12-08 22:08:55 UTC (rev 1963)
@@ -453,8 +453,11 @@
 				BackupStoreFilenameClear nm(en->GetName());
 				std::string localFilename(rLocalDirectoryName + DIRECTORY_SEPARATOR_ASCHAR + nm.GetClearFilename());
 				
-				// Unlink anything which already exists -- for resuming restores, we can't overwrite files already there.
-				if(::unlink(localFilename.c_str()) == 0)
+				// Unlink anything which already exists:
+				// For resuming restores, we can't overwrite
+				// files already there.
+				if(ObjectExists(localFilename) != ObjectExists_NoObject &&
+					::unlink(localFilename.c_str()) != 0)
 				{
 					BOX_ERROR("Failed to delete file '" <<
 						localFilename << "': " <<


From boxbackup-dev@fluffy.co.uk  Sat Dec  8 22:26:11 2007
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Sat,  8 Dec 2007 22:26:11 +0000 (UTC)
Subject: [Box Backup-commit] COMMIT r1964 - in box/chris/general: infrastructure lib/common test/backupstorefix test/bbackupd
Message-ID: <20071208222611.022A7325A0D@www.boxbackup.org>

Author: chris
Date: 2007-12-08 22:26:10 +0000 (Sat, 08 Dec 2007)
New Revision: 1964

Modified:
   box/chris/general/infrastructure/buildenv-testmain-template.cpp
   box/chris/general/lib/common/Utils.cpp
   box/chris/general/test/backupstorefix/testbackupstorefix.cpp
   box/chris/general/test/bbackupd/testbbackupd.cpp
Log:
Use lstat() instead of stat() to check whether a file exists. Thanks to
Hans-Joachim Baader for reporting this problem.
(http://lists.warhead.org.uk/pipermail/boxbackup/2007-November/003958.html)

Add a test that symlinks are not followed during restore.

Improve handling of bbackup_args by not including a redundant space
at the start of the string.

(merges [1923] [1927] [1931] [1932])


Modified: box/chris/general/infrastructure/buildenv-testmain-template.cpp
===================================================================
--- box/chris/general/infrastructure/buildenv-testmain-template.cpp	2007-12-08 22:08:55 UTC (rev 1963)
+++ box/chris/general/infrastructure/buildenv-testmain-template.cpp	2007-12-08 22:26:10 UTC (rev 1964)
@@ -181,7 +181,10 @@
 		{
 			case 'c':
 			{
-				bbackupd_args += " ";
+				if (bbackupd_args.length() > 0)
+				{
+					bbackupd_args += " ";
+				}
 				bbackupd_args += optarg;
 			}
 			break;

Modified: box/chris/general/lib/common/Utils.cpp
===================================================================
--- box/chris/general/lib/common/Utils.cpp	2007-12-08 22:08:55 UTC (rev 1963)
+++ box/chris/general/lib/common/Utils.cpp	2007-12-08 22:26:10 UTC (rev 1964)
@@ -98,7 +98,7 @@
 bool FileExists(const char *Filename, int64_t *pFileSize, bool TreatLinksAsNotExisting)
 {
 	struct stat st;
-	if(::stat(Filename, &st) != 0)
+	if(::lstat(Filename, &st) != 0)
 	{
 		if(errno == ENOENT)
 		{

Modified: box/chris/general/test/backupstorefix/testbackupstorefix.cpp
===================================================================
--- box/chris/general/test/backupstorefix/testbackupstorefix.cpp	2007-12-08 22:08:55 UTC (rev 1963)
+++ box/chris/general/test/backupstorefix/testbackupstorefix.cpp	2007-12-08 22:26:10 UTC (rev 1964)
@@ -310,7 +310,7 @@
 		TEST_THAT_ABORTONFAIL(::system(PERL_EXECUTABLE 
 			" testfiles/testbackupstorefix.pl init") == 0);
 
-		std::string cmd = BBACKUPD + bbackupd_args +
+		std::string cmd = BBACKUPD + " " + bbackupd_args +
 			" testfiles/bbackupd.conf";
 		int bbackupd_pid = LaunchServer(cmd, "testfiles/bbackupd.pid");
 		TEST_THAT(bbackupd_pid != -1 && bbackupd_pid != 0);

Modified: box/chris/general/test/bbackupd/testbbackupd.cpp
===================================================================
--- box/chris/general/test/bbackupd/testbbackupd.cpp	2007-12-08 22:08:55 UTC (rev 1963)
+++ box/chris/general/test/bbackupd/testbbackupd.cpp	2007-12-08 22:26:10 UTC (rev 1964)
@@ -1022,11 +1022,11 @@
 	}
 #endif // PLATFORM_CLIB_FNS_INTERCEPTION_IMPOSSIBLE
 
-	std::string cmd = BBACKUPD + bbackupd_args + " testfiles/bbackupd.conf";
+	std::string cmd = BBACKUPD " " + bbackupd_args + 
+		" testfiles/bbackupd-temploc.conf";
+
 	bbackupd_pid = LaunchServer(cmd, "testfiles/bbackupd.pid");
-
 	TEST_THAT(bbackupd_pid != -1 && bbackupd_pid != 0);
-
 	::safe_sleep(1);
 
 	TEST_THAT(ServerIsAlive(bbackupd_pid));
@@ -1034,6 +1034,163 @@
 	if (!ServerIsAlive(bbackupd_pid)) return 1;
 	if (!ServerIsAlive(bbstored_pid)) return 1;
 
+	#ifndef WIN32
+	printf("\n==== Testing that absolute symlinks are not followed "
+		"during restore\n");
+
+	{
+		#define SYM_DIR "testfiles" DIRECTORY_SEPARATOR "TestDir1" \
+			DIRECTORY_SEPARATOR "symlink_test"
+
+		TEST_THAT(::mkdir(SYM_DIR, 0777) == 0);
+		TEST_THAT(::mkdir(SYM_DIR DIRECTORY_SEPARATOR "a", 0777) == 0);
+		TEST_THAT(::mkdir(SYM_DIR DIRECTORY_SEPARATOR "a"
+			DIRECTORY_SEPARATOR "subdir", 0777) == 0);
+		TEST_THAT(::mkdir(SYM_DIR DIRECTORY_SEPARATOR "b", 0777) == 0);
+
+		FILE* fp = fopen(SYM_DIR DIRECTORY_SEPARATOR "a"
+			DIRECTORY_SEPARATOR "subdir"
+			DIRECTORY_SEPARATOR "content", "w");
+		TEST_THAT(fp != NULL);
+		fputs("before\n", fp);
+		fclose(fp);
+
+		char buf[PATH_MAX];
+		TEST_THAT(getcwd(buf, sizeof(buf)) != NULL);
+		std::string path = buf;
+		path += DIRECTORY_SEPARATOR SYM_DIR 
+			DIRECTORY_SEPARATOR "a"
+			DIRECTORY_SEPARATOR "subdir";
+		TEST_THAT(symlink(path.c_str(), SYM_DIR 
+			DIRECTORY_SEPARATOR "b"
+			DIRECTORY_SEPARATOR "link") == 0);
+
+		::wait_for_operation(4);
+		::sync_and_wait();
+
+		// Check that the backup was successful, i.e. no differences
+		int compareReturnValue = ::system(BBACKUPQUERY " -q "
+			"-c testfiles/bbackupd.conf "
+			"-l testfiles/query1.log "
+			"\"compare -acQ\" quit");
+		TEST_RETURN(compareReturnValue, 1);
+		TestRemoteProcessMemLeaks("bbackupquery.memleaks");
+
+		// now stop bbackupd and update the test file,
+		// make the original directory unreadable
+		terminate_bbackupd(bbackupd_pid);
+
+		fp = fopen(SYM_DIR DIRECTORY_SEPARATOR "a"
+			DIRECTORY_SEPARATOR "subdir"
+			DIRECTORY_SEPARATOR "content", "w");
+		TEST_THAT(fp != NULL);
+		fputs("after\n", fp);
+		fclose(fp);
+
+		TEST_THAT(chmod(SYM_DIR, 0) == 0);
+
+		// check that we can restore it
+		compareReturnValue = ::system(BBACKUPQUERY " "
+			"-c testfiles/bbackupd.conf "
+			"-q \"restore Test1 testfiles/restore-symlink\" "
+			"quit");
+		TEST_RETURN(compareReturnValue, 0);
+
+		// make it accessible again
+		TEST_THAT(chmod(SYM_DIR, 0755) == 0);
+
+		// check that the original file was not overwritten
+		FileStream fs(SYM_DIR "/a/subdir/content");
+		IOStreamGetLine gl(fs);
+		std::string line;
+		TEST_THAT(gl.GetLine(line));
+		TEST_THAT(line != "before");
+		TEST_THAT(line == "after");
+
+		#undef SYM_DIR
+
+		bbackupd_pid = LaunchServer(cmd, "testfiles/bbackupd.pid");
+		TEST_THAT(bbackupd_pid != -1 && bbackupd_pid != 0);
+		::safe_sleep(1);
+
+		TEST_THAT(ServerIsAlive(bbackupd_pid));
+		TEST_THAT(ServerIsAlive(bbstored_pid));
+		if (!ServerIsAlive(bbackupd_pid)) return 1;
+		if (!ServerIsAlive(bbstored_pid)) return 1;
+	}
+	#endif // ! WIN32
+
+	printf("\n==== Testing that redundant locations are deleted on time\n");
+
+	{
+		std::auto_ptr<BackupProtocolClient> client = Connect(
+			context,
+			BackupProtocolClientLogin::Flags_ReadOnly);
+		
+		std::auto_ptr<BackupStoreDirectory> dir = ReadDirectory(
+			*client,
+			BackupProtocolClientListDirectory::RootDirectory);
+
+		// int64_t testDirId = SearchDir(*dir, "Test2");
+		// TEST_THAT(testDirId == 0);
+
+		sync_and_wait();
+
+		dir = ReadDirectory(*client,
+			BackupProtocolClientListDirectory::RootDirectory);
+		int64_t testDirId = SearchDir(*dir, "Test2");
+		TEST_THAT(testDirId != 0);
+
+		// Kill the daemon
+		terminate_bbackupd(bbackupd_pid);
+
+		cmd = BBACKUPD " " + bbackupd_args +
+			" testfiles/bbackupd.conf";
+		bbackupd_pid = LaunchServer(cmd, "testfiles/bbackupd.pid");
+
+		TEST_THAT(bbackupd_pid != -1 && bbackupd_pid != 0);
+
+		::safe_sleep(1);
+
+		TEST_THAT(ServerIsAlive(bbackupd_pid));
+		TEST_THAT(ServerIsAlive(bbstored_pid));
+		if (!ServerIsAlive(bbackupd_pid)) return 1;
+		if (!ServerIsAlive(bbstored_pid)) return 1;
+
+		// Test2 should be deleted after 10 seconds (4 runs)
+		wait_for_sync_end();
+		wait_for_sync_end();
+		wait_for_sync_end();
+
+		dir = ReadDirectory(*client,
+			BackupProtocolClientListDirectory::RootDirectory);
+		testDirId = SearchDir(*dir, "Test2");
+		TEST_THAT(testDirId != 0);
+
+		wait_for_sync_end();
+		
+		dir = ReadDirectory(*client,
+			BackupProtocolClientListDirectory::RootDirectory);
+		testDirId = SearchDir(*dir, "Test2");
+		TEST_THAT(testDirId != 0);
+
+		BackupStoreDirectory::Iterator i(*dir);
+		BackupStoreFilenameClear dirname("Test2");
+		BackupStoreDirectory::Entry *en = i.FindMatchingClearName(dirname);
+		TEST_THAT(en != 0);
+		int16_t en_flags = en->GetFlags();
+		TEST_THAT(en_flags && BackupStoreDirectory::Entry::Flags_Deleted);
+
+		// Log out.
+		client->QueryFinished();
+		sSocket.Close();
+	}
+
+	TEST_THAT(ServerIsAlive(bbackupd_pid));
+	TEST_THAT(ServerIsAlive(bbstored_pid));
+	if (!ServerIsAlive(bbackupd_pid)) return 1;
+	if (!ServerIsAlive(bbstored_pid)) return 1;
+
 	if(bbackupd_pid > 0)
 	{
 		printf("\n==== Testing that backup pauses when store is full\n");
@@ -2791,7 +2948,8 @@
 		terminate_bbackupd(bbackupd_pid);
 		
 		// Start it again
-		cmd = BBACKUPD + bbackupd_args + " testfiles/bbackupd.conf";
+		cmd = BBACKUPD " " + bbackupd_args +
+			" testfiles/bbackupd.conf";
 		bbackupd_pid = LaunchServer(cmd, "testfiles/bbackupd.pid");
 
 		TEST_THAT(bbackupd_pid != -1 && bbackupd_pid != 0);


From boxbackup-dev@fluffy.co.uk  Sat Dec  8 22:34:42 2007
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Sat,  8 Dec 2007 22:34:42 +0000 (UTC)
Subject: [Box Backup-commit] COMMIT r1965 - box/chris/general/test/bbackupd
Message-ID: <20071208223442.84745325A0D@www.boxbackup.org>

Author: chris
Date: 2007-12-08 22:34:42 +0000 (Sat, 08 Dec 2007)
New Revision: 1965

Modified:
   box/chris/general/test/bbackupd/testbbackupd.cpp
Log:
Fix keepalive test failure:

* zero memory buffer before use to keep consistent behaviour.

* expect a diff even if the maximum diffing time expires

* really check when we have a diff and when we don't

Thanks to Matt Brown and Guno Heitman for reporting this.

(merges [1924] [1925] [1941])


Modified: box/chris/general/test/bbackupd/testbbackupd.cpp
===================================================================
--- box/chris/general/test/bbackupd/testbbackupd.cpp	2007-12-08 22:26:10 UTC (rev 1964)
+++ box/chris/general/test/bbackupd/testbbackupd.cpp	2007-12-08 22:34:42 UTC (rev 1965)
@@ -79,6 +79,27 @@
 // two cycles and a bit
 #define TIME_TO_WAIT_FOR_BACKUP_OPERATION	12
 
+// utility macro for comparing two strings in a line
+#define TEST_EQUAL(expected, found, line) \
+{ \
+	std::string exp_str = expected; \
+	std::string found_str = found; \
+	TEST_THAT(exp_str == found_str); \
+	if(exp_str != found_str) \
+	{ \
+		printf("Expected <%s> but found <%s> in <%s>\n", \
+			exp_str.c_str(), found_str.c_str(), line.c_str()); \
+	} \
+}
+
+// utility macro for testing a line
+#define TEST_LINE(condition, line) \
+	TEST_THAT(condition); \
+	if (!(condition)) \
+	{ \
+		printf("Test failed on <%s>\n", line.c_str()); \
+	}
+
 void wait_for_backup_operation(int seconds = TIME_TO_WAIT_FOR_BACKUP_OPERATION)
 {
 	wait_for_operation(seconds);
@@ -762,7 +783,10 @@
 		// something to diff against (empty file doesn't work)
 		int fd = open("testfiles/TestDir1/spacetest/f1", O_WRONLY);
 		TEST_THAT(fd > 0);
+
 		char buffer[10000];
+		memset(buffer, 0, sizeof(buffer));
+
 		TEST_THAT(write(fd, buffer, sizeof(buffer)) == sizeof(buffer));
 		TEST_THAT(close(fd) == 0);
 		
@@ -770,6 +794,9 @@
 		wait_for_backup_operation();
 		stop_internal_daemon(pid);
 
+		// two-second delay on the first read() of f1
+		// should mean that a single keepalive is sent,
+		// and diff does not abort.
 		intercept_setup_delay("testfiles/TestDir1/spacetest/f1", 
 			0, 2000, SYS_read, 1);
 		TEST_THAT(unlink("testfiles/bbackupd.log") == 0);
@@ -811,22 +838,30 @@
 			std::string line;
 			TEST_THAT(reader.GetLine(line));
 			std::string comp = "Receive Success(0x";
-			TEST_THAT(line.substr(0, comp.size()) == comp);
+			TEST_EQUAL(comp, line.substr(0, comp.size()), line);
 			TEST_THAT(reader.GetLine(line));
-			TEST_THAT(line == "Receiving stream, size 124");
+			TEST_EQUAL("Receiving stream, size 124", line, line);
 			TEST_THAT(reader.GetLine(line));
-			TEST_THAT(line == "Send GetIsAlive()");
+			TEST_EQUAL("Send GetIsAlive()", line, line);
 			TEST_THAT(reader.GetLine(line));
-			TEST_THAT(line == "Receive IsAlive()");
+			TEST_EQUAL("Receive IsAlive()", line, line);
 
 			TEST_THAT(reader.GetLine(line));
 			comp = "Send StoreFile(0x3,";
-			TEST_THAT(line.substr(0, comp.size()) == comp);
+			TEST_EQUAL(comp, line.substr(0, comp.size()), line);
 			comp = ",\"f1\")";
-			TEST_THAT(line.substr(line.size() - comp.size())
-				== comp);
+			std::string sub = line.substr(line.size() - comp.size());
+			TEST_EQUAL(comp, sub, line);
+			std::string comp2 = ",0x0,";
+			sub = line.substr(line.size() - comp.size() -
+				comp2.size() + 1, comp2.size());
+			TEST_LINE(comp2 != sub, line);
 		}
 		
+		// four-second delay on first read() of f1
+		// should mean that no keepalives were sent,
+		// because diff was immediately aborted
+		// before any matching blocks could be found.
 		intercept_setup_delay("testfiles/TestDir1/spacetest/f1", 
 			0, 4000, SYS_read, 1);
 		pid = start_internal_daemon();
@@ -874,10 +909,10 @@
 
 			TEST_THAT(reader.GetLine(line));
 			comp = "Send StoreFile(0x3,";
-			TEST_THAT(line.substr(0, comp.size()) == comp);
+			TEST_EQUAL(comp, line.substr(0, comp.size()), line);
 			comp = ",0x0,\"f1\")";
-			TEST_THAT(line.substr(line.size() - comp.size())
-				== comp);
+			std::string sub = line.substr(line.size() - comp.size());
+			TEST_EQUAL(comp, sub, line);
 		}
 
 		intercept_setup_delay("testfiles/TestDir1/spacetest/f1", 
@@ -935,12 +970,20 @@
 			TEST_THAT(reader.GetLine(line));
 			TEST_THAT(line == "Receive IsAlive()");
 
+			// but two matching blocks should have been found
+			// already, so the upload should be a diff.
+
 			TEST_THAT(reader.GetLine(line));
 			comp = "Send StoreFile(0x3,";
-			TEST_THAT(line.substr(0, comp.size()) == comp);
-			comp = ",0x0,\"f1\")";
-			TEST_THAT(line.substr(line.size() - comp.size())
-				== comp);
+			TEST_EQUAL(comp, line.substr(0, comp.size()), line);
+			comp = ",\"f1\")";
+			std::string sub = line.substr(line.size() - comp.size());
+
+			TEST_EQUAL(comp, sub, line);
+			std::string comp2 = ",0x0,";
+			sub = line.substr(line.size() - comp.size() -
+				comp2.size() + 1, comp2.size());
+			TEST_LINE(comp2 != sub, line);
 		}
 
 		intercept_setup_readdir_hook("testfiles/TestDir1/spacetest/d1", 
@@ -1002,17 +1045,17 @@
 		{
 			std::string line;
 			TEST_THAT(reader.GetLine(line));
-			TEST_THAT(line == "Receive Success(0x3)");
+			TEST_EQUAL("Receive Success(0x3)", line, line);
 			TEST_THAT(reader.GetLine(line));
-			TEST_THAT(line == "Receiving stream, size 425");
+			TEST_EQUAL("Receiving stream, size 425", line, line);
 			TEST_THAT(reader.GetLine(line));
-			TEST_THAT(line == "Send GetIsAlive()");
+			TEST_EQUAL("Send GetIsAlive()", line, line);
 			TEST_THAT(reader.GetLine(line));
-			TEST_THAT(line == "Receive IsAlive()");
+			TEST_EQUAL("Receive IsAlive()", line, line);
 			TEST_THAT(reader.GetLine(line));
-			TEST_THAT(line == "Send GetIsAlive()");
+			TEST_EQUAL("Send GetIsAlive()", line, line);
 			TEST_THAT(reader.GetLine(line));
-			TEST_THAT(line == "Receive IsAlive()");
+			TEST_EQUAL("Receive IsAlive()", line, line);
 		}
 
 		TEST_THAT(unlink(touchfile.c_str()) == 0);


From boxbackup-dev@fluffy.co.uk  Sat Dec  8 22:37:56 2007
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Sat,  8 Dec 2007 22:37:56 +0000 (UTC)
Subject: [Box Backup-commit] COMMIT r1966 - box/chris/general/bin/bbackupquery
Message-ID: <20071208223756.EEB9E325A0D@www.boxbackup.org>

Author: chris
Date: 2007-12-08 22:37:56 +0000 (Sat, 08 Dec 2007)
New Revision: 1966

Modified:
   box/chris/general/bin/bbackupquery/BackupQueries.cpp
Log:
Ensure that restore failure sets the return code from bbackupquery, so
that symlink following test fails. (merges [1926])


Modified: box/chris/general/bin/bbackupquery/BackupQueries.cpp
===================================================================
--- box/chris/general/bin/bbackupquery/BackupQueries.cpp	2007-12-08 22:34:42 UTC (rev 1965)
+++ box/chris/general/bin/bbackupquery/BackupQueries.cpp	2007-12-08 22:37:56 UTC (rev 1966)
@@ -2028,11 +2028,13 @@
 	catch(std::exception &e)
 	{
 		BOX_ERROR("Failed to restore: " << e.what());
+		SetReturnCode(COMMAND_RETURN_ERROR);
 		return;
 	}
 	catch(...)
 	{
 		BOX_ERROR("Failed to restore: unknown exception");
+		SetReturnCode(COMMAND_RETURN_ERROR);
 		return;
 	}
 
@@ -2044,10 +2046,12 @@
 	
 	case Restore_ResumePossible:
 		BOX_ERROR("Resume possible -- repeat command with -r flag to resume");
+		SetReturnCode(COMMAND_RETURN_ERROR);
 		break;
 	
 	case Restore_TargetExists:
 		BOX_ERROR("The target directory exists. You cannot restore over an existing directory.");
+		SetReturnCode(COMMAND_RETURN_ERROR);
 		break;
 		
 	#ifdef WIN32
@@ -2055,15 +2059,18 @@
 		BOX_ERROR("The target directory path does not exist.\n"
 			"To restore to a directory whose parent "
 			"does not exist, create the parent first.");
+		SetReturnCode(COMMAND_RETURN_ERROR);
 		break;
 	#endif
 
 	case Restore_UnknownError:
 		BOX_ERROR("Unknown error during restore.");
+		SetReturnCode(COMMAND_RETURN_ERROR);
 		break;
 
 	default:
 		BOX_ERROR("Unknown restore result " << result << ".");
+		SetReturnCode(COMMAND_RETURN_ERROR);
 		break;
 	}
 }


From boxbackup-dev@fluffy.co.uk  Sat Dec  8 22:40:47 2007
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Sat,  8 Dec 2007 22:40:47 +0000 (UTC)
Subject: [Box Backup-commit] COMMIT r1967 - box/chris/general/test/bbackupd
Message-ID: <20071208224047.5A295325A0D@www.boxbackup.org>

Author: chris
Date: 2007-12-08 22:40:47 +0000 (Sat, 08 Dec 2007)
New Revision: 1967

Modified:
   box/chris/general/test/bbackupd/testbbackupd.cpp
Log:
Pass bbackupd_args to the internal daemon (spaces are NOT supported).

Stop early if a keepalive test fails, for debugging.

(merges [1928] [1929])


Modified: box/chris/general/test/bbackupd/testbbackupd.cpp
===================================================================
--- box/chris/general/test/bbackupd/testbbackupd.cpp	2007-12-08 22:37:56 UTC (rev 1966)
+++ box/chris/general/test/bbackupd/testbbackupd.cpp	2007-12-08 22:40:47 UTC (rev 1967)
@@ -604,8 +604,23 @@
 	// ensure that no child processes end up running tests!
 	int own_pid = getpid();
 		
+	// this is a quick hack to allow passing some options to the daemon
+	const char* argv[] = {
+		"dummy",
+		bbackupd_args.c_str(),
+	};
+
 	BackupDaemon daemon;
-	int result = daemon.Main("testfiles/bbackupd.conf");
+	int result;
+
+	if (bbackupd_args.size() > 0)
+	{
+		result = daemon.Main("testfiles/bbackupd.conf", 2, argv);
+	}
+	else
+	{
+		result = daemon.Main("testfiles/bbackupd.conf", 1, argv);
+	}
 	
 	TEST_THAT(result == 0);
 	if (result != 0)
@@ -862,6 +877,7 @@
 		// should mean that no keepalives were sent,
 		// because diff was immediately aborted
 		// before any matching blocks could be found.
+
 		intercept_setup_delay("testfiles/TestDir1/spacetest/f1", 
 			0, 4000, SYS_read, 1);
 		pid = start_internal_daemon();
@@ -915,6 +931,12 @@
 			TEST_EQUAL(comp, sub, line);
 		}
 
+		if (failures > 0)
+		{
+			// stop early to make debugging easier
+			return 1;
+		}
+
 		intercept_setup_delay("testfiles/TestDir1/spacetest/f1", 
 			0, 1000, SYS_read, 3);
 		pid = start_internal_daemon();
@@ -986,6 +1008,12 @@
 			TEST_LINE(comp2 != sub, line);
 		}
 
+		if (failures > 0)
+		{
+			// stop early to make debugging easier
+			return 1;
+		}
+
 		intercept_setup_readdir_hook("testfiles/TestDir1/spacetest/d1", 
 			readdir_test_hook_1);
 		
@@ -1058,6 +1086,12 @@
 			TEST_EQUAL("Receive IsAlive()", line, line);
 		}
 
+		if (failures > 0)
+		{
+			// stop early to make debugging easier
+			return 1;
+		}
+
 		TEST_THAT(unlink(touchfile.c_str()) == 0);
 
 		// restore timers for rest of tests


From boxbackup-dev@fluffy.co.uk  Sat Dec  8 22:49:46 2007
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Sat,  8 Dec 2007 22:49:46 +0000 (UTC)
Subject: [Box Backup-commit] COMMIT r1968 - box/chris/general/lib/common
Message-ID: <20071208224946.D8975325A0D@www.boxbackup.org>

Author: chris
Date: 2007-12-08 22:49:46 +0000 (Sat, 08 Dec 2007)
New Revision: 1968

Modified:
   box/chris/general/lib/common/Timer.cpp
Log:
Don't crash when trying to cleanup timers a second time (or if never
initialised) in release mode. (merges [1934])


Modified: box/chris/general/lib/common/Timer.cpp
===================================================================
--- box/chris/general/lib/common/Timer.cpp	2007-12-08 22:40:47 UTC (rev 1967)
+++ box/chris/general/lib/common/Timer.cpp	2007-12-08 22:49:46 UTC (rev 1968)
@@ -65,6 +65,11 @@
 void Timers::Cleanup()
 {
 	ASSERT(spTimers);
+	if (!spTimers)
+	{
+		BOX_ERROR("Tried to clean up timers when not initialised!");
+		return;
+	}
 	
 	#if defined WIN32 && ! defined PLATFORM_CYGWIN
 		// no support for signals at all


From boxbackup-dev@fluffy.co.uk  Sat Dec  8 22:50:37 2007
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Sat,  8 Dec 2007 22:50:37 +0000 (UTC)
Subject: [Box Backup-commit] COMMIT r1969 - in box/chris/general/lib: common server
Message-ID: <20071208225037.98198325A0D@www.boxbackup.org>

Author: chris
Date: 2007-12-08 22:50:37 +0000 (Sat, 08 Dec 2007)
New Revision: 1969

Modified:
   box/chris/general/lib/common/Test.h
   box/chris/general/lib/server/ServerControl.h
Log:
Slightly improve output from waiting methods. (merges [1935])


Modified: box/chris/general/lib/common/Test.h
===================================================================
--- box/chris/general/lib/common/Test.h	2007-12-08 22:49:46 UTC (rev 1968)
+++ box/chris/general/lib/common/Test.h	2007-12-08 22:50:37 UTC (rev 1969)
@@ -419,7 +419,7 @@
 // Wait a given number of seconds for something to complete
 inline void wait_for_operation(int seconds)
 {
-	printf("waiting: ");
+	printf("Waiting: ");
 	fflush(stdout);
 	for(int l = 0; l < seconds; ++l)
 	{
@@ -427,7 +427,7 @@
 		printf(".");
 		fflush(stdout);
 	}
-	printf("\n");
+	printf(" done.\n");
 	fflush(stdout);
 }
 

Modified: box/chris/general/lib/server/ServerControl.h
===================================================================
--- box/chris/general/lib/server/ServerControl.h	2007-12-08 22:49:46 UTC (rev 1968)
+++ box/chris/general/lib/server/ServerControl.h	2007-12-08 22:50:37 UTC (rev 1969)
@@ -155,26 +155,26 @@
 
 	for (int i = 0; i < 30; i++)
 	{
-		if (!ServerIsAlive(pid)) break;
-		::sleep(1);
-		if (!ServerIsAlive(pid)) break;
-
 		if (i == 0) 
 		{
-			printf("waiting for server to die");
+			printf("Waiting for server to die: ");
 		}
 
 		printf(".");
 		fflush(stdout);
+
+		if (!ServerIsAlive(pid)) break;
+		::sleep(1);
+		if (!ServerIsAlive(pid)) break;
 	}
 
 	if (!ServerIsAlive(pid))
 	{
-		printf("done.\n");
+		printf(" done.\n");
 	}
 	else
 	{
-		printf("failed!\n");
+		printf(" failed!\n");
 	}
 
 	fflush(stdout);


From boxbackup-dev@fluffy.co.uk  Sat Dec  8 23:02:06 2007
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Sat,  8 Dec 2007 23:02:06 +0000 (UTC)
Subject: [Box Backup-commit] COMMIT r1970 - box/chris/general/test/bbackupd
Message-ID: <20071208230206.62E43325A0D@www.boxbackup.org>

Author: chris
Date: 2007-12-08 23:02:06 +0000 (Sat, 08 Dec 2007)
New Revision: 1970

Modified:
   box/chris/general/test/bbackupd/testbbackupd.cpp
Log:
Re-initialise the timers when aborting test run during SSL KeepAlive
tests, as main() will try to clean them up and we'll get an error
message if they're not initialised. (merges [1936])


Modified: box/chris/general/test/bbackupd/testbbackupd.cpp
===================================================================
--- box/chris/general/test/bbackupd/testbbackupd.cpp	2007-12-08 22:50:37 UTC (rev 1969)
+++ box/chris/general/test/bbackupd/testbbackupd.cpp	2007-12-08 23:02:06 UTC (rev 1970)
@@ -872,7 +872,14 @@
 				comp2.size() + 1, comp2.size());
 			TEST_LINE(comp2 != sub, line);
 		}
-		
+	
+		if (failures > 0)
+		{
+			// stop early to make debugging easier
+			Timers::Init();
+			return 1;
+		}
+	
 		// four-second delay on first read() of f1
 		// should mean that no keepalives were sent,
 		// because diff was immediately aborted
@@ -934,6 +941,7 @@
 		if (failures > 0)
 		{
 			// stop early to make debugging easier
+			Timers::Init();
 			return 1;
 		}
 
@@ -1011,6 +1019,7 @@
 		if (failures > 0)
 		{
 			// stop early to make debugging easier
+			Timers::Init();
 			return 1;
 		}
 
@@ -1089,6 +1098,7 @@
 		if (failures > 0)
 		{
 			// stop early to make debugging easier
+			Timers::Init();
 			return 1;
 		}
 


From boxbackup-dev@fluffy.co.uk  Sat Dec  8 23:03:41 2007
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Sat,  8 Dec 2007 23:03:41 +0000 (UTC)
Subject: [Box Backup-commit] COMMIT r1971 - box/chris/general/lib/server
Message-ID: <20071208230341.E84CF325A0D@www.boxbackup.org>

Author: chris
Date: 2007-12-08 23:03:41 +0000 (Sat, 08 Dec 2007)
New Revision: 1971

Modified:
   box/chris/general/lib/server/makeprotocol.pl.in
Log:
Make ExtendedLogging use the logging framework so that we can view
the logs on the console along with other debug output. (merges [1937])


Modified: box/chris/general/lib/server/makeprotocol.pl.in
===================================================================
--- box/chris/general/lib/server/makeprotocol.pl.in	2007-12-08 23:02:06 UTC (rev 1970)
+++ box/chris/general/lib/server/makeprotocol.pl.in	2007-12-08 23:03:41 UTC (rev 1971)
@@ -503,11 +503,11 @@
 
 	if($implement_syslog)
 	{
-		my ($format,$args) = make_log_strings($cmd);
+		my ($log) = make_log_strings_framework($cmd);
 		print CPP <<__E;
 void ${class}LogSysLog(const char *Action) const
 {
-	::syslog(LOG_INFO,"%s $format",Action$args);
+	BOX_TRACE($log);
 }
 __E
 	}
@@ -1004,4 +1004,45 @@
 	return ($cmd.'('.join(',',@str).')', join(',','',@arg));
 }
 
+sub make_log_strings_framework
+{
+	my ($cmd) = @_;
 
+	my @args;
+
+	for(my $x = 0; $x < $#{$cmd_contents{$cmd}}; $x+=2)
+	{
+		my ($ty,$nm) = (${$cmd_contents{$cmd}}[$x], ${$cmd_contents{$cmd}}[$x+1]);
+		
+		if(exists $log_display_types{$ty})
+		{
+			# need to translate it
+			my ($format,$arg) = @{$log_display_types{$ty}};
+			$arg =~ s/VAR/m$nm/g;
+
+			if ($format =~ m'x$')
+			{
+				$arg = "std::hex << std::showbase " .
+					"<< $arg << std::dec";
+			}
+
+			push @args, $arg;
+		}
+		else
+		{
+			# is opaque
+			push @args, '"OPAQUE"';
+		}
+	}
+
+	my $log_cmd = "Action << \" $cmd(\" ";
+	foreach my $arg (@args)
+	{
+		$arg = "<< $arg ";
+	}
+	$log_cmd .= join('<< "," ',@args);
+	$log_cmd .= '<< ")"';
+	return $log_cmd;
+}
+
+


From boxbackup-dev@fluffy.co.uk  Sat Dec  8 23:05:13 2007
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Sat,  8 Dec 2007 23:05:13 +0000 (UTC)
Subject: [Box Backup-commit] COMMIT r1972 - box/chris/general/lib/common
Message-ID: <20071208230513.B07F0325A0D@www.boxbackup.org>

Author: chris
Date: 2007-12-08 23:05:13 +0000 (Sat, 08 Dec 2007)
New Revision: 1972

Modified:
   box/chris/general/lib/common/Logging.h
Log:
Enable TRACE logging in release builds, but make it really cheap
when disabled. (merges [1938])


Modified: box/chris/general/lib/common/Logging.h
===================================================================
--- box/chris/general/lib/common/Logging.h	2007-12-08 23:03:41 UTC (rev 1971)
+++ box/chris/general/lib/common/Logging.h	2007-12-08 23:05:13 UTC (rev 1972)
@@ -37,11 +37,9 @@
 #define BOX_WARNING(stuff) BOX_LOG(Log::WARNING, stuff)
 #define BOX_NOTICE(stuff)  BOX_LOG(Log::NOTICE,  stuff)
 #define BOX_INFO(stuff)    BOX_LOG(Log::INFO,    stuff)
-#if defined NDEBUG && ! defined COMPILE_IN_TRACES
-        #define BOX_TRACE(stuff)   
-#else
-        #define BOX_TRACE(stuff)   BOX_LOG(Log::TRACE, stuff)
-#endif
+#define BOX_TRACE(stuff)   \
+	if (Logging::IsEnabled(Log::TRACE)) \
+	{ BOX_LOG(Log::TRACE, stuff) }
 
 #define BOX_FORMAT_ACCOUNT(accno) \
 	std::hex << \
@@ -191,6 +189,10 @@
 	static void SetContext(std::string context);
 	static void ClearContext();
 	static void SetGlobalLevel(Log::Level level) { sGlobalLevel = level; }
+	static bool IsEnabled(Log::Level level)
+	{
+		return (int)sGlobalLevel >= (int)level;
+	}
 	static void SetProgramName(const std::string& rProgramName);
 };
 


From boxbackup-dev@fluffy.co.uk  Sat Dec  8 23:06:04 2007
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Sat,  8 Dec 2007 23:06:04 +0000 (UTC)
Subject: [Box Backup-commit] COMMIT r1973 - box/chris/general/lib/backupclient
Message-ID: <20071208230604.E4CC5325A0D@www.boxbackup.org>

Author: chris
Date: 2007-12-08 23:06:04 +0000 (Sat, 08 Dec 2007)
New Revision: 1973

Modified:
   box/chris/general/lib/backupclient/BackupStoreFileDiff.cpp
Log:
Use new logging framework for tracing diffs.

Log each block found and each false match at DEBUG level.

(merges [1940])


Modified: box/chris/general/lib/backupclient/BackupStoreFileDiff.cpp
===================================================================
--- box/chris/general/lib/backupclient/BackupStoreFileDiff.cpp	2007-12-08 23:05:13 UTC (rev 1972)
+++ box/chris/general/lib/backupclient/BackupStoreFileDiff.cpp	2007-12-08 23:06:04 UTC (rev 1973)
@@ -18,17 +18,17 @@
 	#include <sys/time.h>
 #endif
 
+#include "BackupStoreConstants.h"
+#include "BackupStoreException.h"
 #include "BackupStoreFile.h"
+#include "BackupStoreFileCryptVar.h"
+#include "BackupStoreFileEncodeStream.h"
 #include "BackupStoreFileWire.h"
-#include "BackupStoreFileCryptVar.h"
 #include "BackupStoreObjectMagic.h"
-#include "BackupStoreException.h"
-#include "BackupStoreFileEncodeStream.h"
-#include "BackupStoreConstants.h"
+#include "CommonException.h"
 #include "FileStream.h"
+#include "MD5Digest.h"
 #include "RollingChecksum.h"
-#include "MD5Digest.h"
-#include "CommonException.h"
 #include "Timer.h"
 
 #include "MemLeakFindOn.h"
@@ -485,10 +485,9 @@
 		THROW_EXCEPTION(BackupStoreException, BadBackupStoreFile)
 	}
 	
-	// TODO: Use buffered file class
-	// Because we read in the file a scanned block size at a time, it is likely to be
-	// inefficient. Probably will be much better to use a buffering IOStream class which
-	// reads data in at the size of the filesystem block size.
+	// TODO: Because we read in the file a scanned block size at a time,
+	// it is likely to be inefficient. Probably will be much better to
+	// calculate checksums for all block sizes in a single pass.
 
 	// Allocate the buffers.
 	uint8_t *pbuffer0 = (uint8_t *)::malloc(bufSize);
@@ -513,7 +512,8 @@
 		for(int s = BACKUP_FILE_DIFF_MAX_BLOCK_SIZES - 1; s >= 0; --s)
 		{
 			ASSERT(Sizes[s] <= bufSize);
-			//TRACE2("Diff pass %d, for block size %d\n", s, Sizes[s]);
+			BOX_TRACE("Diff pass " << s << ", for block size " <<
+				Sizes[s]);
 			
 			// Check we haven't finished
 			if(Sizes[s] == 0)
@@ -552,8 +552,8 @@
 				if(maximumDiffingTime.HasExpired())
 				{
 					ASSERT(pDiffTimer != NULL);
-					TRACE0("MaximumDiffingTime reached - "
-						"suspending file diff\n");
+					BOX_INFO("MaximumDiffingTime reached - "
+						"suspending file diff");
 					abortSearch = true;
 					break;
 				}
@@ -621,6 +621,7 @@
 					{
 						if(SecondStageMatch(phashTable[hash], rolling, beginnings, endings, offset, Sizes[s], fileBlockNumber, pIndex, rFoundBlocks))
 						{
+							BOX_TRACE("Found block match for " << hash << " of " << Sizes[s] << " bytes at offset " << fileOffset);
 							goodnessOfFit[fileOffset] = Sizes[s];
 
 							// Block matched, roll the checksum forward to the next block without doing
@@ -646,6 +647,10 @@
 							// End this loop, so the final byte isn't used again
 							break;
 						}
+						else
+						{
+							BOX_TRACE("False alarm match for " << hash << " of " << Sizes[s] << " bytes at offset " << fileOffset);
+						}
 
 						int64_t NumBlocksFound = static_cast<int64_t>(
 							rFoundBlocks.size());
@@ -722,7 +727,9 @@
 	if(BackupStoreFile::TraceDetailsOfDiffProcess)
 	{
 		// Trace out the found blocks in debug mode
-		TRACE0("Diff: list of found blocks\n======== ======== ======== ========\n  Offset   BlkIdx     Size Movement\n");
+		BOX_TRACE("Diff: list of found blocks");
+		BOX_TRACE("======== ======== ======== ========");
+		BOX_TRACE("  Offset   BlkIdx     Size Movement");
 		for(std::map<int64_t, int64_t>::const_iterator i(rFoundBlocks.begin()); i != rFoundBlocks.end(); ++i)
 		{
 			int64_t orgLoc = 0;
@@ -730,10 +737,13 @@
 			{
 				orgLoc += pIndex[b].mSize;
 			}
-			TRACE4("%8lld %8lld %8lld %8lld\n", i->first, i->second,
-				(int64_t)(pIndex[i->second].mSize), i->first - orgLoc);
+			BOX_TRACE(std::setw(8) << i->first << " " <<
+				std::setw(8) << i->second << " " <<
+				std::setw(8) << pIndex[i->second].mSize << 
+				" " << 
+				std::setw(8) << (i->first - orgLoc));
 		}
-		TRACE0("======== ======== ======== ========\n");
+		BOX_TRACE("======== ======== ======== ========");
 	}
 #endif
 }


From boxbackup-dev@fluffy.co.uk  Sat Dec  8 23:40:29 2007
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Sat,  8 Dec 2007 23:40:29 +0000 (UTC)
Subject: [Box Backup-commit] COMMIT r1974 - box/trunk
Message-ID: <20071208234029.F1E0F325A0D@www.boxbackup.org>

Author: chris
Date: 2007-12-08 23:40:29 +0000 (Sat, 08 Dec 2007)
New Revision: 1974

Modified:
   box/trunk/configure.ac
Log:
Check for optreset (fixes [1930])


Modified: box/trunk/configure.ac
===================================================================
--- box/trunk/configure.ac	2007-12-08 23:06:04 UTC (rev 1973)
+++ box/trunk/configure.ac	2007-12-08 23:40:29 UTC (rev 1974)
@@ -42,6 +42,11 @@
 AC_DEFINE_UNQUOTED([PERL_EXECUTABLE], ["$TARGET_PERL"], 
 	[Location of the perl executable])
 
+AC_CHECK_PROGS([AR],     [ar],    
+	[AC_MSG_ERROR([[cannot find ar executable]])])
+AC_CHECK_PROGS([RANLIB], [ranlib],
+	[AC_MSG_ERROR([[cannot find ranlib executable]])])
+
 ### Checks for libraries.
 
 case $target_os in
@@ -137,6 +142,7 @@
 
 AC_CHECK_TYPES([u_int8_t, u_int16_t, u_int32_t, u_int64_t])
 AC_CHECK_TYPES([uint8_t, uint16_t, uint32_t, uint64_t])
+
 AC_HEADER_STDBOOL
 AC_C_CONST
 AC_C_BIGENDIAN
@@ -146,15 +152,24 @@
 AC_TYPE_OFF_T
 AC_TYPE_PID_T
 AC_TYPE_SIZE_T
+
 AC_CHECK_MEMBERS([struct stat.st_flags])
 AC_CHECK_MEMBERS([struct stat.st_mtimespec])
 AC_CHECK_MEMBERS([struct sockaddr_in.sin_len],,, [[
   #include <sys/types.h>
   #include <netinet/in.h>
   ]])
+
 AC_CHECK_DECLS([INFTIM],,, [[#include <poll.h>]])
 AC_CHECK_DECLS([SO_PEERCRED],,, [[#include <sys/socket.h>]])
 AC_CHECK_DECLS([O_BINARY],,,)
+
+AC_CHECK_DECLS([optreset],,, [[#include <getopt.h>]])
+AC_CHECK_DECL([dirfd],
+	[],
+	AC_DEFINE([dirfd(x)], [(x)->d_fd], [dirfd() replacement for Solaris]),
+	[#include <getopt.h>])
+
 AC_HEADER_TIME
 AC_STRUCT_TM
 AX_CHECK_DIRENT_D_TYPE


From boxbackup-dev@fluffy.co.uk  Sat Dec  8 23:44:18 2007
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Sat,  8 Dec 2007 23:44:18 +0000 (UTC)
Subject: [Box Backup-commit] COMMIT r1975 - in box/chris/general: . lib/server
Message-ID: <20071208234418.1D14D325A0D@www.boxbackup.org>

Author: chris
Date: 2007-12-08 23:44:17 +0000 (Sat, 08 Dec 2007)
New Revision: 1975

Modified:
   box/chris/general/configure.ac
   box/chris/general/lib/server/Daemon.cpp
Log:
Fix getopt reset for solaris and maybe other platforms. See
http://lists.debian.org/debian-glibc/2004/10/msg00070.html.
(merges [1930] [1974] plus local change for Win32)


Modified: box/chris/general/configure.ac
===================================================================
--- box/chris/general/configure.ac	2007-12-08 23:40:29 UTC (rev 1974)
+++ box/chris/general/configure.ac	2007-12-08 23:44:17 UTC (rev 1975)
@@ -42,6 +42,11 @@
 AC_DEFINE_UNQUOTED([PERL_EXECUTABLE], ["$TARGET_PERL"], 
 	[Location of the perl executable])
 
+AC_CHECK_PROGS([AR],     [ar],    
+	[AC_MSG_ERROR([[cannot find ar executable]])])
+AC_CHECK_PROGS([RANLIB], [ranlib],
+	[AC_MSG_ERROR([[cannot find ranlib executable]])])
+
 ### Checks for libraries.
 
 case $target_os in
@@ -137,6 +142,7 @@
 
 AC_CHECK_TYPES([u_int8_t, u_int16_t, u_int32_t, u_int64_t])
 AC_CHECK_TYPES([uint8_t, uint16_t, uint32_t, uint64_t])
+
 AC_HEADER_STDBOOL
 AC_C_CONST
 AC_C_BIGENDIAN
@@ -146,15 +152,24 @@
 AC_TYPE_OFF_T
 AC_TYPE_PID_T
 AC_TYPE_SIZE_T
+
 AC_CHECK_MEMBERS([struct stat.st_flags])
 AC_CHECK_MEMBERS([struct stat.st_mtimespec])
 AC_CHECK_MEMBERS([struct sockaddr_in.sin_len],,, [[
   #include <sys/types.h>
   #include <netinet/in.h>
   ]])
+
 AC_CHECK_DECLS([INFTIM],,, [[#include <poll.h>]])
 AC_CHECK_DECLS([SO_PEERCRED],,, [[#include <sys/socket.h>]])
 AC_CHECK_DECLS([O_BINARY],,,)
+
+AC_CHECK_DECLS([optreset],,, [[#include <getopt.h>]])
+AC_CHECK_DECL([dirfd],
+	[],
+	AC_DEFINE([dirfd(x)], [(x)->d_fd], [dirfd() replacement for Solaris]),
+	[#include <getopt.h>])
+
 AC_HEADER_TIME
 AC_STRUCT_TM
 AX_CHECK_DIRENT_D_TYPE

Modified: box/chris/general/lib/server/Daemon.cpp
===================================================================
--- box/chris/general/lib/server/Daemon.cpp	2007-12-08 23:40:29 UTC (rev 1974)
+++ box/chris/general/lib/server/Daemon.cpp	2007-12-08 23:44:17 UTC (rev 1975)
@@ -276,11 +276,13 @@
 	// reset getopt, just in case anybody used it before.
 	// unfortunately glibc and BSD differ on this point!
 	// http://www.ussg.iu.edu/hypermail/linux/kernel/0305.3/0262.html
-	#ifdef __GLIBC__
+	#if HAVE_DECL_OPTRESET == 1 || defined WIN32
+		optind = 1;
+		optreset = 1;
+	#elif defined __GLIBC__
 		optind = 0;
-	#else
+	#else // Solaris, any others?
 		optind = 1;
-		optreset = 1;
 	#endif
 
 	while((c = getopt(argc, (char * const *)argv, 


From boxbackup-dev@fluffy.co.uk  Sat Dec  8 23:45:06 2007
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Sat,  8 Dec 2007 23:45:06 +0000 (UTC)
Subject: [Box Backup-commit] COMMIT r1976 - box/trunk/infrastructure
Message-ID: <20071208234506.D6838325A0D@www.boxbackup.org>

Author: chris
Date: 2007-12-08 23:45:06 +0000 (Sat, 08 Dec 2007)
New Revision: 1976

Modified:
   box/trunk/infrastructure/makebuildenv.pl.in
Log:
Use detected CXX, AR and RANLIB from configure.


Modified: box/trunk/infrastructure/makebuildenv.pl.in
===================================================================
--- box/trunk/infrastructure/makebuildenv.pl.in	2007-12-08 23:44:17 UTC (rev 1975)
+++ box/trunk/infrastructure/makebuildenv.pl.in	2007-12-08 23:45:06 UTC (rev 1976)
@@ -525,9 +525,9 @@
 #    do not edit!
 #
 #
-CXX = g++
-AR = ar
-RANLIB = ranlib
+CXX = "@CXX@"
+AR = "@AR@"
+RANLIB = "@RANLIB@"
 PERL = "@PERL@"
 WINDRES = windres
 .ifdef RELEASE


From boxbackup-dev@fluffy.co.uk  Sun Dec  9 01:11:24 2007
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Sun,  9 Dec 2007 01:11:24 +0000 (UTC)
Subject: [Box Backup-commit] COMMIT r1977 - box/trunk/bin/bbstoreaccounts
Message-ID: <20071209011124.BF02E325A0D@www.boxbackup.org>

Author: chris
Date: 2007-12-09 01:11:24 +0000 (Sun, 09 Dec 2007)
New Revision: 1977

Modified:
   box/trunk/bin/bbstoreaccounts/bbstoreaccounts.cpp
Log:
Properly report when we failed to lock the account, so that changes
requiring a write lock don't proceed when we don't have one.


Modified: box/trunk/bin/bbstoreaccounts/bbstoreaccounts.cpp
===================================================================
--- box/trunk/bin/bbstoreaccounts/bbstoreaccounts.cpp	2007-12-08 23:45:06 UTC (rev 1976)
+++ box/trunk/bin/bbstoreaccounts/bbstoreaccounts.cpp	2007-12-09 01:11:24 UTC (rev 1977)
@@ -147,7 +147,7 @@
 		// Couldn't lock the account -- just stop now
 		BOX_ERROR("Failed to lock the account, did not change limits. "
 			"Try again later.");
-		return 1;
+		return false;
 	}
 
 	return gotLock;


From boxbackup-dev@fluffy.co.uk  Sun Dec  9 01:11:55 2007
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Sun,  9 Dec 2007 01:11:55 +0000 (UTC)
Subject: [Box Backup-commit] COMMIT r1978 - box/trunk/bin/bbstoreaccounts
Message-ID: <20071209011155.BCD11326969@www.boxbackup.org>

Author: chris
Date: 2007-12-09 01:11:55 +0000 (Sun, 09 Dec 2007)
New Revision: 1978

Modified:
   box/trunk/bin/bbstoreaccounts/bbstoreaccounts.cpp
Log:
Even simpler replacement for [1977].


Modified: box/trunk/bin/bbstoreaccounts/bbstoreaccounts.cpp
===================================================================
--- box/trunk/bin/bbstoreaccounts/bbstoreaccounts.cpp	2007-12-09 01:11:24 UTC (rev 1977)
+++ box/trunk/bin/bbstoreaccounts/bbstoreaccounts.cpp	2007-12-09 01:11:55 UTC (rev 1978)
@@ -147,7 +147,6 @@
 		// Couldn't lock the account -- just stop now
 		BOX_ERROR("Failed to lock the account, did not change limits. "
 			"Try again later.");
-		return false;
 	}
 
 	return gotLock;


From boxbackup-dev@fluffy.co.uk  Sun Dec  9 01:13:05 2007
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Sun,  9 Dec 2007 01:13:05 +0000 (UTC)
Subject: [Box Backup-commit] COMMIT r1979 - box/chris/general/bin/bbstoreaccounts
Message-ID: <20071209011305.DA8DC325A0D@www.boxbackup.org>

Author: chris
Date: 2007-12-09 01:13:05 +0000 (Sun, 09 Dec 2007)
New Revision: 1979

Modified:
   box/chris/general/bin/bbstoreaccounts/bbstoreaccounts.cpp
Log:
Make bbstoreaccounts properly report when it failed to lock the
account, so that changes requiring a write lock don't proceed
when we don't have one. (merges [1977] [1978])


Modified: box/chris/general/bin/bbstoreaccounts/bbstoreaccounts.cpp
===================================================================
--- box/chris/general/bin/bbstoreaccounts/bbstoreaccounts.cpp	2007-12-09 01:11:55 UTC (rev 1978)
+++ box/chris/general/bin/bbstoreaccounts/bbstoreaccounts.cpp	2007-12-09 01:13:05 UTC (rev 1979)
@@ -147,7 +147,6 @@
 		// Couldn't lock the account -- just stop now
 		BOX_ERROR("Failed to lock the account, did not change limits. "
 			"Try again later.");
-		return 1;
 	}
 
 	return gotLock;


From boxbackup-dev@fluffy.co.uk  Sun Dec  9 01:13:37 2007
From: boxbackup-dev@fluffy.co.uk (Box Backup)
Date: Sun, 09 Dec 2007 01:13:37 -0000
Subject: [Box Backup-commit] Re: #31: bbstoreaccounts info prints out wrong info?
In-Reply-To: <042.b18de7e0dae291cfc5093fc55fc12f95@fluffy.co.uk>
References: <042.b18de7e0dae291cfc5093fc55fc12f95@fluffy.co.uk>
Message-ID: <051.3086d61af5ed542d347cf9c3ff3554d2@fluffy.co.uk>

#31: bbstoreaccounts info prints out wrong info?
------------------------------+---------------------------------------------
  Reporter:  petej            |       Owner:        
      Type:  defect           |      Status:  closed
  Priority:  major            |   Milestone:  0.11  
 Component:  bbstoreaccounts  |     Version:  0.10  
Resolution:  fixed            |    Keywords:        
------------------------------+---------------------------------------------
Changes (by chris):

  * priority:  trivial => major
  * status:  new => closed
  * resolution:  => fixed
  * milestone:  => 0.11

Comment:

 Thanks for the report, that was a serious bug, fixed in [1977].

-- 
Ticket URL: <http://www.boxbackup.org/trac/ticket/31#comment:1>
Box Backup <http://www.boxbackup.org/>
An open source, completely automatic on-line backup system for UNIX.

From boxbackup-dev@fluffy.co.uk  Sun Dec  9 01:33:58 2007
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Sun,  9 Dec 2007 01:33:58 +0000 (UTC)
Subject: [Box Backup-commit] COMMIT r1980 - box/chris/general/bin/bbackupd
Message-ID: <20071209013358.9E901325A0D@www.boxbackup.org>

Author: chris
Date: 2007-12-09 01:33:58 +0000 (Sun, 09 Dec 2007)
New Revision: 1980

Modified:
   box/chris/general/bin/bbackupd/BackupDaemon.cpp
Log:
Fix crash when notifyscript is called for BackupStart or BackupFinish.
(merges [1862])


Modified: box/chris/general/bin/bbackupd/BackupDaemon.cpp
===================================================================
--- box/chris/general/bin/bbackupd/BackupDaemon.cpp	2007-12-09 01:13:05 UTC (rev 1979)
+++ box/chris/general/bin/bbackupd/BackupDaemon.cpp	2007-12-09 01:33:58 UTC (rev 1980)
@@ -2369,10 +2369,11 @@
 		return;
 	}
 
-	// Is there a notifation script?
+	// Is there a notification script?
 	const Configuration &conf(GetConfiguration());
 	if(!conf.KeyExists("NotifyScript"))
 	{
+		// Log, and then return
 		if(Event != NotifyEvent_BackupStart &&
 			Event != NotifyEvent_BackupFinish)
 		{


From boxbackup-dev@fluffy.co.uk  Sun Dec  9 01:35:08 2007
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Sun,  9 Dec 2007 01:35:08 +0000 (UTC)
Subject: [Box Backup-commit] COMMIT r1981 - in box/chris/general: bin/bbackupd lib/backupclient
Message-ID: <20071209013508.90E2D325A0D@www.boxbackup.org>

Author: chris
Date: 2007-12-09 01:35:08 +0000 (Sun, 09 Dec 2007)
New Revision: 1981

Modified:
   box/chris/general/bin/bbackupd/BackupDaemon.cpp
   box/chris/general/bin/bbackupd/BackupDaemon.h
   box/chris/general/lib/backupclient/BackupDaemonConfigVerify.cpp
   box/chris/general/lib/backupclient/BackupStoreConstants.h
Log:
Allow configuration of the time to delete redundant store locations.
(merges [1863])


Modified: box/chris/general/bin/bbackupd/BackupDaemon.cpp
===================================================================
--- box/chris/general/bin/bbackupd/BackupDaemon.cpp	2007-12-09 01:33:58 UTC (rev 1980)
+++ box/chris/general/bin/bbackupd/BackupDaemon.cpp	2007-12-09 01:35:08 UTC (rev 1981)
@@ -983,6 +983,9 @@
 					SecondsToBoxTime(
 						conf.GetKeyValueInt(
 							"MaxFileTimeInFuture"));
+				mDeleteRedundantLocationsAfter =
+					conf.GetKeyValueInt(
+						"DeleteRedundantLocationsAfter");
 
 				clientContext.SetMaximumDiffingTime(maximumDiffingTime);
 				clientContext.SetKeepAliveTime(keepAliveTime);
@@ -1766,7 +1769,7 @@
 	for(std::list<std::pair<std::string, Configuration> >::const_iterator i = rLocationsConf.mSubConfigurations.begin();
 		i != rLocationsConf.mSubConfigurations.end(); ++i)
 	{
-		BOX_TRACE("new location");
+		BOX_TRACE("new location: " << i->first);
 		// Create a record for it
 		std::auto_ptr<Location> apLoc(new Location);
 
@@ -1938,6 +1941,8 @@
 				<< apLoc->mName << "' path '"
 				<< apLoc->mPath << "': " << e.what() <<
 				": please check for previous errors");
+			delete ploc;
+			ploc = 0;
 			throw;
 		}
 		catch(...)
@@ -1953,6 +1958,23 @@
 	// Any entries in the root directory which need deleting?
 	if(dir.GetNumberOfEntries() > 0)
 	{
+		box_time_t now = GetCurrentBoxTime();
+
+		// This should reset the timer if the list of unused
+		// locations changes, but it will not if the number of
+		// unused locations does not change, but the locations
+		// do change, e.g. one mysteriously appears and another
+		// mysteriously appears. (FIXME)
+		if (dir.GetNumberOfEntries() != mUnusedRootDirEntries.size() ||
+			mDeleteUnusedRootDirEntriesAfter == 0)
+		{
+			mDeleteUnusedRootDirEntriesAfter = now + 
+				SecondsToBoxTime(mDeleteRedundantLocationsAfter);
+		}
+
+		int secs = BoxTimeToSeconds(mDeleteUnusedRootDirEntriesAfter
+			- now);
+
 		BOX_NOTICE(dir.GetNumberOfEntries() << " redundant locations "
 			"in root directory found, will delete from store "
 			"after " << BACKUP_DELETE_UNUSED_ROOT_ENTRIES_AFTER 

Modified: box/chris/general/bin/bbackupd/BackupDaemon.h
===================================================================
--- box/chris/general/bin/bbackupd/BackupDaemon.h	2007-12-09 01:33:58 UTC (rev 1980)
+++ box/chris/general/bin/bbackupd/BackupDaemon.h	2007-12-09 01:35:08 UTC (rev 1981)
@@ -166,6 +166,8 @@
 	std::vector<BackupClientInodeToIDMap *> mCurrentIDMaps;
 	std::vector<BackupClientInodeToIDMap *> mNewIDMaps;
 	
+	int mDeleteRedundantLocationsAfter;
+
 	// For the command socket
 	class CommandSocketInfo
 	{

Modified: box/chris/general/lib/backupclient/BackupDaemonConfigVerify.cpp
===================================================================
--- box/chris/general/lib/backupclient/BackupDaemonConfigVerify.cpp	2007-12-09 01:33:58 UTC (rev 1980)
+++ box/chris/general/lib/backupclient/BackupDaemonConfigVerify.cpp	2007-12-09 01:35:08 UTC (rev 1981)
@@ -77,6 +77,7 @@
 				// return "now" if it's allowed, or a number of seconds if it's not
 
 	{"MaximumDiffingTime", 0, ConfigTest_IsInt, 0},
+	{"DeleteRedundantLocationsAfter", "172800", ConfigTest_IsInt, 0},
 
 	{"FileTrackingSizeThreshold", 0, ConfigTest_Exists | ConfigTest_IsInt, 0},
 	{"DiffingUploadSizeThreshold", 0, ConfigTest_Exists | ConfigTest_IsInt, 0},

Modified: box/chris/general/lib/backupclient/BackupStoreConstants.h
===================================================================
--- box/chris/general/lib/backupclient/BackupStoreConstants.h	2007-12-09 01:33:58 UTC (rev 1980)
+++ box/chris/general/lib/backupclient/BackupStoreConstants.h	2007-12-09 01:35:08 UTC (rev 1981)
@@ -40,14 +40,5 @@
 // This is a multiple of the number of blocks in the diff from file.
 #define BACKUP_FILE_DIFF_MAX_BLOCK_FIND_MULTIPLE	4096
 
-// How many seconds to wait before deleting unused root directory entries?
-#ifndef NDEBUG
-	// Debug: 30 seconds (easier to test)
-	#define BACKUP_DELETE_UNUSED_ROOT_ENTRIES_AFTER		30
-#else
-	// Release: 2 days (plenty of time for sysadmins to notice, or change their mind)
-	#define BACKUP_DELETE_UNUSED_ROOT_ENTRIES_AFTER		172800
-#endif
-
 #endif // BACKUPSTORECONSTANTS__H
 


From boxbackup-dev@fluffy.co.uk  Sun Dec  9 01:35:36 2007
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Sun,  9 Dec 2007 01:35:36 +0000 (UTC)
Subject: [Box Backup-commit] COMMIT r1982 - box/chris/general/lib/common
Message-ID: <20071209013536.B5710325A0D@www.boxbackup.org>

Author: chris
Date: 2007-12-09 01:35:36 +0000 (Sun, 09 Dec 2007)
New Revision: 1982

Modified:
   box/chris/general/lib/common/Logging.h
Log:
Revert from hex to decimal default format after logging an account
number. (merges [1864])


Modified: box/chris/general/lib/common/Logging.h
===================================================================
--- box/chris/general/lib/common/Logging.h	2007-12-09 01:35:08 UTC (rev 1981)
+++ box/chris/general/lib/common/Logging.h	2007-12-09 01:35:36 UTC (rev 1982)
@@ -47,7 +47,8 @@
 	std::internal << \
 	std::setw(10) << \
 	std::setfill('0') << \
-	(accno)
+	(accno) \\
+	std::dec
 
 #define BOX_FORMAT_OBJECTID(objectid) \
 	std::hex << \


From boxbackup-dev@fluffy.co.uk  Sun Dec  9 01:36:12 2007
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Sun,  9 Dec 2007 01:36:12 +0000 (UTC)
Subject: [Box Backup-commit] COMMIT r1983 - box/chris/general
Message-ID: <20071209013612.C7DDF325A0D@www.boxbackup.org>

Author: chris
Date: 2007-12-09 01:36:12 +0000 (Sun, 09 Dec 2007)
New Revision: 1983

Modified:
   box/chris/general/configure.ac
Log:
Die if infrastructure/makebuildenv.pl or infrastructure/makeparcels.pl fails
during configure. (merges [1866])


Modified: box/chris/general/configure.ac
===================================================================
--- box/chris/general/configure.ac	2007-12-09 01:35:36 UTC (rev 1982)
+++ box/chris/general/configure.ac	2007-12-09 01:36:12 UTC (rev 1983)
@@ -296,8 +296,11 @@
 
 # Configure the Box build system
 echo
-$PERL ./infrastructure/makebuildenv.pl &&
-  $PERL ./infrastructure/makeparcels.pl
+if ! $PERL ./infrastructure/makebuildenv.pl \
+|| ! $PERL ./infrastructure/makeparcels.pl; then
+	echo "Making infrastructure failed!"
+	exit 1
+fi
 
 # Write summary of important info
 cat <<EOC


From boxbackup-dev@fluffy.co.uk  Sun Dec  9 01:38:06 2007
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Sun,  9 Dec 2007 01:38:06 +0000 (UTC)
Subject: [Box Backup-commit] COMMIT r1984 - box/chris/general/lib/common
Message-ID: <20071209013806.150DB325A0D@www.boxbackup.org>

Author: chris
Date: 2007-12-09 01:38:05 +0000 (Sun, 09 Dec 2007)
New Revision: 1984

Modified:
   box/chris/general/lib/common/Logging.h
Log:
Revert to decimal properly, and also after logging an Object ID.
(merges [1869] [1870])


Modified: box/chris/general/lib/common/Logging.h
===================================================================
--- box/chris/general/lib/common/Logging.h	2007-12-09 01:36:12 UTC (rev 1983)
+++ box/chris/general/lib/common/Logging.h	2007-12-09 01:38:05 UTC (rev 1984)
@@ -47,13 +47,14 @@
 	std::internal << \
 	std::setw(10) << \
 	std::setfill('0') << \
-	(accno) \\
+	(accno) << \
 	std::dec
 
 #define BOX_FORMAT_OBJECTID(objectid) \
 	std::hex << \
 	std::showbase << \
-	(objectid)
+	(objectid) << \
+	std::dec
 
 #undef ERROR
 


From boxbackup-dev@fluffy.co.uk  Sun Dec  9 01:38:47 2007
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Sun,  9 Dec 2007 01:38:47 +0000 (UTC)
Subject: [Box Backup-commit] COMMIT r1985 - in box/chris/general/lib: backupstore compress server
Message-ID: <20071209013847.09DBC326969@www.boxbackup.org>

Author: chris
Date: 2007-12-09 01:38:46 +0000 (Sun, 09 Dec 2007)
New Revision: 1985

Modified:
   box/chris/general/lib/backupstore/BackupStoreInfo.h
   box/chris/general/lib/compress/Compress.h
   box/chris/general/lib/server/ProtocolUncertainStream.h
Log:
Fix wrong comments, thanks to Nestor Arocha Rodriguez.
(merges [1868])


Modified: box/chris/general/lib/backupstore/BackupStoreInfo.h
===================================================================
--- box/chris/general/lib/backupstore/BackupStoreInfo.h	2007-12-09 01:38:05 UTC (rev 1984)
+++ box/chris/general/lib/backupstore/BackupStoreInfo.h	2007-12-09 01:38:46 UTC (rev 1985)
@@ -18,7 +18,7 @@
 
 // --------------------------------------------------------------------------
 //
-// File
+// Class
 //		Name:    BackupStoreInfo
 //		Purpose: Main backup store information storage
 //		Created: 2003/08/28

Modified: box/chris/general/lib/compress/Compress.h
===================================================================
--- box/chris/general/lib/compress/Compress.h	2007-12-09 01:38:05 UTC (rev 1984)
+++ box/chris/general/lib/compress/Compress.h	2007-12-09 01:38:46 UTC (rev 1985)
@@ -1,7 +1,7 @@
 // --------------------------------------------------------------------------
 //
 // File
-//		Name:    CompressContext.h
+//		Name:    Compress.h
 //		Purpose: Interface to zlib compression
 //		Created: 5/12/03
 //
@@ -17,7 +17,7 @@
 // --------------------------------------------------------------------------
 //
 // Class
-//		Name:    CompressContext
+//		Name:    Compress
 //		Purpose: Interface to zlib compression, only very slight wrapper.
 //				 (Use CompressStream for a more friendly interface.)
 //		Created: 5/12/03

Modified: box/chris/general/lib/server/ProtocolUncertainStream.h
===================================================================
--- box/chris/general/lib/server/ProtocolUncertainStream.h	2007-12-09 01:38:05 UTC (rev 1984)
+++ box/chris/general/lib/server/ProtocolUncertainStream.h	2007-12-09 01:38:46 UTC (rev 1985)
@@ -1,7 +1,7 @@
 // --------------------------------------------------------------------------
 //
 // File
-//		Name:    PartialReadStream.h
+//		Name:    ProtocolUncertainStream.h
 //		Purpose: Read part of another stream
 //		Created: 2003/12/05
 //
@@ -15,7 +15,7 @@
 // --------------------------------------------------------------------------
 //
 // Class
-//		Name:    PartialReadStream
+//		Name:    ProtocolUncertainStream
 //		Purpose: Read part of another stream
 //		Created: 2003/12/05
 //


From boxbackup-dev@fluffy.co.uk  Sun Dec  9 01:39:11 2007
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Sun,  9 Dec 2007 01:39:11 +0000 (UTC)
Subject: [Box Backup-commit] COMMIT r1986 - box/chris/general/documentation/boxbackup
Message-ID: <20071209013911.54E03325A0D@www.boxbackup.org>

Author: chris
Date: 2007-12-09 01:39:11 +0000 (Sun, 09 Dec 2007)
New Revision: 1986

Modified:
   box/chris/general/documentation/boxbackup/adminguide.xml
Log:
Document the need for -v options when using LogAllFileAccess.
(merges [1871])


Modified: box/chris/general/documentation/boxbackup/adminguide.xml
===================================================================
--- box/chris/general/documentation/boxbackup/adminguide.xml	2007-12-09 01:38:46 UTC (rev 1985)
+++ box/chris/general/documentation/boxbackup/adminguide.xml	2007-12-09 01:39:11 UTC (rev 1986)
@@ -1160,6 +1160,13 @@
                 file, or crashing while trying to upload it. The logs will be
                 sent to the system log or Windows Event Viewer.</para>
 
+		<para>This generates a <emphasis>lot</emphasis>
+		of output, so it should only be used when instructed, or when
+		you suspect that bbackupd is skipping some files and want to
+		know why. Because it is verbose, the messages are hidden by
+		default even if the option is enabled. To see them, you must
+		run bbackupd with at least one -v option.</para>
+
                 <para>This is a boolean value, which may be set to
                 <quote>Yes</quote> or <quote>No</quote>. The default is of
                 course <quote>No</quote>.</para>
@@ -1971,4 +1978,4 @@
       testing, and should not be relied on in a production environment.</para>
     </section>
   </appendix>
-</book>
\ No newline at end of file
+</book>


From boxbackup-dev@fluffy.co.uk  Sun Dec  9 01:44:44 2007
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Sun,  9 Dec 2007 01:44:44 +0000 (UTC)
Subject: [Box Backup-commit] COMMIT r1987 - in box/chris/general/test/bbackupd: . testfiles
Message-ID: <20071209014444.DD35B325A0D@www.boxbackup.org>

Author: chris
Date: 2007-12-09 01:44:44 +0000 (Sun, 09 Dec 2007)
New Revision: 1987

Added:
   box/chris/general/test/bbackupd/testfiles/bbackupd-temploc.conf
Modified:
   box/chris/general/test/bbackupd/testbbackupd.cpp
   box/chris/general/test/bbackupd/testfiles/bbackupd.conf.in
Log:
Test that redundant locations are really deleted after the time
expires. (merges [1867])


Modified: box/chris/general/test/bbackupd/testbbackupd.cpp
===================================================================
--- box/chris/general/test/bbackupd/testbbackupd.cpp	2007-12-09 01:39:11 UTC (rev 1986)
+++ box/chris/general/test/bbackupd/testbbackupd.cpp	2007-12-09 01:44:44 UTC (rev 1987)
@@ -598,6 +598,42 @@
 	TEST_THAT(id != BackupProtocolClientListDirectory::RootDirectory);
 	return id;
 }
+
+SocketStreamTLS sSocket;
+
+std::auto_ptr<BackupProtocolClient> Connect(TLSContext& rContext, int flags)
+{
+	sSocket.Open(rContext, Socket::TypeINET, 
+		"localhost", BOX_PORT_BBSTORED);
+	std::auto_ptr<BackupProtocolClient> connection;
+	connection.reset(new BackupProtocolClient(sSocket));
+	connection->Handshake();
+	std::auto_ptr<BackupProtocolClientVersion> 
+		serverVersion(connection->QueryVersion(
+			BACKUP_STORE_SERVER_VERSION));
+	if(serverVersion->GetVersion() != 
+		BACKUP_STORE_SERVER_VERSION)
+	{
+		THROW_EXCEPTION(BackupStoreException, 
+			WrongServerVersion);
+	}
+	connection->QueryLogin(0x01234567, flags);
+	return connection;
+}
+
+std::auto_ptr<BackupStoreDirectory> ReadDirectory
+(
+	BackupProtocolClient& rClient,
+	int64_t id
+)
+{
+	std::auto_ptr<BackupProtocolClientSuccess> dirreply(
+		rClient.QueryListDirectory(id, false, 0, false));
+	std::auto_ptr<IOStream> dirstream(rClient.ReceiveStream());
+	std::auto_ptr<BackupStoreDirectory> apDir(new BackupStoreDirectory());
+	apDir->ReadFromStream(*dirstream, rClient.GetTimeout());
+	return apDir;
+}
 	
 int start_internal_daemon()
 {
@@ -1526,40 +1562,25 @@
 
 		// Check that we can find it in directory listing
 		{
-			SocketStreamTLS conn;
-			conn.Open(context, Socket::TypeINET, "localhost", 
-				BOX_PORT_BBSTORED);
-			BackupProtocolClient protocol(conn);
-			protocol.QueryVersion(BACKUP_STORE_SERVER_VERSION);
-			protocol.QueryLogin(0x01234567, 0);
+			std::auto_ptr<BackupProtocolClient> client =
+				Connect(context, 0);
 
-			int64_t rootDirId = BackupProtocolClientListDirectory
-				::RootDirectory;
-			std::auto_ptr<BackupProtocolClientSuccess> dirreply(
-				protocol.QueryListDirectory(
-					rootDirId, false, 0, false));
-			std::auto_ptr<IOStream> dirstream(
-				protocol.ReceiveStream());
-			BackupStoreDirectory dir;
-			dir.ReadFromStream(*dirstream, protocol.GetTimeout());
+			std::auto_ptr<BackupStoreDirectory> dir = ReadDirectory(
+				*client, 
+				BackupProtocolClientListDirectory::RootDirectory);
 
-			int64_t baseDirId = SearchDir(dir, "Test1");
+			int64_t baseDirId = SearchDir(*dir, "Test1");
 			TEST_THAT(baseDirId != 0);
-			dirreply = protocol.QueryListDirectory(baseDirId,
-				false, 0, false);
-			dirstream = protocol.ReceiveStream();
-			dir.ReadFromStream(*dirstream, protocol.GetTimeout());
+			dir = ReadDirectory(*client, baseDirId);
 
 			int64_t testDirId = SearchDir(dir, dirname.c_str());
 			TEST_THAT(testDirId != 0);
-			dirreply = protocol.QueryListDirectory(testDirId,
-				false, 0, false);
-			dirstream = protocol.ReceiveStream();
-			dir.ReadFromStream(*dirstream, protocol.GetTimeout());
+			dir = ReadDirectory(*client, testDirId);
 		
 			TEST_THAT(SearchDir(dir, filename.c_str()) != 0);
 			// Log out
-			protocol.QueryFinished();
+			client->QueryFinished();
+			sSocket.Close();
 		}
 
 
@@ -2310,75 +2331,37 @@
 			"actually work\n");
 
 		{
-			std::string errs;
-			std::auto_ptr<Configuration> config(
-				Configuration::LoadAndVerify(
-					"testfiles/bbackupd.conf",
-					&BackupDaemonConfigVerify, errs));
-			Configuration& conf(*config);
-			SSLLib::Initialise();
-			TLSContext tlsContext;
-			std::string certFile(conf.GetKeyValue("CertificateFile"));
-			std::string keyFile (conf.GetKeyValue("PrivateKeyFile"));
-			std::string caFile  (conf.GetKeyValue("TrustedCAsFile"));
-			tlsContext.Initialise(false, certFile.c_str(), 
-				keyFile.c_str(), caFile.c_str());
-			BackupClientCryptoKeys_Setup(
-				conf.GetKeyValue("KeysFile").c_str());
-			SocketStreamTLS socket;
-			socket.Open(tlsContext, Socket::TypeINET, 
-				conf.GetKeyValue("StoreHostname").c_str(), 
-				BOX_PORT_BBSTORED);
-			BackupProtocolClient connection(socket);
-			connection.Handshake();
-			std::auto_ptr<BackupProtocolClientVersion> 
-				serverVersion(connection.QueryVersion(
-					BACKUP_STORE_SERVER_VERSION));
-			if(serverVersion->GetVersion() != 
-				BACKUP_STORE_SERVER_VERSION)
-			{
-				THROW_EXCEPTION(BackupStoreException, 
-					WrongServerVersion);
-			}
-			connection.QueryLogin(
-				conf.GetKeyValueInt("AccountNumber"),
+			std::auto_ptr<BackupProtocolClient> client = Connect(
+				context,
 				BackupProtocolClientLogin::Flags_ReadOnly);
 			
-			int64_t rootDirId = BackupProtocolClientListDirectory
-				::RootDirectory;
-			std::auto_ptr<BackupProtocolClientSuccess> dirreply(
-				connection.QueryListDirectory(
-					rootDirId, false, 0, false));
-			std::auto_ptr<IOStream> dirstream(
-				connection.ReceiveStream());
-			BackupStoreDirectory dir;
-			dir.ReadFromStream(*dirstream, connection.GetTimeout());
+			std::auto_ptr<BackupStoreDirectory> dir = ReadDirectory(
+				*client,
+				BackupProtocolClientListDirectory::RootDirectory);
 
-			int64_t testDirId = SearchDir(dir, "Test1");
+			int64_t testDirId = SearchDir(*dir, "Test1");
 			TEST_THAT(testDirId != 0);
-			dirreply = connection.QueryListDirectory(testDirId, 					false, 0, false);
-			dirstream = connection.ReceiveStream();
-			dir.ReadFromStream(*dirstream, connection.GetTimeout());
-			
-			TEST_THAT(!SearchDir(dir, "excluded_1"));
-			TEST_THAT(!SearchDir(dir, "excluded_2"));
-			TEST_THAT(!SearchDir(dir, "exclude_dir"));
-			TEST_THAT(!SearchDir(dir, "exclude_dir_2"));
+			dir = ReadDirectory(*client, testDirId);
+				
+			TEST_THAT(!SearchDir(*dir, "excluded_1"));
+			TEST_THAT(!SearchDir(*dir, "excluded_2"));
+			TEST_THAT(!SearchDir(*dir, "exclude_dir"));
+			TEST_THAT(!SearchDir(*dir, "exclude_dir_2"));
 			// xx_not_this_dir_22 should not be excluded by
 			// ExcludeDirsRegex, because it's a file
-			TEST_THAT(SearchDir (dir, "xx_not_this_dir_22"));
-			TEST_THAT(!SearchDir(dir, "zEXCLUDEu"));
-			TEST_THAT(SearchDir (dir, "dont.excludethis"));
-			TEST_THAT(SearchDir (dir, "xx_not_this_dir_ALWAYSINCLUDE"));
+			TEST_THAT(SearchDir (*dir, "xx_not_this_dir_22"));
+			TEST_THAT(!SearchDir(*dir, "zEXCLUDEu"));
+			TEST_THAT(SearchDir (*dir, "dont.excludethis"));
+			TEST_THAT(SearchDir (*dir, "xx_not_this_dir_ALWAYSINCLUDE"));
 
-			int64_t sub23id = SearchDir(dir, "sub23");
+			int64_t sub23id = SearchDir(*dir, "sub23");
 			TEST_THAT(sub23id != 0);
-			dirreply = connection.QueryListDirectory(sub23id, 					false, 0, false);
-			dirstream = connection.ReceiveStream();
-			dir.ReadFromStream(*dirstream, connection.GetTimeout());
-			TEST_THAT(!SearchDir(dir, "xx_not_this_dir_22"));
-			TEST_THAT(!SearchDir(dir, "somefile.excludethis"));
-			connection.QueryFinished();
+			dir = ReadDirectory(*client, sub23id);
+
+			TEST_THAT(!SearchDir(*dir, "xx_not_this_dir_22"));
+			TEST_THAT(!SearchDir(*dir, "somefile.excludethis"));
+			client->QueryFinished();
+			sSocket.Close();
 		}
 
 		TEST_THAT(ServerIsAlive(bbackupd_pid));
@@ -2521,22 +2504,17 @@
 		int64_t restoredirid = 0;
 		{
 			// connect and log in
-			SocketStreamTLS conn;
-			conn.Open(context, Socket::TypeINET, "localhost", 
-				BOX_PORT_BBSTORED);
-			BackupProtocolClient protocol(conn);
-			protocol.QueryVersion(BACKUP_STORE_SERVER_VERSION);
-			std::auto_ptr<BackupProtocolClientLoginConfirmed> 
-				loginConf(protocol.QueryLogin(0x01234567, 
-				BackupProtocolClientLogin::Flags_ReadOnly));
+			std::auto_ptr<BackupProtocolClient> client = Connect(
+				context,
+				BackupProtocolClientLogin::Flags_ReadOnly);
 
 			// Find the ID of the Test1 directory
-			restoredirid = GetDirID(protocol, "Test1", 
+			restoredirid = GetDirID(*client, "Test1", 
 				BackupProtocolClientListDirectory::RootDirectory);
 			TEST_THAT(restoredirid != 0);
 
 			// Test the restoration
-			TEST_THAT(BackupClientRestore(protocol, restoredirid, 
+			TEST_THAT(BackupClientRestore(*client, restoredirid, 
 				"testfiles/restore-Test1", 
 				true /* print progress dots */) 
 				== Restore_Complete);
@@ -2545,32 +2523,33 @@
 			// to the server, so we'll compare later.
 
 			// Make sure you can't restore a restored directory
-			TEST_THAT(BackupClientRestore(protocol, restoredirid, 
+			TEST_THAT(BackupClientRestore(*client, restoredirid, 
 				"testfiles/restore-Test1", 
 				true /* print progress dots */) 
 				== Restore_TargetExists);
 			
 			// Make sure you can't restore to a nonexistant path
 			printf("Try to restore to a path that doesn't exist\n");
-			TEST_THAT(BackupClientRestore(protocol, restoredirid, 
+			TEST_THAT(BackupClientRestore(*client, restoredirid, 
 				"testfiles/no-such-path/subdir", 
 				true /* print progress dots */) 
 				== Restore_TargetPathNotFound);
 			
 			// Find ID of the deleted directory
-			deldirid = GetDirID(protocol, "x1", restoredirid);
+			deldirid = GetDirID(*client, "x1", restoredirid);
 			TEST_THAT(deldirid != 0);
 
 			// Just check it doesn't bomb out -- will check this 
 			// properly later (when bbackupd is stopped)
-			TEST_THAT(BackupClientRestore(protocol, deldirid, 
+			TEST_THAT(BackupClientRestore(*client, deldirid, 
 				"testfiles/restore-Test1-x1", 
 				true /* print progress dots */, 
 				true /* deleted files */) 
 				== Restore_Complete);
 
 			// Log out
-			protocol.QueryFinished();
+			client->QueryFinished();
+			sSocket.Close();
 		}
 
 		// Compare the restored files
@@ -2877,24 +2856,19 @@
 
 			printf("\n==== Resume restore\n");
 
-			SocketStreamTLS conn;
-			conn.Open(context, Socket::TypeINET, "localhost", 
-				BOX_PORT_BBSTORED);
-			BackupProtocolClient protocol(conn);
-			protocol.QueryVersion(BACKUP_STORE_SERVER_VERSION);
-			std::auto_ptr<BackupProtocolClientLoginConfirmed> 
-				loginConf(protocol.QueryLogin(0x01234567, 
-				0 /* read-write */));
+			std::auto_ptr<BackupProtocolClient> client = Connect(
+				context,
+				BackupProtocolClientLogin::Flags_ReadOnly);
 
 			// Check that the restore fn returns resume possible,
 			// rather than doing anything
-			TEST_THAT(BackupClientRestore(protocol, restoredirid, 
+			TEST_THAT(BackupClientRestore(*client, restoredirid, 
 				"testfiles/restore-interrupt", 
 				true /* print progress dots */) 
 				== Restore_ResumePossible);
 
 			// Then resume it
-			TEST_THAT(BackupClientRestore(protocol, restoredirid, 
+			TEST_THAT(BackupClientRestore(*client, restoredirid, 
 				"testfiles/restore-interrupt", 
 				true /* print progress dots */, 
 				false /* deleted files */, 
@@ -2902,7 +2876,8 @@
 				true /* resume */) 
 				== Restore_Complete);
 
-			protocol.QueryFinished();
+			client->QueryFinished();
+			sSocket.Close();
 
 			// Then check it has restored the correct stuff
 			compareReturnValue = ::system(BBACKUPQUERY " -q "
@@ -2923,24 +2898,19 @@
 		printf("\n==== Check restore deleted files\n");
 
 		{
-			SocketStreamTLS conn;
-			conn.Open(context, Socket::TypeINET, "localhost", 
-				BOX_PORT_BBSTORED);
-			BackupProtocolClient protocol(conn);
-			protocol.QueryVersion(BACKUP_STORE_SERVER_VERSION);
-			std::auto_ptr<BackupProtocolClientLoginConfirmed> 
-				loginConf(protocol.QueryLogin(0x01234567, 
-				0 /* read-write */));
+			std::auto_ptr<BackupProtocolClient> client = Connect(
+				context, 0 /* read-write */);
 
 			// Do restore and undelete
-			TEST_THAT(BackupClientRestore(protocol, deldirid, 
+			TEST_THAT(BackupClientRestore(*client, deldirid, 
 				"testfiles/restore-Test1-x1-2", 
 				true /* print progress dots */, 
 				true /* deleted files */, 
 				true /* undelete on server */) 
 				== Restore_Complete);
 
-			protocol.QueryFinished();
+			client->QueryFinished();
+			sSocket.Close();
 
 			// Do a compare with the now undeleted files
 			compareReturnValue = ::system(BBACKUPQUERY " -q "

Copied: box/chris/general/test/bbackupd/testfiles/bbackupd-temploc.conf (from rev 1867, box/trunk/test/bbackupd/testfiles/bbackupd-temploc.conf)
===================================================================
--- box/chris/general/test/bbackupd/testfiles/bbackupd-temploc.conf	                        (rev 0)
+++ box/chris/general/test/bbackupd/testfiles/bbackupd-temploc.conf	2007-12-09 01:44:44 UTC (rev 1987)
@@ -0,0 +1,54 @@
+
+CertificateFile = testfiles/clientCerts.pem
+PrivateKeyFile = testfiles/clientPrivKey.pem
+TrustedCAsFile = testfiles/clientTrustedCAs.pem
+
+KeysFile = testfiles/bbackupd.keys
+
+DataDirectory = testfiles/bbackupd-data
+
+StoreHostname = localhost
+AccountNumber = 0x01234567
+
+UpdateStoreInterval = 3
+MinimumFileAge = 4
+MaxUploadWait = 24
+
+FileTrackingSizeThreshold = 1024
+DiffingUploadSizeThreshold = 1024
+
+MaximumDiffingTime = 3
+KeepAliveTime = 1
+
+ExtendedLogging = no
+ExtendedLogFile = testfiles/bbackupd.log
+
+CommandSocket = testfiles/bbackupd.sock
+
+Server
+{
+	PidFile = testfiles/bbackupd.pid
+}
+
+BackupLocations
+{
+	Test1
+	{
+		Path = testfiles/TestDir1
+
+		ExcludeFile = testfiles/TestDir1/excluded_1
+		ExcludeFile = testfiles/TestDir1/excluded_2
+		ExcludeFilesRegex = \.excludethis$
+		ExcludeFilesRegex = EXCLUDE
+		AlwaysIncludeFile = testfiles/TestDir1/dont.excludethis
+		ExcludeDir = testfiles/TestDir1/exclude_dir
+		ExcludeDir = testfiles/TestDir1/exclude_dir_2
+		ExcludeDirsRegex = not_this_dir
+		AlwaysIncludeDirsRegex = ALWAYSINCLUDE
+	}
+	Test2
+	{
+		Path = testfiles/TestDir1
+	}
+}
+

Modified: box/chris/general/test/bbackupd/testfiles/bbackupd.conf.in
===================================================================
--- box/chris/general/test/bbackupd/testfiles/bbackupd.conf.in	2007-12-09 01:39:11 UTC (rev 1986)
+++ box/chris/general/test/bbackupd/testfiles/bbackupd.conf.in	2007-12-09 01:44:44 UTC (rev 1987)
@@ -13,6 +13,7 @@
 UpdateStoreInterval = 3
 MinimumFileAge = 4
 MaxUploadWait = 24
+DeleteRedundantLocationsAfter = 10
 
 FileTrackingSizeThreshold = 1024
 DiffingUploadSizeThreshold = 1024


From boxbackup-dev@fluffy.co.uk  Sun Dec  9 01:47:48 2007
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Sun,  9 Dec 2007 01:47:48 +0000 (UTC)
Subject: [Box Backup-commit] COMMIT r1988 - box/chris/general
Message-ID: <20071209014748.20732325A0D@www.boxbackup.org>

Author: chris
Date: 2007-12-09 01:47:47 +0000 (Sun, 09 Dec 2007)
New Revision: 1988

Modified:
   box/chris/general/configure.ac
Log:
Check for zlib.h and fail if we don't have it.


Modified: box/chris/general/configure.ac
===================================================================
--- box/chris/general/configure.ac	2007-12-09 01:44:44 UTC (rev 1987)
+++ box/chris/general/configure.ac	2007-12-09 01:47:47 UTC (rev 1988)
@@ -58,6 +58,7 @@
 	;;
 esac
 
+AC_CHECK_HEADER([zlib.h],, [AC_MSG_ERROR([[cannot find zlib.h]])])
 AC_CHECK_LIB([z], [zlibVersion],, [AC_MSG_ERROR([[cannot find zlib]])])
 VL_LIB_READLINE([have_libreadline=yes], [have_libreadline=no])
 


From boxbackup-dev@fluffy.co.uk  Sun Dec  9 12:02:17 2007
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Sun,  9 Dec 2007 12:02:17 +0000 (UTC)
Subject: [Box Backup-commit] COMMIT r1989 - box/chris/general/bin/bbackupd
Message-ID: <20071209120217.F30FD325A0D@www.boxbackup.org>

Author: chris
Date: 2007-12-09 12:02:17 +0000 (Sun, 09 Dec 2007)
New Revision: 1989

Modified:
   box/chris/general/bin/bbackupd/BackupDaemon.cpp
Log:
Hopefully fix a bug reported by Tobias Balle-Petersen, where unused
locations on the store would never be deleted because the timer would be
reset on every backup pass (refs #3, merges [1726])


Modified: box/chris/general/bin/bbackupd/BackupDaemon.cpp
===================================================================
--- box/chris/general/bin/bbackupd/BackupDaemon.cpp	2007-12-09 01:47:47 UTC (rev 1988)
+++ box/chris/general/bin/bbackupd/BackupDaemon.cpp	2007-12-09 12:02:17 UTC (rev 1989)
@@ -1977,8 +1977,7 @@
 
 		BOX_NOTICE(dir.GetNumberOfEntries() << " redundant locations "
 			"in root directory found, will delete from store "
-			"after " << BACKUP_DELETE_UNUSED_ROOT_ENTRIES_AFTER 
-			<< " seconds.");
+			"after " << secs << " seconds.");
 
 		// Store directories in list of things to delete
 		mUnusedRootDirEntries.clear();
@@ -1989,14 +1988,13 @@
 			// Add name to list
 			BackupStoreFilenameClear clear(en->GetName());
 			const std::string &name(clear.GetClearFilename());
-			mUnusedRootDirEntries.push_back(std::pair<int64_t,std::string>(en->GetObjectID(), name));
+			mUnusedRootDirEntries.push_back(
+				std::pair<int64_t,std::string>
+				(en->GetObjectID(), name));
 			// Log this
 			BOX_INFO("Unused location in root: " << name);
 		}
 		ASSERT(mUnusedRootDirEntries.size() > 0);
-		// Time to delete them
-		mDeleteUnusedRootDirEntriesAfter =
-			GetCurrentBoxTime() + SecondsToBoxTime(BACKUP_DELETE_UNUSED_ROOT_ENTRIES_AFTER);
 	}
 }
 
@@ -2438,16 +2436,27 @@
 // --------------------------------------------------------------------------
 void BackupDaemon::DeleteUnusedRootDirEntries(BackupClientContext &rContext)
 {
-	if(mUnusedRootDirEntries.empty() || mDeleteUnusedRootDirEntriesAfter == 0)
+	if(mUnusedRootDirEntries.empty())
 	{
-		// Nothing to do.
+		BOX_INFO("Not deleting unused entries - none in list");
 		return;
 	}
 	
+	if(mDeleteUnusedRootDirEntriesAfter == 0)
+	{
+		BOX_INFO("Not deleting unused entries - "
+			"zero delete time (bad)");
+		return;
+	}
+
 	// Check time
-	if(GetCurrentBoxTime() < mDeleteUnusedRootDirEntriesAfter)
+	box_time_t now = GetCurrentBoxTime();
+	if(now < mDeleteUnusedRootDirEntriesAfter)
 	{
-		// Too early to delete files
+		int secs = BoxTimeToSeconds(mDeleteUnusedRootDirEntriesAfter
+			- now);
+		BOX_INFO("Not deleting unused entries - too early ("
+			<< secs << " seconds remaining)");
 		return;
 	}
 


From boxbackup-dev@fluffy.co.uk  Sun Dec  9 12:10:00 2007
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Sun,  9 Dec 2007 12:10:00 +0000 (UTC)
Subject: [Box Backup-commit] COMMIT r1990 - box/chris/general/lib/common
Message-ID: <20071209121000.58AD8325A0D@www.boxbackup.org>

Author: chris
Date: 2007-12-09 12:10:00 +0000 (Sun, 09 Dec 2007)
New Revision: 1990

Modified:
   box/chris/general/lib/common/Logging.cpp
Log:
Flush console after each log message.


Modified: box/chris/general/lib/common/Logging.cpp
===================================================================
--- box/chris/general/lib/common/Logging.cpp	2007-12-09 12:02:17 UTC (rev 1989)
+++ box/chris/general/lib/common/Logging.cpp	2007-12-09 12:10:00 UTC (rev 1990)
@@ -264,6 +264,7 @@
 	msg += rMessage;
 
 	fprintf(target, "%s\n", msg.c_str());
+	fflush(target);
 	
 	return true;
 }


From boxbackup-dev@fluffy.co.uk  Sun Dec  9 12:10:37 2007
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Sun,  9 Dec 2007 12:10:37 +0000 (UTC)
Subject: [Box Backup-commit] COMMIT r1991 - box/chris/general/bin/bbackupd
Message-ID: <20071209121037.57A5E326969@www.boxbackup.org>

Author: chris
Date: 2007-12-09 12:10:37 +0000 (Sun, 09 Dec 2007)
New Revision: 1991

Modified:
   box/chris/general/bin/bbackupd/BackupDaemon.cpp
Log:
Compile fix (remove old reference to ploc, replaced with auto ptr).


Modified: box/chris/general/bin/bbackupd/BackupDaemon.cpp
===================================================================
--- box/chris/general/bin/bbackupd/BackupDaemon.cpp	2007-12-09 12:10:00 UTC (rev 1990)
+++ box/chris/general/bin/bbackupd/BackupDaemon.cpp	2007-12-09 12:10:37 UTC (rev 1991)
@@ -1941,8 +1941,6 @@
 				<< apLoc->mName << "' path '"
 				<< apLoc->mPath << "': " << e.what() <<
 				": please check for previous errors");
-			delete ploc;
-			ploc = 0;
 			throw;
 		}
 		catch(...)


From boxbackup-dev@fluffy.co.uk  Sun Dec  9 12:11:13 2007
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Sun,  9 Dec 2007 12:11:13 +0000 (UTC)
Subject: [Box Backup-commit] COMMIT r1992 - box/chris/general/infrastructure/msvc
Message-ID: <20071209121113.EF10F325A0D@www.boxbackup.org>

Author: chris
Date: 2007-12-09 12:11:13 +0000 (Sun, 09 Dec 2007)
New Revision: 1992

Modified:
   box/chris/general/infrastructure/msvc/getversion.pl
Log:
Don't replace BoxVersion.h if it hasn't changed, saves rebuilding
everything.


Modified: box/chris/general/infrastructure/msvc/getversion.pl
===================================================================
--- box/chris/general/infrastructure/msvc/getversion.pl	2007-12-09 12:10:37 UTC (rev 1991)
+++ box/chris/general/infrastructure/msvc/getversion.pl	2007-12-09 12:11:13 UTC (rev 1992)
@@ -11,6 +11,20 @@
 
 require "$basedir\\infrastructure\\BoxPlatform.pm.in";
 
+my $version_string = "#define BOX_VERSION \"$BoxPlatform::product_version\"\n";
+
+open VERSIONFILE, "< $basedir/lib/common/BoxVersion.h";
+my $old_version = <VERSIONFILE>;
+close VERSIONFILE;
+
+if ($old_version eq $version_string)
+{
+	print "Version unchanged.\n";
+	exit 0;
+}
+
+print "New version: $BoxPlatform::product_version\n";
+
 open VERSIONFILE, "> $basedir/lib/common/BoxVersion.h" 
 	or die "BoxVersion.h: $!";
 print VERSIONFILE "#define BOX_VERSION \"$BoxPlatform::product_version\"\n";


From boxbackup-dev@fluffy.co.uk  Thu Dec 13 00:19:42 2007
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Thu, 13 Dec 2007 00:19:42 +0000 (UTC)
Subject: [Box Backup-commit] COMMIT r1994 - box/trunk/test/bbackupd
Message-ID: <20071213001942.8300532696D@www.boxbackup.org>

Author: chris
Date: 2007-12-13 00:19:42 +0000 (Thu, 13 Dec 2007)
New Revision: 1994

Modified:
   box/trunk/test/bbackupd/testbbackupd.cpp
Log:
Move comment, add whitespace.


Modified: box/trunk/test/bbackupd/testbbackupd.cpp
===================================================================
--- box/trunk/test/bbackupd/testbbackupd.cpp	2007-12-13 00:18:45 UTC (rev 1993)
+++ box/trunk/test/bbackupd/testbbackupd.cpp	2007-12-13 00:19:42 UTC (rev 1994)
@@ -752,8 +752,8 @@
 #ifndef PLATFORM_CLIB_FNS_INTERCEPTION_IMPOSSIBLE
 		intercept_setup_readdir_hook(NULL, NULL);
 		intercept_setup_lstat_hook  (NULL, NULL);
+		// we will not be called again.
 #endif
-		// we will not be called again.
 	}
 
 	// fill in the struct dirent appropriately
@@ -772,6 +772,7 @@
 	snprintf(stat_hook_filename, sizeof(stat_hook_filename),
 		"testfiles/TestDir1/spacetest/d1/test.%d", 
 		readdir_test_counter);
+
 #ifndef PLATFORM_CLIB_FNS_INTERCEPTION_IMPOSSIBLE
 	intercept_setup_lstat_hook(stat_hook_filename, lstat_test_hook);
 #endif


From boxbackup-dev@fluffy.co.uk  Thu Dec 13 00:18:46 2007
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Thu, 13 Dec 2007 00:18:46 +0000 (UTC)
Subject: [Box Backup-commit] COMMIT r1993 - box/trunk
Message-ID: <20071213001846.A3BFA325A0D@www.boxbackup.org>

Author: chris
Date: 2007-12-13 00:18:45 +0000 (Thu, 13 Dec 2007)
New Revision: 1993

Modified:
   box/trunk/configure.ac
Log:
Include the header file where dirfd() is supposed to be defined,
otherwise we can expect not to find it and cause problems later
with our own definition.


Modified: box/trunk/configure.ac
===================================================================
--- box/trunk/configure.ac	2007-12-09 12:11:13 UTC (rev 1992)
+++ box/trunk/configure.ac	2007-12-13 00:18:45 UTC (rev 1993)
@@ -168,7 +168,10 @@
 AC_CHECK_DECL([dirfd],
 	[],
 	AC_DEFINE([dirfd(x)], [(x)->d_fd], [dirfd() replacement for Solaris]),
-	[#include <getopt.h>])
+	[
+		#include <getopt.h>
+		#include <dirent.h>
+	])
 
 AC_HEADER_TIME
 AC_STRUCT_TM


From boxbackup-dev@fluffy.co.uk  Thu Dec 13 00:21:38 2007
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Thu, 13 Dec 2007 00:21:38 +0000 (UTC)
Subject: [Box Backup-commit] COMMIT r1995 - box/trunk/lib/intercept
Message-ID: <20071213002138.9F829326972@www.boxbackup.org>

Author: chris
Date: 2007-12-13 00:21:38 +0000 (Thu, 13 Dec 2007)
New Revision: 1995

Modified:
   box/trunk/lib/intercept/intercept.cpp
Log:
Restructure intercept_errornow() for clarity.

Move delay code out of macro and into intercept_errornow() to
simplify macro.

Clear hook functions in intercept_clear_setup().

Check that intercept_filename is not NULL before comparing it with
anything.

Change some TRACEx macros to BOX_TRACE.


Modified: box/trunk/lib/intercept/intercept.cpp
===================================================================
--- box/trunk/lib/intercept/intercept.cpp	2007-12-13 00:19:42 UTC (rev 1994)
+++ box/trunk/lib/intercept/intercept.cpp	2007-12-13 00:21:38 UTC (rev 1995)
@@ -74,6 +74,14 @@
 off_t intercept_filepos = 0;
 int intercept_delay_ms = 0;
 
+static opendir_t*  opendir_real  = NULL;
+static readdir_t*  readdir_real  = NULL;
+static readdir_t*  readdir_hook  = NULL;
+static closedir_t* closedir_real = NULL;
+static lstat_t*    lstat_real    = NULL;
+static lstat_t*    lstat_hook    = NULL;
+static const char* lstat_file    = NULL;
+
 #define SIZE_ALWAYS_ERROR	-773
 
 void intercept_clear_setup()
@@ -85,6 +93,8 @@
 	intercept_syscall = 0;
 	intercept_filepos = 0;
 	intercept_delay_ms = 0;
+	readdir_hook = NULL;
+	lstat_hook = NULL;
 }
 
 bool intercept_triggered()
@@ -94,7 +104,11 @@
 
 void intercept_setup_error(const char *filename, unsigned int errorafter, int errortoreturn, int syscalltoerror)
 {
-	TRACE4("Setup for error: %s, after %d, err %d, syscall %d\n", filename, errorafter, errortoreturn, syscalltoerror);
+	BOX_TRACE("Setup for error: " << filename << 
+		", after " << errorafter <<
+		", err " << errortoreturn <<
+		", syscall " << syscalltoerror);
+
 	intercept_count = 1;
 	intercept_filename = filename;
 	intercept_filedes = -1;
@@ -108,9 +122,12 @@
 void intercept_setup_delay(const char *filename, unsigned int delay_after, 
 	int delay_ms, int syscall_to_delay, int num_delays)
 {
-	TRACE5("Setup for delay: %s, after %d, wait %d ms, times %d, "
-		"syscall %d\n", filename, delay_after, delay_ms, 
-		num_delays, syscall_to_delay);
+	BOX_TRACE("Setup for delay: " << filename <<
+		", after " << delay_after <<
+		", wait " << delay_ms << " ms" <<
+		", times " << num_delays <<
+		", syscall " << syscall_to_delay);
+
 	intercept_count = num_delays;
 	intercept_filename = filename;
 	intercept_filedes = -1;
@@ -120,37 +137,69 @@
 	intercept_filepos = 0;
 	intercept_delay_ms = delay_ms;
 }
+
 bool intercept_errornow(int d, int size, int syscallnum)
 {
-	if(intercept_filedes != -1 && d == intercept_filedes && syscallnum == intercept_syscall)
+	ASSERT(intercept_count > 0)
+
+	if (intercept_filedes == -1)
 	{
-		//printf("Checking for err, %d, %d, %d\n", d, size, syscallnum);
-		if(size == SIZE_ALWAYS_ERROR)
-		{
-			// Looks good for an error!
-			TRACE2("Returning error %d for syscall %d\n", intercept_errno, syscallnum);
-			return true;
-		}
-		// where are we in the file?
-		if(intercept_filepos >= intercept_errorafter || intercept_filepos >= ((off_t)intercept_errorafter - size))
-		{
-			if (intercept_errno != 0)
-			{
-				TRACE3("Returning error %d for syscall %d, "
-					"file pos %d\n", intercept_errno, 
-					syscallnum, (int)intercept_filepos);
-			}
-			else if (intercept_delay_ms != 0)
-			{
-				TRACE3("Delaying %d ms for syscall %d, "
-					"file pos %d\n", intercept_delay_ms, 
-					syscallnum, (int)intercept_filepos);
-			}
+		return false; // no error please!
+	}
 
-			return true;
-		}
+	if (d != intercept_filedes)
+	{
+		return false; // no error please!
 	}
-	return false;	// no error please!
+
+	if (syscallnum != intercept_syscall)
+	{
+		return false; // no error please!
+	}
+
+	bool ret = false; // no error unless one of the conditions matches
+
+	//printf("Checking for err, %d, %d, %d\n", d, size, syscallnum);
+
+	if (intercept_delay_ms != 0)
+	{
+		BOX_TRACE("Delaying " << intercept_delay_ms << " ms " <<
+			" for syscall " << syscallnum << 
+			" at " << intercept_filepos);
+
+		struct timespec tm;
+		tm.tv_sec = intercept_delay_ms / 1000;
+		tm.tv_nsec = (intercept_delay_ms % 1000) * 1000000;
+		while (nanosleep(&tm, &tm) != 0 &&
+			errno == EINTR) { }
+	}
+
+	if (size == SIZE_ALWAYS_ERROR)
+	{
+		// Looks good for an error!
+		BOX_TRACE("Returning error " << intercept_errno <<
+			" for syscall " << syscallnum);
+		ret = true;
+	}
+	else if (intercept_filepos + size < intercept_errorafter)
+	{
+		return false; // no error please
+	}
+	else if (intercept_errno != 0)
+	{
+		BOX_TRACE("Returning error " << intercept_errno << 
+			" for syscall " << syscallnum <<
+			" at " << intercept_filepos);
+		ret = true;
+	}
+
+	intercept_count--;
+	if (intercept_count == 0)
+	{
+		intercept_clear_setup();
+	}
+
+	return ret;
 }
 
 int intercept_reterr()
@@ -160,31 +209,14 @@
 	return err;
 }
 
-#define CHECK_FOR_FAKE_ERROR_COND(D, S, CALL, FAILRES)	\
+#define CHECK_FOR_FAKE_ERROR_COND(D, S, CALL, FAILRES) \
 	if(intercept_count > 0) \
-	{										\
-		if(intercept_errornow(D, S, CALL))	\
-		{									\
-			if(intercept_delay_ms > 0) \
-			{ \
-				struct timespec tm; \
-				tm.tv_sec = intercept_delay_ms / 1000; \
-				tm.tv_nsec = (intercept_delay_ms % 1000) \
-					* 1000000; \
-				while (nanosleep(&tm, &tm) != 0 && \
-					errno == EINTR) { } \
-				intercept_count --; \
-				if (intercept_count == 0) \
-				{ \
-					intercept_clear_setup(); \
-				} \
-			} \
-			else \
-			{ \
-				errno = intercept_reterr();		\
-				return FAILRES;					\
-			} \
-		}									\
+	{ \
+		if(intercept_errornow(D, S, CALL)) \
+		{ \
+			errno = intercept_reterr(); \
+			return FAILRES; \
+		} \
 	}
 
 extern "C" int
@@ -192,18 +224,24 @@
 {
 	if(intercept_count > 0)
 	{
-		if(intercept_syscall == SYS_open && strcmp(path, intercept_filename) == 0)
+		if(intercept_filename != NULL &&
+			intercept_syscall == SYS_open &&
+			strcmp(path, intercept_filename) == 0)
 		{
 			errno = intercept_reterr();
 			return -1;
 		}
 	}
+
 #ifdef PLATFORM_NO_SYSCALL
 	int r = TEST_open(path, flags, mode);
 #else
 	int r = syscall(SYS_open, path, flags, mode);
 #endif
-	if(intercept_count > 0 && intercept_filedes == -1)
+
+	if(intercept_filename != NULL && 
+		intercept_count > 0 && 
+		intercept_filedes == -1)
 	{
 		// Right file?
 		if(strcmp(intercept_filename, path) == 0)
@@ -212,6 +250,7 @@
 			//printf("Found file to intercept, h = %d\n", r);
 		}
 	}
+
 	return r;
 }
 
@@ -323,26 +362,19 @@
 	return r;
 }
 
-static opendir_t*  opendir_real  = NULL;
-static readdir_t*  readdir_real  = NULL;
-static readdir_t*  readdir_hook  = NULL;
-static closedir_t* closedir_real = NULL;
-static lstat_t*    lstat_real    = NULL;
-static lstat_t*    lstat_hook    = NULL;
-static const char* lstat_file    = NULL;
-
 void intercept_setup_readdir_hook(const char *dirname, readdir_t hookfn)
 {
 	if (hookfn != NULL && dirname == NULL)
 	{
 		dirname = intercept_filename;
+		ASSERT(dirname != NULL);
 	}
 
 	if (hookfn != NULL)
 	{
 		TRACE2("readdir hooked to %p for %s\n", hookfn, dirname);
 	}
-	else
+	else if (intercept_filename != NULL)
 	{
 		TRACE2("readdir unhooked from %p for %s\n", readdir_hook, 
 			intercept_filename);
@@ -386,7 +418,9 @@
 
 	DIR* r = opendir_real(dirname);
 
-	if(readdir_hook != NULL && intercept_filedes == -1 && 
+	if (readdir_hook != NULL && 
+		intercept_filename != NULL && 
+		intercept_filedes == -1 && 
 		strcmp(intercept_filename, dirname) == 0)
 	{
 		intercept_filedes = dirfd(r);


From boxbackup-dev@fluffy.co.uk  Fri Dec 14 23:38:33 2007
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Fri, 14 Dec 2007 23:38:33 +0000 (UTC)
Subject: [Box Backup-commit] COMMIT r1996 - box/chris/general/test/backupstorefix
Message-ID: <20071214233833.3081C325A0D@www.boxbackup.org>

Author: chris
Date: 2007-12-14 23:38:29 +0000 (Fri, 14 Dec 2007)
New Revision: 1996

Modified:
   box/chris/general/test/backupstorefix/testbackupstorefix.cpp
Log:
Compile fix.


Modified: box/chris/general/test/backupstorefix/testbackupstorefix.cpp
===================================================================
--- box/chris/general/test/backupstorefix/testbackupstorefix.cpp	2007-12-13 00:21:38 UTC (rev 1995)
+++ box/chris/general/test/backupstorefix/testbackupstorefix.cpp	2007-12-14 23:38:29 UTC (rev 1996)
@@ -310,7 +310,7 @@
 		TEST_THAT_ABORTONFAIL(::system(PERL_EXECUTABLE 
 			" testfiles/testbackupstorefix.pl init") == 0);
 
-		std::string cmd = BBACKUPD + " " + bbackupd_args +
+		std::string cmd = BBACKUPD " " + bbackupd_args +
 			" testfiles/bbackupd.conf";
 		int bbackupd_pid = LaunchServer(cmd, "testfiles/bbackupd.pid");
 		TEST_THAT(bbackupd_pid != -1 && bbackupd_pid != 0);


From boxbackup-dev@fluffy.co.uk  Sat Dec 15 00:09:27 2007
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Sat, 15 Dec 2007 00:09:27 +0000 (UTC)
Subject: [Box Backup-commit] COMMIT r1997 - box/chris/general
Message-ID: <20071215000927.94199325A0D@www.boxbackup.org>

Author: chris
Date: 2007-12-15 00:09:27 +0000 (Sat, 15 Dec 2007)
New Revision: 1997

Modified:
   box/chris/general/configure.ac
Log:
PCRE 7.x requires us to #define PCRE_STATIC to get the right symbol
names.


Modified: box/chris/general/configure.ac
===================================================================
--- box/chris/general/configure.ac	2007-12-14 23:38:29 UTC (rev 1996)
+++ box/chris/general/configure.ac	2007-12-15 00:09:27 UTC (rev 1997)
@@ -123,6 +123,7 @@
 fi
 
 if test "$have_pcreposix_h" = "yes"; then
+  AC_DEFINE([PCRE_STATIC], [1], [Box Backup always uses static PCRE])
   AC_SEARCH_LIBS([regcomp], ["pcreposix -lpcre"],,[have_pcreposix_h=no_regcomp])
 fi
 


From boxbackup-dev@fluffy.co.uk  Sat Dec 15 17:02:58 2007
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Sat, 15 Dec 2007 17:02:58 +0000 (UTC)
Subject: [Box Backup-commit] COMMIT r1998 - in box/trunk: . lib/common
Message-ID: <20071215170258.3D70E326997@www.boxbackup.org>

Author: chris
Date: 2007-12-15 17:02:55 +0000 (Sat, 15 Dec 2007)
New Revision: 1998

Modified:
   box/trunk/configure.ac
   box/trunk/lib/common/BoxPlatform.h
Log:
Fix definition of dirfd(x) macro (autoconf doesn't like defining macros
with parameters).


Modified: box/trunk/configure.ac
===================================================================
--- box/trunk/configure.ac	2007-12-15 00:09:27 UTC (rev 1997)
+++ box/trunk/configure.ac	2007-12-15 17:02:55 UTC (rev 1998)
@@ -165,13 +165,11 @@
 AC_CHECK_DECLS([O_BINARY],,,)
 
 AC_CHECK_DECLS([optreset],,, [[#include <getopt.h>]])
-AC_CHECK_DECL([dirfd],
-	[],
-	AC_DEFINE([dirfd(x)], [(x)->d_fd], [dirfd() replacement for Solaris]),
-	[
+AC_CHECK_DECLS([dirfd],,,
+	[[
 		#include <getopt.h>
 		#include <dirent.h>
-	])
+	]])
 
 AC_HEADER_TIME
 AC_STRUCT_TM

Modified: box/trunk/lib/common/BoxPlatform.h
===================================================================
--- box/trunk/lib/common/BoxPlatform.h	2007-12-15 00:09:27 UTC (rev 1997)
+++ box/trunk/lib/common/BoxPlatform.h	2007-12-15 17:02:55 UTC (rev 1998)
@@ -165,4 +165,12 @@
 	#include "emu.h"
 #endif
 
+// Solaris has no dirfd(x) macro or function, and we need one.
+// We cannot define macros with arguments directly using AC_DEFINE,
+// so do it here instead of in configure.ac.
+
+#ifndef HAVE_DECL_DIRFD
+	#define dirfd(x) (x)->d_fd
+#endif
+
 #endif // BOXPLATFORM__H


From boxbackup-dev@fluffy.co.uk  Sat Dec 15 17:03:41 2007
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Sat, 15 Dec 2007 17:03:41 +0000 (UTC)
Subject: [Box Backup-commit] COMMIT r1999 - box/trunk/lib/server
Message-ID: <20071215170341.60578326997@www.boxbackup.org>

Author: chris
Date: 2007-12-15 17:03:41 +0000 (Sat, 15 Dec 2007)
New Revision: 1999

Modified:
   box/trunk/lib/server/ServerControl.h
Log:
Report reason why killing a process failed.


Modified: box/trunk/lib/server/ServerControl.h
===================================================================
--- box/trunk/lib/server/ServerControl.h	2007-12-15 17:02:55 UTC (rev 1998)
+++ box/trunk/lib/server/ServerControl.h	2007-12-15 17:03:41 UTC (rev 1999)
@@ -140,6 +140,11 @@
 {
 	if(pid == 0 || pid == -1) return false;
 	bool killed = (::kill(pid, SIGTERM) == 0);
+	if (!killed)
+	{
+		BOX_ERROR("Failed to kill process " << pid << ": " <<
+			strerror(errno));
+	}
 	TEST_THAT(killed);
 	return killed;
 }


From boxbackup-dev@fluffy.co.uk  Sat Dec 15 17:04:24 2007
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Sat, 15 Dec 2007 17:04:24 +0000 (UTC)
Subject: [Box Backup-commit] COMMIT r2000 - box/trunk/test/bbackupd
Message-ID: <20071215170424.B7BB0326997@www.boxbackup.org>

Author: chris
Date: 2007-12-15 17:04:24 +0000 (Sat, 15 Dec 2007)
New Revision: 2000

Modified:
   box/trunk/test/bbackupd/testbbackupd.cpp
Log:
Report line of test where failed to kill internal daemon during SSL
keepalive tests.


Modified: box/trunk/test/bbackupd/testbbackupd.cpp
===================================================================
--- box/trunk/test/bbackupd/testbbackupd.cpp	2007-12-15 17:03:41 UTC (rev 1999)
+++ box/trunk/test/bbackupd/testbbackupd.cpp	2007-12-15 17:04:24 UTC (rev 2000)
@@ -701,9 +701,11 @@
 	return pid;
 }
 
-void stop_internal_daemon(int pid)
+bool stop_internal_daemon(int pid)
 {
-	TEST_THAT(KillServer(pid));
+	bool killed_server = KillServer(pid);
+	TEST_THAT(killed_server);
+	return killed_server;
 
 	/*
 	int status;
@@ -844,7 +846,7 @@
 		
 		int pid = start_internal_daemon();
 		wait_for_backup_operation();
-		stop_internal_daemon(pid);
+		TEST_THAT(stop_internal_daemon(pid));
 
 		// two-second delay on the first read() of f1
 		// should mean that a single keepalive is sent,
@@ -865,7 +867,7 @@
 		// can't test whether intercept was triggered, because
 		// it's in a different process.
 		// TEST_THAT(intercept_triggered());
-		stop_internal_daemon(pid);
+		TEST_THAT(stop_internal_daemon(pid));
 
 		// check that keepalive was written to logs, and
 		// diff was not aborted, i.e. upload was a diff
@@ -935,7 +937,7 @@
 		// can't test whether intercept was triggered, because
 		// it's in a different process.
 		// TEST_THAT(intercept_triggered());
-		stop_internal_daemon(pid);
+		TEST_THAT(stop_internal_daemon(pid));
 
 		// check that the diff was aborted, i.e. upload was not a diff
 		found1 = false;
@@ -995,7 +997,7 @@
 		// can't test whether intercept was triggered, because
 		// it's in a different process.
 		// TEST_THAT(intercept_triggered());
-		stop_internal_daemon(pid);
+		TEST_THAT(stop_internal_daemon(pid));
 
 		// check that the diff was aborted, i.e. upload was not a diff
 		found1 = false;
@@ -1079,7 +1081,7 @@
 		// can't test whether intercept was triggered, because
 		// it's in a different process.
 		// TEST_THAT(intercept_triggered());
-		stop_internal_daemon(pid);
+		TEST_THAT(stop_internal_daemon(pid));
 
 		// check that keepalives were sent during the dir search
 		found1 = false;


From boxbackup-dev@fluffy.co.uk  Sat Dec 15 20:03:50 2007
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Sat, 15 Dec 2007 20:03:50 +0000 (UTC)
Subject: [Box Backup-commit] COMMIT r2001 - box/trunk/lib/common
Message-ID: <20071215200350.DE1F6326997@www.boxbackup.org>

Author: chris
Date: 2007-12-15 20:03:50 +0000 (Sat, 15 Dec 2007)
New Revision: 2001

Modified:
   box/trunk/lib/common/Logging.cpp
   box/trunk/lib/common/Logging.h
Log:
Allow logging with microsecond timestamps.


Modified: box/trunk/lib/common/Logging.cpp
===================================================================
--- box/trunk/lib/common/Logging.cpp	2007-12-15 17:04:24 UTC (rev 2000)
+++ box/trunk/lib/common/Logging.cpp	2007-12-15 20:03:50 UTC (rev 2001)
@@ -20,6 +20,8 @@
 
 #include <iomanip>
 
+#include "BoxTime.h"
+
 bool Logging::sLogToSyslog  = false;
 bool Logging::sLogToConsole = false;
 bool Logging::sContextSet   = false;
@@ -178,7 +180,8 @@
 }
 
 bool Console::sShowTime = false;
-bool Console::sShowTag  = false;
+bool Console::sShowTimeMicros = false;
+bool Console::sShowTag = false;
 std::string Console::sTag;
 
 void Console::SetTag(const std::string& rTag)
@@ -192,6 +195,11 @@
 	sShowTime = enabled;
 }
 
+void Console::SetShowTimeMicros(bool enabled)
+{
+	sShowTimeMicros = enabled;
+}
+
 bool Console::Log(Log::Level level, const std::string& rFile, 
 	int line, std::string& rMessage)
 {
@@ -211,25 +219,31 @@
 
 	if (sShowTime)
 	{
-		struct tm time_now, *tm_ptr = &time_now;
-		time_t time_t_now = time(NULL);
+		box_time_t time_now = GetCurrentBoxTime();
+		time_t seconds = BoxTimeToSeconds(time_now);
+		int micros = BoxTimeToMicroSeconds(time_now) % MICRO_SEC_IN_SEC;
 
-		if (time_t_now == ((time_t)-1))
-		{
-			msg += strerror(errno);
-			msg += " ";
-		}
+		struct tm tm_now, *tm_ptr = &tm_now;
+
 		#ifdef WIN32
-			else if ((tm_ptr = localtime(&time_t_now)) != NULL)
+			if ((tm_ptr = localtime(&seconds)) != NULL)
 		#else
-			else if (localtime_r(&time_t_now, &time_now) != NULL)
+			if (localtime_r(&seconds, &tm_now) != NULL)
 		#endif
 		{
 			std::ostringstream buf;
+
 			buf << std::setfill('0') <<
 				std::setw(2) << tm_ptr->tm_hour << ":" << 
 				std::setw(2) << tm_ptr->tm_min  << ":" <<
-				std::setw(2) << tm_ptr->tm_sec  << " ";
+				std::setw(2) << tm_ptr->tm_sec;
+
+			if (sShowTimeMicros)
+			{
+				buf << "." << std::setw(6) << micros;
+			}
+
+			buf << " ";
 			msg += buf.str();
 		}
 		else

Modified: box/trunk/lib/common/Logging.h
===================================================================
--- box/trunk/lib/common/Logging.h	2007-12-15 17:04:24 UTC (rev 2000)
+++ box/trunk/lib/common/Logging.h	2007-12-15 20:03:50 UTC (rev 2001)
@@ -118,6 +118,7 @@
 {
 	private:
 	static bool sShowTime;
+	static bool sShowTimeMicros;
 	static bool sShowTag;
 	static std::string sTag;
 
@@ -129,6 +130,7 @@
 
 	static void SetTag(const std::string& rTag);
 	static void SetShowTime(bool enabled);
+	static void SetShowTimeMicros(bool enabled);
 };
 
 // --------------------------------------------------------------------------


From boxbackup-dev@fluffy.co.uk  Sat Dec 15 20:04:15 2007
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Sat, 15 Dec 2007 20:04:15 +0000 (UTC)
Subject: [Box Backup-commit] COMMIT r2002 - box/trunk/infrastructure
Message-ID: <20071215200415.9C3C9326997@www.boxbackup.org>

Author: chris
Date: 2007-12-15 20:04:15 +0000 (Sat, 15 Dec 2007)
New Revision: 2002

Modified:
   box/trunk/infrastructure/buildenv-testmain-template.cpp
Log:
Add -U option to enable logging microsecond timestamps


Modified: box/trunk/infrastructure/buildenv-testmain-template.cpp
===================================================================
--- box/trunk/infrastructure/buildenv-testmain-template.cpp	2007-12-15 20:03:50 UTC (rev 2001)
+++ box/trunk/infrastructure/buildenv-testmain-template.cpp	2007-12-15 20:04:15 UTC (rev 2002)
@@ -169,7 +169,7 @@
 	
 	int ch;
 	
-	while ((ch = getopt_long(argc, argv, "c:s:t:T", longopts, NULL))
+	while ((ch = getopt_long(argc, argv, "c:s:t:TU", longopts, NULL))
 		!= -1)
 	{
 		switch(ch)
@@ -203,6 +203,13 @@
 			}
 			break;
 
+			case 'U':
+			{
+				Console::SetShowTime(true);
+				Console::SetShowTimeMicros(true);
+			}
+			break;
+
 			case '?':
 			{
 				fprintf(stderr, "Unknown option: %s\n",


From boxbackup-dev@fluffy.co.uk  Sat Dec 15 20:04:56 2007
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Sat, 15 Dec 2007 20:04:56 +0000 (UTC)
Subject: [Box Backup-commit] COMMIT r2003 - box/trunk/lib/common
Message-ID: <20071215200456.4503F326997@www.boxbackup.org>

Author: chris
Date: 2007-12-15 20:04:56 +0000 (Sat, 15 Dec 2007)
New Revision: 2003

Modified:
   box/trunk/lib/common/Timer.cpp
Log:
Don't log our own timestamp now that Logging can do it for us with
microsecond precision.


Modified: box/trunk/lib/common/Timer.cpp
===================================================================
--- box/trunk/lib/common/Timer.cpp	2007-12-15 20:04:15 UTC (rev 2002)
+++ box/trunk/lib/common/Timer.cpp	2007-12-15 20:04:56 UTC (rev 2003)
@@ -149,10 +149,6 @@
 	Reschedule();
 }
 
-#define FORMAT_BOX_TIME(t) \
-	(BoxTimeToSeconds(t)) << "." << \
-	(BoxTimeToMicroSeconds(t) % MICRO_SEC_IN_SEC)
-
 #define FORMAT_MICROSECONDS(t) \
 	(int)(t / 1000000) << "." << \
 	(int)(t % 1000000)
@@ -185,8 +181,10 @@
 
 		if (oldact.sa_handler != Timers::SignalHandler)
 		{
-			printf("Signal handler was %p, expected %p\n", 
-				oldact.sa_handler, Timers::SignalHandler);
+			BOX_ERROR("Signal handler was " <<
+				(void *)oldact.sa_handler << 
+				", expected " <<
+				(void *)Timers::SignalHandler);
 			THROW_EXCEPTION(CommonException, Internal)
 		}
 	#endif
@@ -214,8 +212,7 @@
 		
 			if (timeToExpiry <= 0)
 			{
-				BOX_TRACE(FORMAT_MICROSECONDS(timeNow) <<
-					": timer " << *i << " has expired, "
+				BOX_TRACE("timer " << *i << " has expired, "
 					"triggering it");
 				rTimer.OnExpire();
 				spTimers->erase(i);
@@ -224,8 +221,7 @@
 			}
 			else
 			{
-				BOX_TRACE(FORMAT_MICROSECONDS(timeNow) <<
-					": timer " << *i << " has not "
+				BOX_TRACE("timer " << *i << " has not "
 					"expired, triggering in " <<
 					FORMAT_MICROSECONDS(timeToExpiry) <<
 					" seconds");
@@ -294,17 +290,14 @@
   mExpired(false)
 {
 	#ifndef NDEBUG
-	box_time_t timeNow = GetCurrentBoxTime();
 	if (timeoutSecs == 0)
 	{
-		BOX_TRACE(FORMAT_BOX_TIME(timeNow) <<
-			": timer " << this << " initialised for " <<
+		BOX_TRACE("timer " << this << " initialised for " <<
 			timeoutSecs << " secs, will not fire");
 	}
 	else
 	{
-		BOX_TRACE(FORMAT_BOX_TIME(timeNow) <<
-			": timer " << this << " initialised for " <<
+		BOX_TRACE("timer " << this << " initialised for " <<
 			timeoutSecs << " secs, to fire at " <<
 			FORMAT_MICROSECONDS(mExpires));
 	}
@@ -323,9 +316,7 @@
 Timer::~Timer()
 {
 	#ifndef NDEBUG
-	box_time_t timeNow = GetCurrentBoxTime();
-	BOX_TRACE(FORMAT_BOX_TIME(timeNow) <<
-		": timer " << this << " destroyed");
+	BOX_TRACE("timer " << this << " destroyed");
 	#endif
 
 	Timers::Remove(*this);
@@ -336,23 +327,19 @@
   mExpired(rToCopy.mExpired)
 {
 	#ifndef NDEBUG
-	box_time_t timeNow = GetCurrentBoxTime();
 	if (mExpired)
 	{
-		BOX_TRACE(FORMAT_BOX_TIME(timeNow) <<
-			": timer " << this << " initialised from timer " <<
+		BOX_TRACE("timer " << this << " initialised from timer " <<
 			&rToCopy << ", already expired, will not fire");
 	}
 	else if (mExpires == 0)
 	{
-		BOX_TRACE(FORMAT_BOX_TIME(timeNow) <<
-			": timer " << this << " initialised from timer " <<
+		BOX_TRACE("timer " << this << " initialised from timer " <<
 			&rToCopy << ", no expiry, will not fire");
 	}
 	else
 	{
-		BOX_TRACE(FORMAT_BOX_TIME(timeNow) <<
-			": timer " << this << " initialised from timer " <<
+		BOX_TRACE("timer " << this << " initialised from timer " <<
 			&rToCopy << " to fire at " <<
 			(int)(mExpires / 1000000) << "." <<
 			(int)(mExpires % 1000000));
@@ -368,23 +355,19 @@
 Timer& Timer::operator=(const Timer& rToCopy)
 {
 	#ifndef NDEBUG
-	box_time_t timeNow = GetCurrentBoxTime();
 	if (rToCopy.mExpired)
 	{
-		BOX_TRACE(FORMAT_BOX_TIME(timeNow) <<
-			": timer " << this << " initialised from timer " <<
+		BOX_TRACE("timer " << this << " initialised from timer " <<
 			&rToCopy << ", already expired, will not fire");
 	}
 	else if (rToCopy.mExpires == 0)
 	{
-		BOX_TRACE(FORMAT_BOX_TIME(timeNow) <<
-			": timer " << this << " initialised from timer " <<
+		BOX_TRACE("timer " << this << " initialised from timer " <<
 			&rToCopy << ", no expiry, will not fire");
 	}
 	else
 	{
-		BOX_TRACE(FORMAT_BOX_TIME(timeNow) <<
-			": timer " << this << " initialised from timer " <<
+		BOX_TRACE("timer " << this << " initialised from timer " <<
 			&rToCopy << " to fire at " <<
 			(int)(rToCopy.mExpires / 1000000) << "." <<
 			(int)(rToCopy.mExpires % 1000000));
@@ -404,8 +387,7 @@
 void Timer::OnExpire()
 {
 	#ifndef NDEBUG
-	box_time_t timeNow = GetCurrentBoxTime();
-	BOX_TRACE(FORMAT_BOX_TIME(timeNow) << ": timer " << this << " fired");
+	BOX_TRACE("timer " << this << " fired");
 	#endif
 
 	mExpired = true;


From boxbackup-dev@fluffy.co.uk  Sat Dec 15 20:07:04 2007
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Sat, 15 Dec 2007 20:07:04 +0000 (UTC)
Subject: [Box Backup-commit] COMMIT r2004 - box/trunk/lib/common
Message-ID: <20071215200704.D3235326997@www.boxbackup.org>

Author: chris
Date: 2007-12-15 20:07:04 +0000 (Sat, 15 Dec 2007)
New Revision: 2004

Modified:
   box/trunk/lib/common/Test.h
Log:
Log sleep time and resleeps in safe_sleep (only used in tests).


Modified: box/trunk/lib/common/Test.h
===================================================================
--- box/trunk/lib/common/Test.h	2007-12-15 20:04:56 UTC (rev 2003)
+++ box/trunk/lib/common/Test.h	2007-12-15 20:07:04 UTC (rev 2004)
@@ -437,10 +437,17 @@
 	Sleep(seconds * 1000);
 #else
 	struct timespec ts;
+	memset(&ts, 0, sizeof(ts));
 	ts.tv_sec  = seconds;
 	ts.tv_nsec = 0;
+	BOX_TRACE("sleeping for " << seconds << " seconds");
 	while (nanosleep(&ts, &ts) == -1 && errno == EINTR)
-	{ /* sleep again */ }
+	{
+		BOX_TRACE("safe_sleep interrupted with " <<
+			ts.tv_sec << "." << ts.tv_nsec <<
+			" secs remaining, sleeping again");
+		/* sleep again */
+	}
 #endif
 }
 


From boxbackup-dev@fluffy.co.uk  Sat Dec 15 22:20:37 2007
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Sat, 15 Dec 2007 22:20:37 +0000 (UTC)
Subject: [Box Backup-commit] COMMIT r2005 - in box/chris/general: infrastructure lib/common
Message-ID: <20071215222037.7F198326997@www.boxbackup.org>

Author: chris
Date: 2007-12-15 22:20:37 +0000 (Sat, 15 Dec 2007)
New Revision: 2005

Modified:
   box/chris/general/infrastructure/buildenv-testmain-template.cpp
   box/chris/general/lib/common/Logging.cpp
   box/chris/general/lib/common/Logging.h
   box/chris/general/lib/common/Test.h
   box/chris/general/lib/common/Timer.cpp
Log:
Allow logging with microsecond timestamps.

Add -U option to enable logging microsecond timestamps

Don't log our own timestamp now that Logging can do it for us with
microsecond precision.

Log sleep time and resleeps in safe_sleep (only used in tests).

(merges [2001] [2002] [2003] [2004])


Modified: box/chris/general/infrastructure/buildenv-testmain-template.cpp
===================================================================
--- box/chris/general/infrastructure/buildenv-testmain-template.cpp	2007-12-15 20:07:04 UTC (rev 2004)
+++ box/chris/general/infrastructure/buildenv-testmain-template.cpp	2007-12-15 22:20:37 UTC (rev 2005)
@@ -174,7 +174,7 @@
 	
 	int ch;
 	
-	while ((ch = getopt_long(argc, argv, "c:s:t:T", longopts, NULL))
+	while ((ch = getopt_long(argc, argv, "c:s:t:TU", longopts, NULL))
 		!= -1)
 	{
 		switch(ch)
@@ -208,6 +208,13 @@
 			}
 			break;
 
+			case 'U':
+			{
+				Console::SetShowTime(true);
+				Console::SetShowTimeMicros(true);
+			}
+			break;
+
 			case '?':
 			{
 				fprintf(stderr, "Unknown option: %s\n",

Modified: box/chris/general/lib/common/Logging.cpp
===================================================================
--- box/chris/general/lib/common/Logging.cpp	2007-12-15 20:07:04 UTC (rev 2004)
+++ box/chris/general/lib/common/Logging.cpp	2007-12-15 22:20:37 UTC (rev 2005)
@@ -20,6 +20,8 @@
 
 #include <iomanip>
 
+#include "BoxTime.h"
+
 bool Logging::sLogToSyslog  = false;
 bool Logging::sLogToConsole = false;
 bool Logging::sContextSet   = false;
@@ -178,7 +180,8 @@
 }
 
 bool Console::sShowTime = false;
-bool Console::sShowTag  = false;
+bool Console::sShowTimeMicros = false;
+bool Console::sShowTag = false;
 std::string Console::sTag;
 
 void Console::SetTag(const std::string& rTag)
@@ -192,6 +195,11 @@
 	sShowTime = enabled;
 }
 
+void Console::SetShowTimeMicros(bool enabled)
+{
+	sShowTimeMicros = enabled;
+}
+
 bool Console::Log(Log::Level level, const std::string& rFile, 
 	int line, std::string& rMessage)
 {
@@ -211,25 +219,31 @@
 
 	if (sShowTime)
 	{
-		struct tm time_now, *tm_ptr = &time_now;
-		time_t time_t_now = time(NULL);
+		box_time_t time_now = GetCurrentBoxTime();
+		time_t seconds = BoxTimeToSeconds(time_now);
+		int micros = BoxTimeToMicroSeconds(time_now) % MICRO_SEC_IN_SEC;
 
-		if (time_t_now == ((time_t)-1))
-		{
-			msg += strerror(errno);
-			msg += " ";
-		}
+		struct tm tm_now, *tm_ptr = &tm_now;
+
 		#ifdef WIN32
-			else if ((tm_ptr = localtime(&time_t_now)) != NULL)
+			if ((tm_ptr = localtime(&seconds)) != NULL)
 		#else
-			else if (localtime_r(&time_t_now, &time_now) != NULL)
+			if (localtime_r(&seconds, &tm_now) != NULL)
 		#endif
 		{
 			std::ostringstream buf;
+
 			buf << std::setfill('0') <<
 				std::setw(2) << tm_ptr->tm_hour << ":" << 
 				std::setw(2) << tm_ptr->tm_min  << ":" <<
-				std::setw(2) << tm_ptr->tm_sec  << " ";
+				std::setw(2) << tm_ptr->tm_sec;
+
+			if (sShowTimeMicros)
+			{
+				buf << "." << std::setw(6) << micros;
+			}
+
+			buf << " ";
 			msg += buf.str();
 		}
 		else

Modified: box/chris/general/lib/common/Logging.h
===================================================================
--- box/chris/general/lib/common/Logging.h	2007-12-15 20:07:04 UTC (rev 2004)
+++ box/chris/general/lib/common/Logging.h	2007-12-15 22:20:37 UTC (rev 2005)
@@ -118,6 +118,7 @@
 {
 	private:
 	static bool sShowTime;
+	static bool sShowTimeMicros;
 	static bool sShowTag;
 	static std::string sTag;
 
@@ -129,6 +130,7 @@
 
 	static void SetTag(const std::string& rTag);
 	static void SetShowTime(bool enabled);
+	static void SetShowTimeMicros(bool enabled);
 };
 
 // --------------------------------------------------------------------------

Modified: box/chris/general/lib/common/Test.h
===================================================================
--- box/chris/general/lib/common/Test.h	2007-12-15 20:07:04 UTC (rev 2004)
+++ box/chris/general/lib/common/Test.h	2007-12-15 22:20:37 UTC (rev 2005)
@@ -437,10 +437,17 @@
 	Sleep(seconds * 1000);
 #else
 	struct timespec ts;
+	memset(&ts, 0, sizeof(ts));
 	ts.tv_sec  = seconds;
 	ts.tv_nsec = 0;
+	BOX_TRACE("sleeping for " << seconds << " seconds");
 	while (nanosleep(&ts, &ts) == -1 && errno == EINTR)
-	{ /* sleep again */ }
+	{
+		BOX_TRACE("safe_sleep interrupted with " <<
+			ts.tv_sec << "." << ts.tv_nsec <<
+			" secs remaining, sleeping again");
+		/* sleep again */
+	}
 #endif
 }
 

Modified: box/chris/general/lib/common/Timer.cpp
===================================================================
--- box/chris/general/lib/common/Timer.cpp	2007-12-15 20:07:04 UTC (rev 2004)
+++ box/chris/general/lib/common/Timer.cpp	2007-12-15 22:20:37 UTC (rev 2005)
@@ -149,10 +149,6 @@
 	Reschedule();
 }
 
-#define FORMAT_BOX_TIME(t) \
-	(BoxTimeToSeconds(t)) << "." << \
-	(BoxTimeToMicroSeconds(t) % MICRO_SEC_IN_SEC)
-
 #define FORMAT_MICROSECONDS(t) \
 	(int)(t / 1000000) << "." << \
 	(int)(t % 1000000)
@@ -185,8 +181,10 @@
 
 		if (oldact.sa_handler != Timers::SignalHandler)
 		{
-			printf("Signal handler was %p, expected %p\n", 
-				oldact.sa_handler, Timers::SignalHandler);
+			BOX_ERROR("Signal handler was " <<
+				(void *)oldact.sa_handler << 
+				", expected " <<
+				(void *)Timers::SignalHandler);
 			THROW_EXCEPTION(CommonException, Internal)
 		}
 	#endif
@@ -214,8 +212,7 @@
 		
 			if (timeToExpiry <= 0)
 			{
-				BOX_TRACE(FORMAT_MICROSECONDS(timeNow) <<
-					": timer " << *i << " has expired, "
+				BOX_TRACE("timer " << *i << " has expired, "
 					"triggering it");
 				rTimer.OnExpire();
 				spTimers->erase(i);
@@ -224,8 +221,7 @@
 			}
 			else
 			{
-				BOX_TRACE(FORMAT_MICROSECONDS(timeNow) <<
-					": timer " << *i << " has not "
+				BOX_TRACE("timer " << *i << " has not "
 					"expired, triggering in " <<
 					FORMAT_MICROSECONDS(timeToExpiry) <<
 					" seconds");
@@ -294,17 +290,14 @@
   mExpired(false)
 {
 	#ifndef NDEBUG
-	box_time_t timeNow = GetCurrentBoxTime();
 	if (timeoutSecs == 0)
 	{
-		BOX_TRACE(FORMAT_BOX_TIME(timeNow) <<
-			": timer " << this << " initialised for " <<
+		BOX_TRACE("timer " << this << " initialised for " <<
 			timeoutSecs << " secs, will not fire");
 	}
 	else
 	{
-		BOX_TRACE(FORMAT_BOX_TIME(timeNow) <<
-			": timer " << this << " initialised for " <<
+		BOX_TRACE("timer " << this << " initialised for " <<
 			timeoutSecs << " secs, to fire at " <<
 			FORMAT_MICROSECONDS(mExpires));
 	}
@@ -323,9 +316,7 @@
 Timer::~Timer()
 {
 	#ifndef NDEBUG
-	box_time_t timeNow = GetCurrentBoxTime();
-	BOX_TRACE(FORMAT_BOX_TIME(timeNow) <<
-		": timer " << this << " destroyed");
+	BOX_TRACE("timer " << this << " destroyed");
 	#endif
 
 	Timers::Remove(*this);
@@ -336,23 +327,19 @@
   mExpired(rToCopy.mExpired)
 {
 	#ifndef NDEBUG
-	box_time_t timeNow = GetCurrentBoxTime();
 	if (mExpired)
 	{
-		BOX_TRACE(FORMAT_BOX_TIME(timeNow) <<
-			": timer " << this << " initialised from timer " <<
+		BOX_TRACE("timer " << this << " initialised from timer " <<
 			&rToCopy << ", already expired, will not fire");
 	}
 	else if (mExpires == 0)
 	{
-		BOX_TRACE(FORMAT_BOX_TIME(timeNow) <<
-			": timer " << this << " initialised from timer " <<
+		BOX_TRACE("timer " << this << " initialised from timer " <<
 			&rToCopy << ", no expiry, will not fire");
 	}
 	else
 	{
-		BOX_TRACE(FORMAT_BOX_TIME(timeNow) <<
-			": timer " << this << " initialised from timer " <<
+		BOX_TRACE("timer " << this << " initialised from timer " <<
 			&rToCopy << " to fire at " <<
 			(int)(mExpires / 1000000) << "." <<
 			(int)(mExpires % 1000000));
@@ -368,23 +355,19 @@
 Timer& Timer::operator=(const Timer& rToCopy)
 {
 	#ifndef NDEBUG
-	box_time_t timeNow = GetCurrentBoxTime();
 	if (rToCopy.mExpired)
 	{
-		BOX_TRACE(FORMAT_BOX_TIME(timeNow) <<
-			": timer " << this << " initialised from timer " <<
+		BOX_TRACE("timer " << this << " initialised from timer " <<
 			&rToCopy << ", already expired, will not fire");
 	}
 	else if (rToCopy.mExpires == 0)
 	{
-		BOX_TRACE(FORMAT_BOX_TIME(timeNow) <<
-			": timer " << this << " initialised from timer " <<
+		BOX_TRACE("timer " << this << " initialised from timer " <<
 			&rToCopy << ", no expiry, will not fire");
 	}
 	else
 	{
-		BOX_TRACE(FORMAT_BOX_TIME(timeNow) <<
-			": timer " << this << " initialised from timer " <<
+		BOX_TRACE("timer " << this << " initialised from timer " <<
 			&rToCopy << " to fire at " <<
 			(int)(rToCopy.mExpires / 1000000) << "." <<
 			(int)(rToCopy.mExpires % 1000000));
@@ -404,8 +387,7 @@
 void Timer::OnExpire()
 {
 	#ifndef NDEBUG
-	box_time_t timeNow = GetCurrentBoxTime();
-	BOX_TRACE(FORMAT_BOX_TIME(timeNow) << ": timer " << this << " fired");
+	BOX_TRACE("timer " << this << " fired");
 	#endif
 
 	mExpired = true;


From boxbackup-dev@fluffy.co.uk  Sun Dec 16 00:44:12 2007
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Sun, 16 Dec 2007 00:44:12 +0000 (UTC)
Subject: [Box Backup-commit] COMMIT r2006 - box/trunk/lib/intercept
Message-ID: <20071216004412.9A24B326997@www.boxbackup.org>

Author: chris
Date: 2007-12-16 00:44:11 +0000 (Sun, 16 Dec 2007)
New Revision: 2006

Modified:
   box/trunk/lib/intercept/intercept.cpp
Log:
Fix readdir() intercept on FreeBSD by fixing the check for redefined
readdir (from Linux).


Modified: box/trunk/lib/intercept/intercept.cpp
===================================================================
--- box/trunk/lib/intercept/intercept.cpp	2007-12-15 22:20:37 UTC (rev 2005)
+++ box/trunk/lib/intercept/intercept.cpp	2007-12-16 00:44:11 UTC (rev 2006)
@@ -402,12 +402,29 @@
 	lstat_hook = hookfn;
 }
 
+static void * find_function(const char *pName)
+{
+	dlerror();
+
+	void *result = dlsym(RTLD_NEXT, pName);
+	const char *errmsg = (const char *)dlerror();
+
+	if (errmsg != NULL)
+	{
+		BOX_ERROR("Failed to find real " << pName << " function: " <<
+			errmsg);
+		return NULL;
+	}
+
+	return result;
+}
+
 extern "C" 
 DIR *opendir(const char *dirname)
 {
 	if (opendir_real == NULL)
 	{
-		opendir_real = (opendir_t*)(dlsym(RTLD_NEXT, "opendir"));
+		opendir_real = (opendir_t*)find_function("opendir");
 	}
 
 	if (opendir_real == NULL)
@@ -440,10 +457,10 @@
 
 	if (readdir_real == NULL)
 	{
-		#if readdir == readdir64
-		readdir_real = (readdir_t*)(dlsym(RTLD_NEXT, "readdir64"));
+		#if defined readdir && readdir == readdir64
+		readdir_real = (readdir_t*)find_function("readdir64");
 		#else
-		readdir_real = (readdir_t*)(dlsym(RTLD_NEXT, "readdir"));
+		readdir_real = (readdir_t*)find_function("readdir");
 		#endif
 	}
 
@@ -466,7 +483,7 @@
 
 	if (closedir_real == NULL)
 	{
-		closedir_real = (closedir_t*)(dlsym(RTLD_NEXT, "closedir"));
+		closedir_real = (closedir_t*)find_function("closedir");
 	}
 
 	if (closedir_real == NULL)
@@ -489,16 +506,16 @@
 	if (lstat_real == NULL)
 	{
 	#ifdef LINUX_WEIRD_LSTAT
-		#if __lxstat == __lxstat64
-		lstat_real = (lstat_t*)(dlsym(RTLD_NEXT, "__lxstat64"));
+		#if defined __lxstat && __lxstat == __lxstat64
+		lstat_real = (lstat_t*)find_function("__lxstat64");
 		#else
-		lstat_real = (lstat_t*)(dlsym(RTLD_NEXT, "__lxstat"));
+		lstat_real = (lstat_t*)find_function("__lxstat");
 		#endif
 	#else
-		#if lstat == lstat64
-		lstat_real = (lstat_t*)(dlsym(RTLD_NEXT, "lstat64"));
+		#if defined lstat && lstat == lstat64
+		lstat_real = (lstat_t*)find_function("lstat64");
 		#else
-		lstat_real = (lstat_t*)(dlsym(RTLD_NEXT, "lstat"));
+		lstat_real = (lstat_t*)find_function("lstat");
 		#endif
 	#endif
 	}


From boxbackup-dev@fluffy.co.uk  Sun Dec 16 00:44:38 2007
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Sun, 16 Dec 2007 00:44:38 +0000 (UTC)
Subject: [Box Backup-commit] COMMIT r2007 - box/trunk/infrastructure
Message-ID: <20071216004438.B2EF9326997@www.boxbackup.org>

Author: chris
Date: 2007-12-16 00:44:38 +0000 (Sun, 16 Dec 2007)
New Revision: 2007

Modified:
   box/trunk/infrastructure/makebuildenv.pl.in
Log:
Compile with -Wundef to warn about undefined macros.


Modified: box/trunk/infrastructure/makebuildenv.pl.in
===================================================================
--- box/trunk/infrastructure/makebuildenv.pl.in	2007-12-16 00:44:11 UTC (rev 2006)
+++ box/trunk/infrastructure/makebuildenv.pl.in	2007-12-16 00:44:38 UTC (rev 2007)
@@ -531,13 +531,13 @@
 PERL = "@PERL@"
 WINDRES = windres
 .ifdef RELEASE
-CXXFLAGS = -DNDEBUG $release_flags -Wall $include_paths $extra_platform_defines -DBOX_VERSION="\\"$product_version\\""
+CXXFLAGS = -DNDEBUG $release_flags -Wall -Wundef $include_paths $extra_platform_defines -DBOX_VERSION="\\"$product_version\\""
 OUTBASE = ../../release
 OUTDIR = ../../release/$mod
 DEPENDMAKEFLAGS = -D RELEASE
 VARIENT = RELEASE
 .else
-CXXFLAGS = -g -Wall $include_paths $extra_platform_defines -DBOX_VERSION="\\"$product_version\\""
+CXXFLAGS = -g -Wall -Wundef $include_paths $extra_platform_defines -DBOX_VERSION="\\"$product_version\\""
 OUTBASE = ../../debug
 OUTDIR = ../../debug/$mod
 DEPENDMAKEFLAGS =


From boxbackup-dev@fluffy.co.uk  Sun Dec 16 12:57:24 2007
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Sun, 16 Dec 2007 12:57:24 +0000 (UTC)
Subject: [Box Backup-commit] COMMIT r2008 - in box: . james james/FreeBSD james/FreeBSD/files
Message-ID: <20071216125724.BEE30326997@www.boxbackup.org>

Author: jamesog
Date: 2007-12-16 12:57:21 +0000 (Sun, 16 Dec 2007)
New Revision: 2008

Added:
   box/james/
   box/james/FreeBSD/
   box/james/FreeBSD/Makefile
   box/james/FreeBSD/distinfo
   box/james/FreeBSD/files/
   box/james/FreeBSD/files/bbackupd.sh.in
   box/james/FreeBSD/files/bbstored.sh.in
   box/james/FreeBSD/files/patch-configure.ac
   box/james/FreeBSD/files/patch-lib-common-BoxPortsAndFiles.h
   box/james/FreeBSD/files/pkg-message.client
   box/james/FreeBSD/files/pkg-message.server
   box/james/FreeBSD/pkg-deinstall
   box/james/FreeBSD/pkg-descr
   box/james/FreeBSD/pkg-install
   box/james/FreeBSD/pkg-plist
Log:
- Add a working directory for myself
- Checkin the FreeBSD port skeleton (as of 0.10 release)



Added: box/james/FreeBSD/Makefile
===================================================================
--- box/james/FreeBSD/Makefile	                        (rev 0)
+++ box/james/FreeBSD/Makefile	2007-12-16 12:57:21 UTC (rev 2008)
@@ -0,0 +1,123 @@
+# New ports collection makefile for: boxbackup
+# Date created:		19 December 2004
+# Whom:			James O'Gorman <james@netinertia.co.uk>
+#
+# $FreeBSD: ports/sysutils/boxbackup/Makefile,v 1.10 2007/09/30 04:47:25 linimon Exp $
+#
+
+PORTNAME=	boxbackup
+PORTVERSION=	0.10
+PORTREVISION=	1
+CATEGORIES=	sysutils
+MASTER_SITES=	${MASTER_SITE_SOURCEFORGE}
+MASTER_SITE_SUBDIR=${PORTNAME}
+EXTRACT_SUFX=	.tgz
+
+MAINTAINER=	james@netinertia.co.uk
+COMMENT=	An open source, completely automatic on-line backup system for UNIX
+
+USE_OPENSSL=	yes
+GNU_CONFIGURE=	yes
+USE_PERL5=	yes
+USE_GCC=	3.2+
+USE_AUTOTOOLS=	autoconf:261 aclocal:19 autoheader:261
+ACLOCAL_ARGS+=	-I ${WRKSRC}/infrastructure/m4
+
+PKGMESSAGE=	${WRKDIR}/pkg-message
+
+OPTIONS=	CLIENT "Install the bbackupd client" On \
+		SERVER "Install the bbstored server" On \
+		GNUREADLINE "Enable the use of GNU readline" Off \
+		TESTS  "Allows use of a 'test' target to run tests" Off
+
+.include <bsd.port.pre.mk>
+
+TARGETOS!=	${ECHO_CMD} `${UNAME} -s``${UNAME} -r | ${SED} -e 's/[-(].*//'` | ${TR} A-Z a-z
+
+.if defined(WITH_GNUREADLINE)
+CONFIGURE_ARGS+=--enable-gnu-readline
+.endif
+
+.if defined(WITHOUT_CLIENT) && defined(WITHOUT_SERVER)
+IGNORE=		requires at least CLIENT or SERVER to be defined.\
+		Please 'make config' again
+.endif
+
+.if defined(WITHOUT_CLIENT)
+PLIST_SUB+=	CLIENT="@comment "
+.else
+USE_RC_SUBR+=	bbackupd.sh
+PLIST_SUB+=	CLIENT=""
+ALL_TARGET+=	parcels/${DISTNAME}-backup-client-${TARGETOS}.tgz
+INSTALL_TARGET+=install-backup-client
+.endif
+
+.if defined(WITHOUT_SERVER)
+PLIST_SUB+=	SERVER="@comment "
+.else
+USE_RC_SUBR+=	bbstored.sh
+PLIST_SUB+=	SERVER=""
+ALL_TARGET+=	parcels/${DISTNAME}-backup-server-${TARGETOS}.tgz
+INSTALL_TARGET+=install-backup-server
+.endif
+
+CONFLICTS=	boxbackup-server-[0-9]* boxbackup-client-[0-9]*
+.if defined(WITHOUT_CLIENT)
+CONFLICTS=	boxbackup-client-[0-9]*
+PKGNAMESUFFIX=	-server
+.elif defined(WITHOUT_SERVER)
+CONFLICTS=	boxbackup-server-[0-9]*
+PKGNAMESUFFIX=	-client
+.endif
+
+post-patch:
+# Replace hard-coded /etc/box with $PREFIX/etc/box
+	@${REINPLACE_CMD} -e 's,%%PREFIX%%,${PREFIX},' \
+		${WRKSRC}/lib/common/BoxPortsAndFiles.h
+# Fix path to perl
+	@${FIND} ${WRKSRC} -name "*.pl" -exec \
+		${REINPLACE_CMD} -e 's,/usr/bin/perl,${PERL},g' {} \;
+	@${REINPLACE_CMD} -e 's,/usr/bin/perl,${PERL},g' \
+		${WRKSRC}/bin/bbackupd/bbackupd-config \
+		${WRKSRC}/bin/bbstored/bbstored-certs \
+		${WRKSRC}/bin/bbstored/bbstored-config \
+		${WRKSRC}/lib/raidfile/raidfile-config
+	@${FIND} ${WRKSRC} -name "Makefile.extra" -exec \
+		${REINPLACE_CMD} -e 's,perl,${PERL},g' {} \;
+	@${REINPLACE_CMD} -e 's,perl ,${PERL} ,g' \
+		${WRKSRC}/test/bbackupd/testfiles/bbackupd.conf \
+		${WRKSRC}/infrastructure/makebuildenv.pl
+	@${REINPLACE_CMD} -e 's,"perl ,PERL_EXECUTABLE " ,g' \
+		${WRKSRC}/test/backupstorefix/testbackupstorefix.cpp
+# Fix hard-coded g++
+	@${REINPLACE_CMD} -e 's,g++,${CXX},' \
+		 ${WRKSRC}/infrastructure/makebuildenv.pl
+.if !defined(WITHOUT_CLIENT)
+	@${CAT} ${FILESDIR}/pkg-message.client >> ${PKGMESSAGE}
+.endif
+.if !defined(WITHOUT_SERVER)
+	@${CAT} ${FILESDIR}/pkg-message.server >> ${PKGMESSAGE}
+.endif
+
+.if !defined(WITHOUT_SERVER)
+pre-install:
+	@${SETENV} PKG_PREFIX=${PREFIX} \
+		${SH} ${PKGINSTALL} ${PKGNAME} PRE-INSTALL
+.endif
+
+post-install:
+.if !defined(WITHOUT_CLIENT)
+	@${MKDIR} -m 0700 ${PREFIX}/etc/box/bbackupd
+.endif
+.if !defined(WITHOUT_SERVER)
+	@${MKDIR} -m 0700 ${PREFIX}/etc/box/bbstored
+.endif
+	@${CAT} ${PKGMESSAGE}
+
+.if defined(WITH_TESTS)
+test:
+	 @${ECHO_CMD} "===> Running tests"
+	 @${MAKE} -C ${WRKSRC} test
+.endif
+
+.include <bsd.port.post.mk>

Added: box/james/FreeBSD/distinfo
===================================================================
--- box/james/FreeBSD/distinfo	                        (rev 0)
+++ box/james/FreeBSD/distinfo	2007-12-16 12:57:21 UTC (rev 2008)
@@ -0,0 +1,3 @@
+MD5 (boxbackup-0.10.tgz) = 2dc02d87932fdb222ed019443ddcf444
+SHA256 (boxbackup-0.10.tgz) = 09e88f4ee26b76b3d6e6a0cf3fc374e55d79dd84e9884dfc6a7635593862d361
+SIZE (boxbackup-0.10.tgz) = 842450

Added: box/james/FreeBSD/files/bbackupd.sh.in
===================================================================
--- box/james/FreeBSD/files/bbackupd.sh.in	                        (rev 0)
+++ box/james/FreeBSD/files/bbackupd.sh.in	2007-12-16 12:57:21 UTC (rev 2008)
@@ -0,0 +1,27 @@
+#!/bin/sh
+#
+# $FreeBSD: ports/sysutils/boxbackup/files/bbackupd.sh.in,v 1.2 2006/02/20 20:47:41 dougb Exp $
+#
+# PROVIDE: bbackupd
+# REQUIRE: NETWORKING
+# KEYWORD: shutdown
+
+#
+# Add the following line to /etc/rc.conf to enable bbackupd:
+#
+#bbackupd_enable="YES"
+#
+
+: ${bbackupd_enable:="NO"}
+: ${bbackupd_flags:="%%PREFIX%%/etc/box/bbackupd.conf"}
+: ${bbackupd_pidfile:="/var/run/bbackupd.pid"}
+
+. %%RC_SUBR%%
+
+name="bbackupd"
+rcvar=`set_rcvar`
+command="%%PREFIX%%/bin/bbackupd"
+extra_commands="reload"
+
+load_rc_config $name
+run_rc_command "$1"

Added: box/james/FreeBSD/files/bbstored.sh.in
===================================================================
--- box/james/FreeBSD/files/bbstored.sh.in	                        (rev 0)
+++ box/james/FreeBSD/files/bbstored.sh.in	2007-12-16 12:57:21 UTC (rev 2008)
@@ -0,0 +1,27 @@
+#!/bin/sh
+#
+# $FreeBSD: ports/sysutils/boxbackup/files/bbstored.sh.in,v 1.2 2006/02/20 20:47:41 dougb Exp $
+#
+# PROVIDE: bbstored
+# REQUIRE: NETWORKING
+# KEYWORD: shutdown
+
+#
+# Add the following line to /etc/rc.conf to enable bbstored:
+#
+#bbstored_enable="YES"
+#
+
+: ${bbstored_enable:="NO"}
+: ${bbstored_flags:="%%PREFIX%%/etc/box/bbstored.conf"}
+: ${bbstored_pidfile:="/var/run/bbstored.pid"}
+
+. %%RC_SUBR%%
+
+name="bbstored"
+rcvar=`set_rcvar`
+command="%%PREFIX%%/bin/bbstored"
+extra_commands="reload"
+
+load_rc_config $name
+run_rc_command "$1"

Added: box/james/FreeBSD/files/patch-configure.ac
===================================================================
--- box/james/FreeBSD/files/patch-configure.ac	                        (rev 0)
+++ box/james/FreeBSD/files/patch-configure.ac	2007-12-16 12:57:21 UTC (rev 2008)
@@ -0,0 +1,35 @@
+--- configure.ac.orig	Thu Mar 16 22:26:39 2006
++++ configure.ac	Thu Mar 16 22:28:31 2006
+@@ -2,7 +2,7 @@
+ # Process this file with autoconf to produce a configure script.
+ 
+ AC_PREREQ(2.59)
+-AC_INIT([Box Backup], 0.09, [box@fluffy.co.uk])
++AC_INIT([Box Backup], 0.10, [box@fluffy.co.uk])
+ AC_CONFIG_SRCDIR([lib/common/Box.h])
+ AC_CONFIG_HEADERS([lib/common/BoxConfig.h])
+ 
+@@ -26,6 +26,12 @@
+   # Use -rdynamic if we have gcc. This is needed for backtrace
+   AC_SUBST([LDADD_RDYNAMIC], ['-rdynamic'])
+ fi
++AC_PATH_PROG([PERL], [perl], [no])
++if test "x$PERL" != "xno"; then
++  AC_DEFINE_UNQUOTED([PERL_EXECUTABLE], ["$PERL"], [Location of the perl executable])
++else
++  AC_MSG_ERROR([[perl executable was not found]])
++fi
+ 
+ 
+ ### Checks for libraries.
+@@ -208,8 +214,8 @@
+ 
+ # Configure the Box build system
+ echo
+-perl ./infrastructure/makebuildenv.pl &&
+-  perl ./infrastructure/makeparcels.pl
++$PERL ./infrastructure/makebuildenv.pl &&
++  $PERL ./infrastructure/makeparcels.pl
+ 
+ # Write summary of important info
+ cat <<EOC

Added: box/james/FreeBSD/files/patch-lib-common-BoxPortsAndFiles.h
===================================================================
--- box/james/FreeBSD/files/patch-lib-common-BoxPortsAndFiles.h	                        (rev 0)
+++ box/james/FreeBSD/files/patch-lib-common-BoxPortsAndFiles.h	2007-12-16 12:57:21 UTC (rev 2008)
@@ -0,0 +1,25 @@
+--- lib/common/BoxPortsAndFiles.h.orig	Thu Mar 16 19:28:09 2006
++++ lib/common/BoxPortsAndFiles.h	Thu Mar 16 19:28:38 2006
+@@ -53,7 +53,7 @@
+ 
+ // Backup store daemon
+ #define BOX_PORT_BBSTORED					(BOX_PORT_BASE+1)
+-#define BOX_FILE_BBSTORED_DEFAULT_CONFIG	"/etc/box/bbstored.conf"
++#define BOX_FILE_BBSTORED_DEFAULT_CONFIG	"%%PREFIX%%/etc/box/bbstored.conf"
+ // directory within the RAIDFILE root for the backup store daemon
+ #define BOX_RAIDFILE_ROOT_BBSTORED			"backup"
+ 
+@@ -61,11 +61,11 @@
+ #ifdef WIN32
+ #define BOX_FILE_BBACKUPD_DEFAULT_CONFIG	"C:\\Program Files\\Box Backup\\bbackupd.conf"
+ #else
+-#define BOX_FILE_BBACKUPD_DEFAULT_CONFIG	"/etc/box/bbackupd.conf"
++#define BOX_FILE_BBACKUPD_DEFAULT_CONFIG	"%%PREFIX%%/etc/box/bbackupd.conf"
+ #endif
+ 
+ // RaidFile conf location default
+-#define BOX_FILE_RAIDFILE_DEFAULT_CONFIG	"/etc/box/raidfile.conf"
++#define BOX_FILE_RAIDFILE_DEFAULT_CONFIG	"%%PREFIX%%/etc/box/raidfile.conf"
+ 
+ // Default name of the named pipe
+ #define BOX_NAMED_PIPE_NAME L"\\\\.\\pipe\\boxbackup"

Added: box/james/FreeBSD/files/pkg-message.client
===================================================================
--- box/james/FreeBSD/files/pkg-message.client	                        (rev 0)
+++ box/james/FreeBSD/files/pkg-message.client	2007-12-16 12:57:21 UTC (rev 2008)
@@ -0,0 +1,4 @@
+
+To run bbackupd at startup, add bbackupd_enable="YES" to /etc/rc.conf
+Please see http://www.fluffy.co.uk/boxbackup/client.html for client
+configuration options

Added: box/james/FreeBSD/files/pkg-message.server
===================================================================
--- box/james/FreeBSD/files/pkg-message.server	                        (rev 0)
+++ box/james/FreeBSD/files/pkg-message.server	2007-12-16 12:57:21 UTC (rev 2008)
@@ -0,0 +1,4 @@
+
+To run bbstored at startup, add bbstored_enable="YES" to /etc/rc.conf
+Please see http://www.fluffy.co.uk/boxbackup/server.html for server
+configuration options

Added: box/james/FreeBSD/pkg-deinstall
===================================================================
--- box/james/FreeBSD/pkg-deinstall	                        (rev 0)
+++ box/james/FreeBSD/pkg-deinstall	2007-12-16 12:57:21 UTC (rev 2008)
@@ -0,0 +1,69 @@
+#! /bin/sh
+#
+# ex:ts=4
+
+ask() {
+	local question default answer
+
+	question=$1
+	default=$2
+	if [ -z "${PACKAGE_BUILDING}" -a -z "${BATCH}" ]; then
+		read -p "${question} [${default}]? " answer
+	fi
+	echo ${answer:-${default}}
+}
+
+yesno() {
+	local question default answer
+
+	question=$1
+	default=$2
+	while :; do
+		answer=$(ask "${question}" "${default}")
+		case "${answer}" in
+		[Yy]*)	return 0;;
+		[Nn]*)	return 1;;
+		esac
+		echo "Please answer yes or no."
+	done
+}
+
+delete_account() {
+	local u pw
+
+	u=$1
+	pw=`pw usershow ${u} >/dev/null 2>&1`
+	if [ $? -eq 0 ]; then
+		if yesno "Do you want me to remove user \"${u}\"" n; then
+			pw userdel -n ${u}
+			echo "Done."
+		fi
+	fi
+}
+
+case $2 in
+
+DEINSTALL)
+	if ps -axc | grep -qw bbstored; then
+		if yesno "bbstored is still running. Shall I stop it?" y; then
+			killall bbstored
+			sleep 2
+		else
+			echo "OK ... I hope you know what you are doing."
+		fi
+	fi
+
+	if ps -axc | grep -qw bbackupd; then
+		if yesno "bbackupd is still running. Shall I stop it?" y; then
+			killall bbackupd
+			sleep 2
+		else
+			echo "OK ... I hope you know what you are doing."
+		fi
+	fi
+
+	delete_account _bbstored
+
+	;;
+
+esac

Added: box/james/FreeBSD/pkg-descr
===================================================================
--- box/james/FreeBSD/pkg-descr	                        (rev 0)
+++ box/james/FreeBSD/pkg-descr	2007-12-16 12:57:21 UTC (rev 2008)
@@ -0,0 +1,13 @@
+This is a port of Box Backup, an online backup daemon 
+
+The backup daemon, bbackupd, runs on all machines to be backed up. The
+store server daemon, bbstored runs on a central server. Data is sent
+to the store server, which stores all data on local filesystems, that
+is, only on local hard drives. Tape or other archive media is not
+used.
+
+The system is designed to be easy to set up and run, and cheap to use.
+Once set up, there should be no need for user or administrative
+intervention, apart from usual system maintenance.
+
+WWW: http://www.fluffy.co.uk/boxbackup/

Added: box/james/FreeBSD/pkg-install
===================================================================
--- box/james/FreeBSD/pkg-install	                        (rev 0)
+++ box/james/FreeBSD/pkg-install	2007-12-16 12:57:21 UTC (rev 2008)
@@ -0,0 +1,36 @@
+#!/bin/sh
+
+# $FreeBSD: ports/sysutils/boxbackup/pkg-install,v 1.3 2006/03/24 19:31:14 mnag Exp $
+
+case $2 in
+PRE-INSTALL)
+	USER=_bbstored
+	GROUP=${USER}
+	UID=505
+	GID=${UID}
+
+	if pw group show "${GROUP}" 2>/dev/null; then
+		echo "You already have a group \"${GROUP}\", so I will use it."
+	else
+		if pw groupadd ${GROUP} -g ${GID}; then
+                        echo "Added group \"${GROUP}\"."
+                else
+                        echo "Adding group \"${GROUP}\" failed..."
+                        exit 1
+                fi
+        fi
+
+	if pw user show "${USER}" 2>/dev/null; then
+		echo "You already have a user \"${USER}\", so I will use it."
+	else
+		if pw useradd ${USER} -u ${UID} -g ${GROUP} -h - \
+			-d /nonexistent -c "Box Backup Store Daemon"
+		then
+			echo "Added user \"${USER}\"."
+		else
+			echo "Adding user \"${USER}\" failed..."
+			exit 1
+		fi
+	fi
+	;;
+esac

Added: box/james/FreeBSD/pkg-plist
===================================================================
--- box/james/FreeBSD/pkg-plist	                        (rev 0)
+++ box/james/FreeBSD/pkg-plist	2007-12-16 12:57:21 UTC (rev 2008)
@@ -0,0 +1,14 @@
+%%CLIENT%%bin/bbackupctl
+%%CLIENT%%bin/bbackupd
+%%CLIENT%%bin/bbackupd-config
+%%CLIENT%%bin/bbackupquery
+%%SERVER%%bin/bbstoreaccounts
+%%SERVER%%bin/bbstored
+%%SERVER%%bin/bbstored-certs
+%%SERVER%%bin/bbstored-config
+%%SERVER%%bin/raidfile-config
+%%CLIENT%%@exec mkdir -p -m 0700 %D/etc/box/bbackupd
+%%SERVER%%@exec mkdir -p -m 0700 %D/etc/box/bbstored
+%%CLIENT%%@dirrmtry etc/box/bbackupd
+%%SERVER%%@dirrmtry etc/box/bbstored
+@dirrmtry etc/box


From boxbackup-dev@fluffy.co.uk  Sun Dec 16 16:48:31 2007
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Sun, 16 Dec 2007 16:48:31 +0000 (UTC)
Subject: [Box Backup-commit] COMMIT r2009 - in box/james/FreeBSD: . files
Message-ID: <20071216164831.BBC0A326997@www.boxbackup.org>

Author: jamesog
Date: 2007-12-16 16:48:28 +0000 (Sun, 16 Dec 2007)
New Revision: 2009

Added:
   box/james/FreeBSD/files/patch-configdir
Removed:
   box/james/FreeBSD/files/patch-configure.ac
   box/james/FreeBSD/files/patch-lib-common-BoxPortsAndFiles.h
Modified:
   box/james/FreeBSD/Makefile
Log:
Update the FreeBSD port skeleton for pre-0.11:

 * Remove all the perl hacks; these have been committed to trunk
 * Update the build targets to the new build-backup-(client|server) targets
 * Enable BDB by default
 * Remove the g++ fix as Chris has fixed this in trunk
 * Update the configdir patch to make autoconf generate a macro instead of
   manually patching with sed



Modified: box/james/FreeBSD/Makefile
===================================================================
--- box/james/FreeBSD/Makefile	2007-12-16 12:57:21 UTC (rev 2008)
+++ box/james/FreeBSD/Makefile	2007-12-16 16:48:28 UTC (rev 2009)
@@ -27,12 +27,17 @@
 
 OPTIONS=	CLIENT "Install the bbackupd client" On \
 		SERVER "Install the bbstored server" On \
+		BDB "Enable Berkeley DB" On \
 		GNUREADLINE "Enable the use of GNU readline" Off \
 		TESTS  "Allows use of a 'test' target to run tests" Off
 
 .include <bsd.port.pre.mk>
 
-TARGETOS!=	${ECHO_CMD} `${UNAME} -s``${UNAME} -r | ${SED} -e 's/[-(].*//'` | ${TR} A-Z a-z
+.if defined(WITH_BDB)
+USE_BDB=	42+
+CONFIGURE_ARGS+=--with-bdb-lib=${BDB_LIB_DIR} \
+		--with-bdb-headers=${BDB_INCLUDE_DIR}
+.endif
 
 .if defined(WITH_GNUREADLINE)
 CONFIGURE_ARGS+=--enable-gnu-readline
@@ -43,22 +48,22 @@
 		Please 'make config' again
 .endif
 
-.if defined(WITHOUT_CLIENT)
-PLIST_SUB+=	CLIENT="@comment "
-.else
+.if defined(WITH_CLIENT)
 USE_RC_SUBR+=	bbackupd.sh
 PLIST_SUB+=	CLIENT=""
-ALL_TARGET+=	parcels/${DISTNAME}-backup-client-${TARGETOS}.tgz
+ALL_TARGET+=	build-backup-client
 INSTALL_TARGET+=install-backup-client
+.else
+PLIST_SUB+=	CLIENT="@comment "
 .endif
 
-.if defined(WITHOUT_SERVER)
-PLIST_SUB+=	SERVER="@comment "
-.else
+.if defined(WITH_SERVER)
 USE_RC_SUBR+=	bbstored.sh
 PLIST_SUB+=	SERVER=""
-ALL_TARGET+=	parcels/${DISTNAME}-backup-server-${TARGETOS}.tgz
+ALL_TARGET+=	build-backup-server
 INSTALL_TARGET+=install-backup-server
+.else
+PLIST_SUB+=	SERVER="@comment "
 .endif
 
 CONFLICTS=	boxbackup-server-[0-9]* boxbackup-client-[0-9]*
@@ -71,27 +76,6 @@
 .endif
 
 post-patch:
-# Replace hard-coded /etc/box with $PREFIX/etc/box
-	@${REINPLACE_CMD} -e 's,%%PREFIX%%,${PREFIX},' \
-		${WRKSRC}/lib/common/BoxPortsAndFiles.h
-# Fix path to perl
-	@${FIND} ${WRKSRC} -name "*.pl" -exec \
-		${REINPLACE_CMD} -e 's,/usr/bin/perl,${PERL},g' {} \;
-	@${REINPLACE_CMD} -e 's,/usr/bin/perl,${PERL},g' \
-		${WRKSRC}/bin/bbackupd/bbackupd-config \
-		${WRKSRC}/bin/bbstored/bbstored-certs \
-		${WRKSRC}/bin/bbstored/bbstored-config \
-		${WRKSRC}/lib/raidfile/raidfile-config
-	@${FIND} ${WRKSRC} -name "Makefile.extra" -exec \
-		${REINPLACE_CMD} -e 's,perl,${PERL},g' {} \;
-	@${REINPLACE_CMD} -e 's,perl ,${PERL} ,g' \
-		${WRKSRC}/test/bbackupd/testfiles/bbackupd.conf \
-		${WRKSRC}/infrastructure/makebuildenv.pl
-	@${REINPLACE_CMD} -e 's,"perl ,PERL_EXECUTABLE " ,g' \
-		${WRKSRC}/test/backupstorefix/testbackupstorefix.cpp
-# Fix hard-coded g++
-	@${REINPLACE_CMD} -e 's,g++,${CXX},' \
-		 ${WRKSRC}/infrastructure/makebuildenv.pl
 .if !defined(WITHOUT_CLIENT)
 	@${CAT} ${FILESDIR}/pkg-message.client >> ${PKGMESSAGE}
 .endif

Added: box/james/FreeBSD/files/patch-configdir
===================================================================
--- box/james/FreeBSD/files/patch-configdir	                        (rev 0)
+++ box/james/FreeBSD/files/patch-configdir	2007-12-16 16:48:28 UTC (rev 2009)
@@ -0,0 +1,16 @@
+Index: configure.ac
+===================================================================
+--- configure.ac	(revision 2007)
++++ configure.ac	(working copy)
+@@ -268,9 +268,11 @@
+ test "x$exec_prefix" = xNONE && exec_prefix='${prefix}'
+ bindir_expanded=`eval "echo $bindir"`
+ bindir_expanded=`eval "echo $bindir_expanded"`
++box_configdir=`eval "echo ${sysconfdir}/box"`
+ prefix=$saved_prefix
+ exec_prefix=$saved_exec_prefix
+ AC_SUBST([bindir_expanded])
++AC_DEFINE_UNQUOTED([BOX_CONFIGDIR], ["$box_configdir"], [Location of config files (e.g. PREFIX/etc)])
+ 
+ 
+ ### Output files

Deleted: box/james/FreeBSD/files/patch-configure.ac
===================================================================
--- box/james/FreeBSD/files/patch-configure.ac	2007-12-16 12:57:21 UTC (rev 2008)
+++ box/james/FreeBSD/files/patch-configure.ac	2007-12-16 16:48:28 UTC (rev 2009)
@@ -1,35 +0,0 @@
---- configure.ac.orig	Thu Mar 16 22:26:39 2006
-+++ configure.ac	Thu Mar 16 22:28:31 2006
-@@ -2,7 +2,7 @@
- # Process this file with autoconf to produce a configure script.
- 
- AC_PREREQ(2.59)
--AC_INIT([Box Backup], 0.09, [box@fluffy.co.uk])
-+AC_INIT([Box Backup], 0.10, [box@fluffy.co.uk])
- AC_CONFIG_SRCDIR([lib/common/Box.h])
- AC_CONFIG_HEADERS([lib/common/BoxConfig.h])
- 
-@@ -26,6 +26,12 @@
-   # Use -rdynamic if we have gcc. This is needed for backtrace
-   AC_SUBST([LDADD_RDYNAMIC], ['-rdynamic'])
- fi
-+AC_PATH_PROG([PERL], [perl], [no])
-+if test "x$PERL" != "xno"; then
-+  AC_DEFINE_UNQUOTED([PERL_EXECUTABLE], ["$PERL"], [Location of the perl executable])
-+else
-+  AC_MSG_ERROR([[perl executable was not found]])
-+fi
- 
- 
- ### Checks for libraries.
-@@ -208,8 +214,8 @@
- 
- # Configure the Box build system
- echo
--perl ./infrastructure/makebuildenv.pl &&
--  perl ./infrastructure/makeparcels.pl
-+$PERL ./infrastructure/makebuildenv.pl &&
-+  $PERL ./infrastructure/makeparcels.pl
- 
- # Write summary of important info
- cat <<EOC

Deleted: box/james/FreeBSD/files/patch-lib-common-BoxPortsAndFiles.h
===================================================================
--- box/james/FreeBSD/files/patch-lib-common-BoxPortsAndFiles.h	2007-12-16 12:57:21 UTC (rev 2008)
+++ box/james/FreeBSD/files/patch-lib-common-BoxPortsAndFiles.h	2007-12-16 16:48:28 UTC (rev 2009)
@@ -1,25 +0,0 @@
---- lib/common/BoxPortsAndFiles.h.orig	Thu Mar 16 19:28:09 2006
-+++ lib/common/BoxPortsAndFiles.h	Thu Mar 16 19:28:38 2006
-@@ -53,7 +53,7 @@
- 
- // Backup store daemon
- #define BOX_PORT_BBSTORED					(BOX_PORT_BASE+1)
--#define BOX_FILE_BBSTORED_DEFAULT_CONFIG	"/etc/box/bbstored.conf"
-+#define BOX_FILE_BBSTORED_DEFAULT_CONFIG	"%%PREFIX%%/etc/box/bbstored.conf"
- // directory within the RAIDFILE root for the backup store daemon
- #define BOX_RAIDFILE_ROOT_BBSTORED			"backup"
- 
-@@ -61,11 +61,11 @@
- #ifdef WIN32
- #define BOX_FILE_BBACKUPD_DEFAULT_CONFIG	"C:\\Program Files\\Box Backup\\bbackupd.conf"
- #else
--#define BOX_FILE_BBACKUPD_DEFAULT_CONFIG	"/etc/box/bbackupd.conf"
-+#define BOX_FILE_BBACKUPD_DEFAULT_CONFIG	"%%PREFIX%%/etc/box/bbackupd.conf"
- #endif
- 
- // RaidFile conf location default
--#define BOX_FILE_RAIDFILE_DEFAULT_CONFIG	"/etc/box/raidfile.conf"
-+#define BOX_FILE_RAIDFILE_DEFAULT_CONFIG	"%%PREFIX%%/etc/box/raidfile.conf"
- 
- // Default name of the named pipe
- #define BOX_NAMED_PIPE_NAME L"\\\\.\\pipe\\boxbackup"


From boxbackup-dev@fluffy.co.uk  Sun Dec 16 23:52:08 2007
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Sun, 16 Dec 2007 23:52:08 +0000 (UTC)
Subject: [Box Backup-commit] COMMIT r2010 - in box/trunk: infrastructure lib/common test/basicserver
Message-ID: <20071216235208.0846C326997@www.boxbackup.org>

Author: chris
Date: 2007-12-16 23:52:05 +0000 (Sun, 16 Dec 2007)
New Revision: 2010

Modified:
   box/trunk/infrastructure/buildenv-testmain-template.cpp
   box/trunk/lib/common/Test.h
   box/trunk/test/basicserver/testbasicserver.cpp
Log:
Pass test options to test daemons.


Modified: box/trunk/infrastructure/buildenv-testmain-template.cpp
===================================================================
--- box/trunk/infrastructure/buildenv-testmain-template.cpp	2007-12-16 16:48:28 UTC (rev 2009)
+++ box/trunk/infrastructure/buildenv-testmain-template.cpp	2007-12-16 23:52:05 UTC (rev 2010)
@@ -57,7 +57,7 @@
 int failures = 0;
 int first_fail_line;
 std::string first_fail_file;
-std::string bbackupd_args, bbstored_args, bbackupquery_args;
+std::string bbackupd_args, bbstored_args, bbackupquery_args, test_args;
 
 int filedes_open_at_beginning = -1;
 
@@ -194,12 +194,16 @@
 			case 't':
 			{
 				Console::SetTag(optarg);
+				test_args += " -t '";
+				test_args += optarg;
+				test_args += "'";
 			}
 			break;
 
 			case 'T':
 			{
 				Console::SetShowTime(true);
+				test_args += " -T";
 			}
 			break;
 
@@ -207,13 +211,14 @@
 			{
 				Console::SetShowTime(true);
 				Console::SetShowTimeMicros(true);
+				test_args += " -U";
 			}
 			break;
 
 			case '?':
 			{
-				fprintf(stderr, "Unknown option: %s\n",
-					optarg);
+				fprintf(stderr, "Unknown option: '%c'\n",
+					optopt);
 				exit(2);
 			}
 

Modified: box/trunk/lib/common/Test.h
===================================================================
--- box/trunk/lib/common/Test.h	2007-12-16 16:48:28 UTC (rev 2009)
+++ box/trunk/lib/common/Test.h	2007-12-16 23:52:05 UTC (rev 2010)
@@ -43,7 +43,7 @@
 extern int failures;
 extern int first_fail_line;
 extern std::string first_fail_file;
-extern std::string bbackupd_args, bbstored_args, bbackupquery_args;
+extern std::string bbackupd_args, bbstored_args, bbackupquery_args, test_args;
 
 #define TEST_FAIL_WITH_MESSAGE(msg) \
 { \

Modified: box/trunk/test/basicserver/testbasicserver.cpp
===================================================================
--- box/trunk/test/basicserver/testbasicserver.cpp	2007-12-16 16:48:28 UTC (rev 2009)
+++ box/trunk/test/basicserver/testbasicserver.cpp	2007-12-16 23:52:05 UTC (rev 2010)
@@ -436,8 +436,10 @@
 
 	// Launch a basic server
 	{
-		int pid = LaunchServer("./test srv1 testfiles/srv1.conf", 
-			"testfiles/srv1.pid");
+		std::string cmd = "./test";
+		cmd += test_args;
+		cmd += " srv1 testfiles/srv1.conf";
+		int pid = LaunchServer(cmd, "testfiles/srv1.pid");
 
 		TEST_THAT(pid != -1 && pid != 0);
 		if(pid > 0)
@@ -480,8 +482,10 @@
 	
 	// Launch a test forking server
 	{
-		int pid = LaunchServer("./test srv2 testfiles/srv2.conf", 
-			"testfiles/srv2.pid");
+		std::string cmd = "./test";
+		cmd += test_args;
+		cmd += " srv2 testfiles/srv2.conf";
+		int pid = LaunchServer(cmd, "testfiles/srv2.pid");
 
 		TEST_THAT(pid != -1 && pid != 0);
 
@@ -548,8 +552,10 @@
 
 	// Launch a test SSL server
 	{
-		int pid = LaunchServer("./test srv3 testfiles/srv3.conf",
-			"testfiles/srv3.pid");
+		std::string cmd = "./test";
+		cmd += test_args;
+		cmd += " srv3 testfiles/srv3.conf";
+		int pid = LaunchServer(cmd, "testfiles/srv3.pid");
 
 		TEST_THAT(pid != -1 && pid != 0);
 
@@ -627,8 +633,10 @@
 //protocolserver:
 	// Launch a test protocol handling server
 	{
-		int pid = LaunchServer("./test srv4 testfiles/srv4.conf", 
-			"testfiles/srv4.pid");
+		std::string cmd = "./test";
+		cmd += test_args;
+		cmd += " srv4 testfiles/srv4.conf";
+		int pid = LaunchServer(cmd, "testfiles/srv4.pid");
 
 		TEST_THAT(pid != -1 && pid != 0);
 


From boxbackup-dev@fluffy.co.uk  Tue Dec 18 00:15:14 2007
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Tue, 18 Dec 2007 00:15:14 +0000 (UTC)
Subject: [Box Backup-commit] COMMIT r2011 - box/trunk/infrastructure/m4
Message-ID: <20071218001514.4F42A326997@www.boxbackup.org>

Author: chris
Date: 2007-12-18 00:15:13 +0000 (Tue, 18 Dec 2007)
New Revision: 2011

Modified:
   box/trunk/infrastructure/m4/ax_check_dirent_d_type.m4
Log:
Stricter check for dirent.d_type validity (possible problems with
large file support resulting in reading the wrong part of the structure
on Slackware?)


Modified: box/trunk/infrastructure/m4/ax_check_dirent_d_type.m4
===================================================================
--- box/trunk/infrastructure/m4/ax_check_dirent_d_type.m4	2007-12-16 23:52:05 UTC (rev 2010)
+++ box/trunk/infrastructure/m4/ax_check_dirent_d_type.m4	2007-12-18 00:15:13 UTC (rev 2011)
@@ -24,7 +24,7 @@
           DIR* dir = opendir(".");
           struct dirent* res = NULL;
           if(dir) res = readdir(dir);
-          return res ? (res->d_type==DT_UNKNOWN) : 1;
+          return res ? (res->d_type != DT_FILE && res->d_type != DT_DIR) : 1;
         ]])],
         [have_valid_dirent_d_type=yes], [have_valid_dirent_d_type=no]
       )])


From boxbackup-dev@fluffy.co.uk  Tue Dec 18 00:17:54 2007
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Tue, 18 Dec 2007 00:17:54 +0000 (UTC)
Subject: [Box Backup-commit] COMMIT r2012 - in box/trunk: . lib/intercept
Message-ID: <20071218001754.7C3D832699B@www.boxbackup.org>

Author: chris
Date: 2007-12-18 00:17:54 +0000 (Tue, 18 Dec 2007)
New Revision: 2012

Modified:
   box/trunk/configure.ac
   box/trunk/lib/intercept/intercept.cpp
Log:
Search for readdir64 and stat64 if LARGE_FILE_SUPPORT is enabled, rather
than relying on Linux redirection macros that aren't present on
Slackware (which uses asm redirects instead).


Modified: box/trunk/configure.ac
===================================================================
--- box/trunk/configure.ac	2007-12-18 00:15:13 UTC (rev 2011)
+++ box/trunk/configure.ac	2007-12-18 00:17:54 UTC (rev 2012)
@@ -225,6 +225,11 @@
     [have_large_file_support=yes], [have_large_file_support=no]
   )])
 
+if test "x$have_large_file_support" = "xyes"; then
+	AC_DEFINE([HAVE_LARGE_FILE_SUPPORT], [1],
+		[Define to 1 if large files are supported])
+fi
+
 ## Find out how to do file locking
 AC_CHECK_FUNCS([flock])
 AC_CHECK_DECLS([O_EXLOCK],,, [[#include <fcntl.h>]])

Modified: box/trunk/lib/intercept/intercept.cpp
===================================================================
--- box/trunk/lib/intercept/intercept.cpp	2007-12-18 00:15:13 UTC (rev 2011)
+++ box/trunk/lib/intercept/intercept.cpp	2007-12-18 00:17:54 UTC (rev 2012)
@@ -457,7 +457,7 @@
 
 	if (readdir_real == NULL)
 	{
-		#if defined readdir && readdir == readdir64
+		#ifdef HAVE_LARGE_FILE_SUPPORT
 		readdir_real = (readdir_t*)find_function("readdir64");
 		#else
 		readdir_real = (readdir_t*)find_function("readdir");
@@ -506,13 +506,13 @@
 	if (lstat_real == NULL)
 	{
 	#ifdef LINUX_WEIRD_LSTAT
-		#if defined __lxstat && __lxstat == __lxstat64
+		#ifdef HAVE_LARGE_FILE_SUPPORT
 		lstat_real = (lstat_t*)find_function("__lxstat64");
 		#else
 		lstat_real = (lstat_t*)find_function("__lxstat");
 		#endif
 	#else
-		#if defined lstat && lstat == lstat64
+		#ifdef HAVE_LARGE_FILE_SUPPORT
 		lstat_real = (lstat_t*)find_function("lstat64");
 		#else
 		lstat_real = (lstat_t*)find_function("lstat");


From boxbackup-dev@fluffy.co.uk  Tue Dec 18 00:21:38 2007
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Tue, 18 Dec 2007 00:21:38 +0000 (UTC)
Subject: [Box Backup-commit] COMMIT r2014 - box/trunk/test/basicserver
Message-ID: <20071218002138.F2BDC3269A1@www.boxbackup.org>

Author: chris
Date: 2007-12-18 00:21:38 +0000 (Tue, 18 Dec 2007)
New Revision: 2014

Modified:
   box/trunk/test/basicserver/testbasicserver.cpp
Log:
Send data back from test daemon to test code, and wait for it to be
received in the test code, to avoid synchronisation issue where the
QUIT command appears to be part of the received data. Mostly harmless,
but gives a false alarm when viewing the test output.


Modified: box/trunk/test/basicserver/testbasicserver.cpp
===================================================================
--- box/trunk/test/basicserver/testbasicserver.cpp	2007-12-18 00:19:20 UTC (rev 2013)
+++ box/trunk/test/basicserver/testbasicserver.cpp	2007-12-18 00:21:38 UTC (rev 2014)
@@ -126,7 +126,26 @@
 					total += r;
 				}
 				TEST_THAT(total == LARGE_DATA_SIZE);
+				if (total != LARGE_DATA_SIZE)
+				{
+					BOX_ERROR("Expected " << 
+						LARGE_DATA_SIZE << " bytes " <<
+						"but was " << total);
+					return;
+				}
 			}
+			{
+				// Send lots of data again
+				char data[LARGE_DATA_BLOCK_SIZE];
+				for(unsigned int y = 0; y < sizeof(data); y++)
+				{
+					data[y] = y & 0xff;
+				}
+				for(int s = 0; s < (LARGE_DATA_SIZE / LARGE_DATA_BLOCK_SIZE); ++s)
+				{
+					rStream.Write(data, sizeof(data));
+				}
+			}
 			
 			// next!
 			continue;
@@ -345,6 +364,18 @@
 			conns[c]->Write(data, sizeof(data));
 		}
 	}
+	for(unsigned int c = 0; c < conns.size(); ++c)
+	{
+		// Receive lots of data again
+		char buf[1024];
+		int total = 0;
+		int r = 0;
+		while(total < LARGE_DATA_SIZE && (r = conns[c]->Read(buf, sizeof(buf))) != 0)
+		{
+			total += r;
+		}
+		TEST_THAT(total == LARGE_DATA_SIZE);
+	}
 
 	for(unsigned int c = 0; c < conns.size(); ++c)
 	{
@@ -407,27 +438,42 @@
 	// Server launching stuff
 	if(argc >= 2)
 	{
-		if(strcmp(argv[1], "srv1") == 0)
+		// this is a quick hack to allow passing some options
+		// to the daemon
+
+		const char* mode = argv[1];
+
+		if (test_args.length() > 0)
 		{
+			argv[1] = test_args.c_str();
+		}
+		else
+		{
+			argc--;
+			argv++;
+		}
+
+		if(strcmp(mode, "srv1") == 0)
+		{
 			// Run very basic daemon
 			basicdaemon daemon;
-			return daemon.Main("doesnotexist", argc - 1, argv + 1);
+			return daemon.Main("doesnotexist", argc, argv);
 		}
-		else if(strcmp(argv[1], "srv2") == 0)
+		else if(strcmp(mode, "srv2") == 0)
 		{
 			// Run daemon which accepts connections
 			testserver daemon;
-			return daemon.Main("doesnotexist", argc - 1, argv + 1);
+			return daemon.Main("doesnotexist", argc, argv);
 		}		
-		else if(strcmp(argv[1], "srv3") == 0)
+		else if(strcmp(mode, "srv3") == 0)
 		{
 			testTLSserver daemon;
-			return daemon.Main("doesnotexist", argc - 1, argv + 1);
+			return daemon.Main("doesnotexist", argc, argv);
 		}
-		else if(strcmp(argv[1], "srv4") == 0)
+		else if(strcmp(mode, "srv4") == 0)
 		{
 			testProtocolServer daemon;
-			return daemon.Main("doesnotexist", argc - 1, argv + 1);
+			return daemon.Main("doesnotexist", argc, argv);
 		}
 	}
 
@@ -436,7 +482,7 @@
 
 	// Launch a basic server
 	{
-		std::string cmd = "./test";
+		std::string cmd = "./test --test-daemon-args=";
 		cmd += test_args;
 		cmd += " srv1 testfiles/srv1.conf";
 		int pid = LaunchServer(cmd, "testfiles/srv1.pid");
@@ -482,7 +528,7 @@
 	
 	// Launch a test forking server
 	{
-		std::string cmd = "./test";
+		std::string cmd = "./test --test-daemon-args=";
 		cmd += test_args;
 		cmd += " srv2 testfiles/srv2.conf";
 		int pid = LaunchServer(cmd, "testfiles/srv2.pid");
@@ -552,7 +598,7 @@
 
 	// Launch a test SSL server
 	{
-		std::string cmd = "./test";
+		std::string cmd = "./test --test-daemon-args=";
 		cmd += test_args;
 		cmd += " srv3 testfiles/srv3.conf";
 		int pid = LaunchServer(cmd, "testfiles/srv3.pid");
@@ -633,7 +679,7 @@
 //protocolserver:
 	// Launch a test protocol handling server
 	{
-		std::string cmd = "./test";
+		std::string cmd = "./test --test-daemon-args=";
 		cmd += test_args;
 		cmd += " srv4 testfiles/srv4.conf";
 		int pid = LaunchServer(cmd, "testfiles/srv4.pid");


From boxbackup-dev@fluffy.co.uk  Tue Dec 18 00:19:20 2007
From: boxbackup-dev@fluffy.co.uk (boxbackup-dev@fluffy.co.uk)
Date: Tue, 18 Dec 2007 00:19:20 +0000 (UTC)
Subject: [Box Backup-commit] COMMIT r2013 - box/trunk/infrastructure
Message-ID: <20071218001920.A729632699F@www.boxbackup.org>

Author: chris
Date: 2007-12-18 00:19:20 +0000 (Tue, 18 Dec 2007)
New Revision: 2013

Modified:
   box/trunk/infrastructure/buildenv-testmain-template.cpp
Log:
Better way to pass arguments to test daemons, with --test-daemon-args.


Modified: box/trunk/infrastructure/buildenv-testmain-template.cpp
===================================================================
--- box/trunk/infrastructure/buildenv-testmain-template.cpp	2007-12-18 00:17:54 UTC (rev 2012)
+++ box/trunk/infrastructure/buildenv-testmain-template.cpp	2007-12-18 00:19:20 UTC (rev 2013)
@@ -164,12 +164,13 @@
 	{
 		{ "bbackupd-args",	required_argument, NULL, 'c' },
 		{ "bbstored-args",	required_argument, NULL, 's' },
+		{ "test-daemon-args",	required_argument, NULL, 'd' },
 		{ NULL,			0,                 NULL,  0  }
 	};
 	
 	int ch;
 	
-	while ((ch = getopt_long(argc, argv, "c:s:t:TU", longopts, NULL))
+	while ((ch = getopt_long(argc, argv, "c:d:s:t:TUV", longopts, NULL))
 		!= -1)
 	{
 		switch(ch)
@@ -184,6 +185,16 @@
 			}
 			break;
 
+			case 'd':
+			{
+				if (test_args.length() > 0)
+				{
+					test_args += " ";
+				}
+				test_args += optarg;
+			}
+			break;
+
 			case 's':
 			{
 				bbstored_args += " ";
@@ -194,16 +205,12 @@
 			case 't':
 			{
 				Console::SetTag(optarg);
-				test_args += " -t '";
-				test_args += optarg;
-				test_args += "'";
 			}
 			break;
 
 			case 'T':
 			{
 				Console::SetShowTime(true);
-				test_args += " -T";
 			}
 			break;
 
@@ -211,10 +218,15 @@
 			{
 				Console::SetShowTime(true);
 				Console::SetShowTimeMicros(true);
-				test_args += " -U";
 			}
 			break;
 
+			case 'V':
+			{
+				Logging::SetGlobalLevel(Log::EVERYTHING);
+			}
+			break;
+
 			case '?':
 			{
 				fprintf(stderr, "Unknown option: '%c'\n",


