[Box Backup-dev] COMMIT r376 - box/chris/win32/vc2005-compile-fixes/lib/server

boxbackup-dev at fluffy.co.uk boxbackup-dev at fluffy.co.uk
Sat Feb 4 13:31:17 GMT 2006


Author: chris
Date: 2006-02-04 13:31:14 +0000 (Sat, 04 Feb 2006)
New Revision: 376

Modified:
   box/chris/win32/vc2005-compile-fixes/lib/server/Daemon.cpp
Log:
* Daemon.cpp
- Catch failure to open the configuration file and log a better error message
- Log all startup exceptions to syslog on win32
- Reformatted log messages to be more readable


Modified: box/chris/win32/vc2005-compile-fixes/lib/server/Daemon.cpp
===================================================================
--- box/chris/win32/vc2005-compile-fixes/lib/server/Daemon.cpp	2006-02-04 13:29:22 UTC (rev 375)
+++ box/chris/win32/vc2005-compile-fixes/lib/server/Daemon.cpp	2006-02-04 13:31:14 UTC (rev 376)
@@ -127,11 +127,35 @@
 
 		// Load the configuration file.
 		std::string errors;
-		std::auto_ptr<Configuration> pconfig = 
-			Configuration::LoadAndVerify(
+		std::auto_ptr<Configuration> pconfig;
+
+		try
+		{
+			pconfig = Configuration::LoadAndVerify(
 				mConfigFileName.c_str(), 
 				GetConfigVerify(), errors);
+		}
+		catch(BoxException &e)
+		{
+			if(e.GetType() == CommonException::ExceptionType &&
+				e.GetSubType() == CommonException::OSFileOpenError)
+			{
+				fprintf(stderr, "%s: failed to start: "
+					"failed to open configuration file: "
+					"%s", DaemonName(), 
+					mConfigFileName.c_str());
+#ifdef WIN32
+				::syslog(LOG_ERR, "%s: failed to start: "
+					"failed to open configuration file: "
+					"%s", DaemonName(), 
+					mConfigFileName.c_str());
+#endif
+				return 1;
+			}
 
+			throw;
+		}
+
 		// Got errors?
 		if(pconfig.get() == 0 || !errors.empty())
 		{
@@ -139,6 +163,11 @@
 			fprintf(stderr, "%s: Errors in config file %s:\n%s", 
 				DaemonName(), mConfigFileName.c_str(), 
 				errors.c_str());
+#ifdef WIN32
+			::syslog(LOG_ERR, "%s: Errors in config file %s:\n%s",
+				DaemonName(), mConfigFileName.c_str(), 
+				errors.c_str());
+#endif
 			// And give up
 			return 1;
 		}
@@ -147,9 +176,6 @@
 		mpConfiguration = pconfig.release();
 		mLoadedConfigModifiedTime = GetConfigFileModifiedTime();
 		
-		// Server configuration
-		const Configuration &serverConfig(mpConfiguration->GetSubConfiguration("Server"));
-		
 		// Let the derived class have a go at setting up stuff in the initial process
 		SetupInInitialProcess();
 		
@@ -164,6 +190,10 @@
 			THROW_EXCEPTION(ServerException, DaemoniseFailed)
 		}
 		
+		// Server configuration
+		const Configuration &serverConfig(
+			mpConfiguration->GetSubConfiguration("Server"));
+
 		// 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());
@@ -293,17 +323,33 @@
 	}
 	catch(BoxException &e)
 	{
-		fprintf(stderr, "%s: exception %s (%d/%d)\n", DaemonName(), e.what(), e.GetType(), e.GetSubType());
+		fprintf(stderr, "%s: failed to start: exception %s (%d/%d)\n", 
+			DaemonName(), e.what(), e.GetType(), e.GetSubType());
+#ifdef WIN32
+		::syslog(LOG_ERR, "%s: failed to start: "
+			"exception %s (%d/%d)\n", DaemonName(), 
+			e.what(), e.GetType(), e.GetSubType());
+#endif
 		return 1;
 	}
 	catch(std::exception &e)
 	{
-		fprintf(stderr, "%s: exception %s\n", DaemonName(), e.what());
+		fprintf(stderr, "%s: failed to start: exception %s\n", 
+			DaemonName(), e.what());
+#ifdef WIN32
+		::syslog(LOG_ERR, "%s: failed to start: exception %s\n", 
+			DaemonName(), e.what());
+#endif
 		return 1;
 	}
 	catch(...)
 	{
-		fprintf(stderr, "%s: unknown exception\n", DaemonName());
+		fprintf(stderr, "%s: failed to start: unknown exception\n", 
+			DaemonName());
+#ifdef WIN32
+		::syslog(LOG_ERR, "%s: failed to start: unknown exception\n", 
+			DaemonName());
+#endif
 		return 1;
 	}
 	
@@ -360,17 +406,21 @@
 	}
 	catch(BoxException &e)
 	{
-		::syslog(LOG_ERR, "exception %s (%d/%d) -- terminating", e.what(), e.GetType(), e.GetSubType());
+		::syslog(LOG_ERR, "%s: terminating due to exception %s "
+			"(%d/%d)", DaemonName(), e.what(), e.GetType(), 
+			e.GetSubType());
 		return 1;
 	}
 	catch(std::exception &e)
 	{
-		::syslog(LOG_ERR, "exception %s -- terminating", e.what());
+		::syslog(LOG_ERR, "%s: terminating due to exception %s", 
+			DaemonName(), e.what());
 		return 1;
 	}
 	catch(...)
 	{
-		::syslog(LOG_ERR, "unknown exception -- terminating");
+		::syslog(LOG_ERR, "%s: terminating due to unknown exception",
+			DaemonName());
 		return 1;
 	}
 	




More information about the Boxbackup-dev mailing list