[Box Backup-dev] COMMIT r580 - in box/chris/general: lib/common lib/server test/basicserver

boxbackup-dev@fluffy.co.uk boxbackup-dev@fluffy.co.uk
Sun, 21 May 2006 14:11:57 +0000 (GMT)


Author: chris
Date: 2006-05-21 14:11:18 +0000 (Sun, 21 May 2006)
New Revision: 580

Modified:
   box/chris/general/lib/common/Test.h
   box/chris/general/lib/server/Daemon.cpp
   box/chris/general/test/basicserver/testbasicserver.cpp
Log:
* lib/common/Test.h
- Fixed launching of server processes

* lib/server/Daemon.cpp
- Save PID file and open syslog on Windows

* test/basicserver/testbasicserver.cpp
- Fixed some wrong path separators on Windows


Modified: box/chris/general/lib/common/Test.h
===================================================================
--- box/chris/general/lib/common/Test.h	2006-05-21 12:57:42 UTC (rev 579)
+++ box/chris/general/lib/common/Test.h	2006-05-21 14:11:18 UTC (rev 580)
@@ -84,6 +84,15 @@
 #ifdef WIN32
 	PROCESS_INFORMATION procInfo;
 
+	STARTUPINFO startInfo;
+	startInfo.cb = sizeof(startInfo);
+	startInfo.lpReserved = NULL;
+	startInfo.lpDesktop  = NULL;
+	startInfo.lpTitle    = NULL;
+	startInfo.dwFlags = 0;
+	startInfo.cbReserved2 = 0;
+	startInfo.lpReserved2 = NULL;
+
 	CHAR* tempCmd = strdup(CommandLine);
 
 	DWORD result = CreateProcess
@@ -96,13 +105,13 @@
 		0,           // dwCreationFlags
 		NULL,        // lpEnvironment
 		NULL,        // lpCurrentDirectory
-		NULL,        // lpStartupInfo
+		&startInfo,  // lpStartupInfo
 		&procInfo    // lpProcessInformation
 	);
 
 	free(tempCmd);
 
-	if (result != 0)
+	if (result == 0)
 	{
 		DWORD err = GetLastError();
 		printf("Launch failed: %s: error %d\n", CommandLine, (int)err);

Modified: box/chris/general/lib/server/Daemon.cpp
===================================================================
--- box/chris/general/lib/server/Daemon.cpp	2006-05-21 12:57:42 UTC (rev 579)
+++ box/chris/general/lib/server/Daemon.cpp	2006-05-21 14:11:18 UTC (rev 580)
@@ -189,6 +189,7 @@
 		{
 			THROW_EXCEPTION(ServerException, DaemoniseFailed)
 		}
+#endif // !WIN32
 		
 		// Server configuration
 		const Configuration &serverConfig(
@@ -197,7 +198,8 @@
 		// Open PID file for writing
 		pidFileName = serverConfig.GetKeyValue("PidFile");
 		FileHandleGuard<(O_WRONLY | O_CREAT | O_TRUNC), (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)> pidFile(pidFileName.c_str());
-		
+	
+#ifndef WIN32	
 		// Handle changing to a different user
 		if(serverConfig.KeyExists("User"))
 		{
@@ -263,25 +265,29 @@
 				break;
 			}
 		}
+#endif // ! WIN32
 
 		// open the log
 		::openlog(DaemonName(), LOG_PID, LOG_LOCAL6);
-#endif // ! WIN32
 
 		// Log the start message
 		::syslog(LOG_INFO, "Starting daemon (config: %s) (version " 
 			BOX_VERSION ")", mConfigFileName.c_str());
 
-#ifndef WIN32
 		// Write PID to file
 		char pid[32];
+
+#ifdef WIN32
+		int pidsize = sprintf(pid, "%d", (int)GetCurrentProcessId());
+#else
 		int pidsize = sprintf(pid, "%d", (int)getpid());
+#endif
+
 		if(::write(pidFile, pid, pidsize) != pidsize)
 		{
 			::syslog(LOG_ERR, "can't write pid file");
 			THROW_EXCEPTION(ServerException, DaemoniseFailed)
 		}
-#endif
 		
 		// Set up memory leak reporting
 		#ifdef BOX_MEMORY_LEAK_TESTING

Modified: box/chris/general/test/basicserver/testbasicserver.cpp
===================================================================
--- box/chris/general/test/basicserver/testbasicserver.cpp	2006-05-21 12:57:42 UTC (rev 579)
+++ box/chris/general/test/basicserver/testbasicserver.cpp	2006-05-21 14:11:18 UTC (rev 580)
@@ -436,21 +436,37 @@
 
 	// Launch a basic server
 	{
-		int pid = LaunchServer("./test srv1 testfiles/srv1.conf", "testfiles/srv1.pid");
+#ifdef WIN32
+		int pid = LaunchServer("test srv1 testfiles\\srv1.conf", 
+			"testfiles\\srv1.pid");
+#else
+		int pid = LaunchServer("./test srv1 testfiles/srv1.conf", 
+			"testfiles/srv1.pid");
+#endif
+
 		TEST_THAT(pid != -1 && pid != 0);
 		if(pid > 0)
 		{
 			// Check that it's written the expected file
-			TEST_THAT(TestFileExists("testfiles/srv1.test1"));
+			TEST_THAT(TestFileExists("testfiles" 
+				DIRECTORY_SEPARATOR "srv1.test1"));
 			TEST_THAT(ServerIsAlive(pid));
 			// Move the config file over
-			TEST_THAT(::rename("testfiles/srv1b.conf", "testfiles/srv1.conf") != -1);
+#ifdef WIN32
+			TEST_THAT(::unlink("testfiles" DIRECTORY_SEPARATOR 
+				"srv1.conf") != -1);
+#endif
+			TEST_THAT(::rename(
+				"testfiles" DIRECTORY_SEPARATOR "srv1b.conf", 
+				"testfiles" DIRECTORY_SEPARATOR "srv1.conf") 
+				!= -1);
 			// Get it to reread the config file
 			TEST_THAT(HUPServer(pid));
 			::sleep(1);
 			TEST_THAT(ServerIsAlive(pid));
 			// Check that new file exists
-			TEST_THAT(TestFileExists("testfiles/srv1.test2"));
+			TEST_THAT(TestFileExists("testfiles" 
+				DIRECTORY_SEPARATOR "srv1.test2"));
 			// Kill it off
 			TEST_THAT(KillServer(pid));
 			TestRemoteProcessMemLeaks("generic-daemon.memleaks");
@@ -459,7 +475,14 @@
 	
 	// Launch a test forking server
 	{
-		int pid = LaunchServer("./test srv2 testfiles/srv2.conf", "testfiles/srv2.pid");
+#ifdef WIN32
+		int pid = LaunchServer("test srv2 testfiles\\srv2.conf", 
+			"testfiles\\srv2.pid");
+#else
+		int pid = LaunchServer("./test srv2 testfiles/srv2.conf", 
+			"testfiles/srv2.pid");
+#endif
+
 		TEST_THAT(pid != -1 && pid != 0);
 		if(pid > 0)
 		{