diff options
author | Ben Summers <ben@fluffy.co.uk> | 2006-02-13 13:30:21 +0000 |
---|---|---|
committer | Ben Summers <ben@fluffy.co.uk> | 2006-02-13 13:30:21 +0000 |
commit | 830aa82e44381c85d8486e46de7ae0e26830457e (patch) | |
tree | f29edb3c3013990a3ae758e1ccfdb56a2d20923f /lib/server | |
parent | 2edd0a00e3244cc4dbc369d81ed1748768a06fb8 (diff) |
Merge chris/win32/vc2005-compile-fixes @ r455, add infrastructure/msvc to distribution
Diffstat (limited to 'lib/server')
-rw-r--r-- | lib/server/Daemon.cpp | 77 | ||||
-rw-r--r-- | lib/server/LocalProcessStream.cpp | 9 | ||||
-rw-r--r-- | lib/server/Socket.cpp | 5 | ||||
-rw-r--r-- | lib/server/SocketListen.h | 5 | ||||
-rw-r--r-- | lib/server/SocketStream.cpp | 5 |
5 files changed, 83 insertions, 18 deletions
diff --git a/lib/server/Daemon.cpp b/lib/server/Daemon.cpp index 9c820b22..2f902473 100644 --- a/lib/server/Daemon.cpp +++ b/lib/server/Daemon.cpp @@ -9,9 +9,12 @@ #include "Box.h" +#ifdef HAVE_UNISTD_H + #include <unistd.h> +#endif + #include <errno.h> #include <stdio.h> -#include <unistd.h> #include <signal.h> #include <string.h> #include <stdarg.h> @@ -124,10 +127,34 @@ int Daemon::Main(const char *DefaultConfigFile, int argc, const char *argv[]) // 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()) @@ -136,6 +163,11 @@ int Daemon::Main(const char *DefaultConfigFile, int argc, const char *argv[]) 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; } @@ -144,9 +176,6 @@ int Daemon::Main(const char *DefaultConfigFile, int argc, const char *argv[]) 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(); @@ -161,6 +190,10 @@ int Daemon::Main(const char *DefaultConfigFile, int argc, const char *argv[]) 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()); @@ -290,17 +323,33 @@ int Daemon::Main(const char *DefaultConfigFile, int argc, const char *argv[]) } 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; } @@ -357,17 +406,21 @@ int Daemon::Main(const char *DefaultConfigFile, int argc, const char *argv[]) } 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; } diff --git a/lib/server/LocalProcessStream.cpp b/lib/server/LocalProcessStream.cpp index 0de7bef4..f1b6b2b8 100644 --- a/lib/server/LocalProcessStream.cpp +++ b/lib/server/LocalProcessStream.cpp @@ -9,10 +9,13 @@ #include "Box.h" -#ifndef WIN32 -#include <sys/socket.h> +#ifdef HAVE_SYS_SOCKET_H + #include <sys/socket.h> +#endif + +#ifdef HAVE_UNISTD_H + #include <unistd.h> #endif -#include <unistd.h> #include "LocalProcessStream.h" #include "SocketStream.h" diff --git a/lib/server/Socket.cpp b/lib/server/Socket.cpp index 0343b8bf..afed4888 100644 --- a/lib/server/Socket.cpp +++ b/lib/server/Socket.cpp @@ -9,7 +9,10 @@ #include "Box.h" -#include <unistd.h> +#ifdef HAVE_UNISTD_H + #include <unistd.h> +#endif + #include <sys/types.h> #ifndef WIN32 #include <sys/socket.h> diff --git a/lib/server/SocketListen.h b/lib/server/SocketListen.h index d954339a..ff08fb8f 100644 --- a/lib/server/SocketListen.h +++ b/lib/server/SocketListen.h @@ -11,7 +11,10 @@ #define SOCKETLISTEN__H #include <errno.h> -#include <unistd.h> + +#ifdef HAVE_UNISTD_H + #include <unistd.h> +#endif #ifdef HAVE_KQUEUE #include <sys/event.h> diff --git a/lib/server/SocketStream.cpp b/lib/server/SocketStream.cpp index 6719fcde..2c704b8b 100644 --- a/lib/server/SocketStream.cpp +++ b/lib/server/SocketStream.cpp @@ -9,7 +9,10 @@ #include "Box.h" -#include <unistd.h> +#ifdef HAVE_UNISTD_H + #include <unistd.h> +#endif + #include <sys/types.h> #include <errno.h> |