From 53ef33b388fdfebf13c98d4a264715fff390c948 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Thu, 31 Aug 2006 22:51:29 +0000 Subject: Revert to trunk --- lib/server/Daemon.cpp | 50 +++++++++----------------------------------------- 1 file changed, 9 insertions(+), 41 deletions(-) diff --git a/lib/server/Daemon.cpp b/lib/server/Daemon.cpp index 2131bdcb..2f902473 100644 --- a/lib/server/Daemon.cpp +++ b/lib/server/Daemon.cpp @@ -23,10 +23,6 @@ #include #endif -#ifdef WIN32 - #include -#endif - #include "Daemon.h" #include "Configuration.h" #include "ServerException.h" @@ -146,7 +142,7 @@ int Daemon::Main(const char *DefaultConfigFile, int argc, const char *argv[]) { 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 @@ int Daemon::Main(const char *DefaultConfigFile, int argc, const char *argv[]) { THROW_EXCEPTION(ServerException, DaemoniseFailed) } -#endif // !WIN32 // Server configuration const Configuration &serverConfig( @@ -202,8 +197,7 @@ int Daemon::Main(const char *DefaultConfigFile, int argc, const char *argv[]) // 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 @@ int Daemon::Main(const char *DefaultConfigFile, int argc, const char *argv[]) // 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 @@ int Daemon::Main(const char *DefaultConfigFile, int argc, const char *argv[]) #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 @@ int Daemon::Main(const char *DefaultConfigFile, int argc, const char *argv[]) mConfigFileName.c_str(), errors.c_str()); // And give up - retcode = 1; - break; + return 1; } // delete old configuration @@ -437,26 +409,22 @@ int Daemon::Main(const char *DefaultConfigFile, int argc, const char *argv[]) ::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; } // -------------------------------------------------------------------------- -- cgit v1.2.3