[Box Backup-dev] COMMIT r897 - box/chris/merge/lib/server

boxbackup-dev at fluffy.co.uk boxbackup-dev at fluffy.co.uk
Thu Aug 31 23:51:29 BST 2006


Author: chris
Date: 2006-08-31 23:51:29 +0100 (Thu, 31 Aug 2006)
New Revision: 897

Modified:
   box/chris/merge/lib/server/Daemon.cpp
Log:
Revert to trunk


Modified: box/chris/merge/lib/server/Daemon.cpp
===================================================================
--- box/chris/merge/lib/server/Daemon.cpp	2006-08-31 22:50:02 UTC (rev 896)
+++ box/chris/merge/lib/server/Daemon.cpp	2006-08-31 22:51:29 UTC (rev 897)
@@ -23,10 +23,6 @@
 	#include <syslog.h>
 #endif
 
-#ifdef WIN32
-	#include <ws2tcpip.h>
-#endif
-
 #include "Daemon.h"
 #include "Configuration.h"
 #include "ServerException.h"
@@ -146,7 +142,7 @@
 			{
 				fprintf(stderr, "%s: failed to start: "
 					"failed to open configuration file: "
-					"%s\n", DaemonName(), 
+					"%s", DaemonName(), 
 					mConfigFileName.c_str());
 #ifdef WIN32
 				::syslog(LOG_ERR, "%s: failed to start: "
@@ -193,7 +189,6 @@
 		{
 			THROW_EXCEPTION(ServerException, DaemoniseFailed)
 		}
-#endif // !WIN32
 		
 		// Server configuration
 		const Configuration &serverConfig(
@@ -202,8 +197,7 @@
 		// 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"))
 		{
@@ -273,25 +267,20 @@
 
 		// open the log
 		::openlog(DaemonName(), LOG_PID, LOG_LOCAL6);
-
 		// 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
@@ -363,22 +352,6 @@
 #endif
 		return 1;
 	}
-
-#ifdef WIN32
-	// Under win32 we must initialise the Winsock library
-	// before using sockets
-
-	WSADATA info;
-
-	if (WSAStartup(0x0101, &info) == SOCKET_ERROR)
-	{
-		// will not run without sockets
-		::syslog(LOG_ERR, "Failed to initialise Windows Sockets");
-		THROW_EXCEPTION(CommonException, Internal)
-	}
-#endif
-
-	int retcode = 0;
 	
 	// Main Daemon running
 	try
@@ -408,8 +381,7 @@
 						mConfigFileName.c_str(),
 						errors.c_str());
 					// And give up
-					retcode = 1;
-					break;
+					return 1;
 				}
 				
 				// delete old configuration
@@ -437,26 +409,22 @@
 		::syslog(LOG_ERR, "%s: terminating due to exception %s "
 			"(%d/%d)", DaemonName(), e.what(), e.GetType(), 
 			e.GetSubType());
-		retcode = 1;
+		return 1;
 	}
 	catch(std::exception &e)
 	{
 		::syslog(LOG_ERR, "%s: terminating due to exception %s", 
 			DaemonName(), e.what());
-		retcode = 1;
+		return 1;
 	}
 	catch(...)
 	{
 		::syslog(LOG_ERR, "%s: terminating due to unknown exception",
 			DaemonName());
-		retcode = 1;
+		return 1;
 	}
-
-#ifdef WIN32
-	WSACleanup();
-#endif
 	
-	return retcode;
+	return 0;
 }
 
 // --------------------------------------------------------------------------




More information about the Boxbackup-dev mailing list