summaryrefslogtreecommitdiff
path: root/lib/server
diff options
context:
space:
mode:
authorChris Wilson <chris+github@qwirx.com>2007-07-31 23:18:05 +0000
committerChris Wilson <chris+github@qwirx.com>2007-07-31 23:18:05 +0000
commit0b2fd98dd63c533e00c0d61ce022f37ee75857cc (patch)
tree5daa2a50b28b572e01281b622fee3adf818f5075 /lib/server
parent05db569d4efc62eaa10597142b8eac4937421e14 (diff)
Replace almost all calls to syslog() with logging framework. (refs #3)
Diffstat (limited to 'lib/server')
-rw-r--r--lib/server/Daemon.cpp7
-rw-r--r--lib/server/LocalProcessStream.cpp8
-rw-r--r--lib/server/SSLLib.cpp13
-rw-r--r--lib/server/ServerStream.h16
-rw-r--r--lib/server/Socket.cpp9
-rw-r--r--lib/server/WinNamedPipeStream.cpp89
6 files changed, 64 insertions, 78 deletions
diff --git a/lib/server/Daemon.cpp b/lib/server/Daemon.cpp
index 147eeb24..a9eb5bf5 100644
--- a/lib/server/Daemon.cpp
+++ b/lib/server/Daemon.cpp
@@ -19,10 +19,6 @@
#include <string.h>
#include <stdarg.h>
-#ifdef HAVE_SYSLOG_H
- #include <syslog.h>
-#endif
-
#ifdef WIN32
#include <ws2tcpip.h>
#endif
@@ -353,7 +349,8 @@ int Daemon::Main(const std::string &rConfigFileName)
// Set new session
if(::setsid() == -1)
{
- ::syslog(LOG_ERR, "can't setsid");
+ BOX_ERROR("Failed to setsid(): " <<
+ strerror(errno));
THROW_EXCEPTION(ServerException, DaemoniseFailed)
}
diff --git a/lib/server/LocalProcessStream.cpp b/lib/server/LocalProcessStream.cpp
index fef7166b..9750aca1 100644
--- a/lib/server/LocalProcessStream.cpp
+++ b/lib/server/LocalProcessStream.cpp
@@ -120,8 +120,8 @@ std::auto_ptr<IOStream> LocalProcessStream(const char *CommandLine, pid_t &rPidO
HANDLE writeInChild, readFromChild;
if(!CreatePipe(&readFromChild, &writeInChild, &secAttr, 0))
{
- ::syslog(LOG_ERR, "Failed to CreatePipe for child process: "
- "error %d", GetLastError());
+ BOX_ERROR("Failed to CreatePipe for child process: "
+ GetErrorMessage(GetLastError()));
THROW_EXCEPTION(ServerException, SocketPairFailed)
}
SetHandleInformation(readFromChild, HANDLE_FLAG_INHERIT, 0);
@@ -155,8 +155,8 @@ std::auto_ptr<IOStream> LocalProcessStream(const char *CommandLine, pid_t &rPidO
if(!result)
{
- ::syslog(LOG_ERR, "Failed to CreateProcess: '%s': "
- "error %d", CommandLine, GetLastError());
+ BOX_ERROR("Failed to CreateProcess: '" << CommandLine <<
+ "': " << GetErrorMessage(GetLastError()));
CloseHandle(writeInChild);
CloseHandle(readFromChild);
THROW_EXCEPTION(ServerException, ServerForkError)
diff --git a/lib/server/SSLLib.cpp b/lib/server/SSLLib.cpp
index 2a5bdbde..6082a9f4 100644
--- a/lib/server/SSLLib.cpp
+++ b/lib/server/SSLLib.cpp
@@ -14,10 +14,6 @@
#include <openssl/err.h>
#include <openssl/rand.h>
-#ifndef WIN32
-#include <syslog.h>
-#endif
-
#include "SSLLib.h"
#include "ServerException.h"
@@ -73,13 +69,8 @@ void SSLLib::LogError(const char *ErrorDuringAction)
while((errcode = ERR_get_error()) != 0)
{
::ERR_error_string_n(errcode, errname, sizeof(errname));
- #ifndef NDEBUG
- if(SSLLib__TraceErrors)
- {
- TRACE2("SSL err during %s: %s\n", ErrorDuringAction, errname);
- }
- #endif
- ::syslog(LOG_ERR, "SSL err during %s: %s", ErrorDuringAction, errname);
+ BOX_ERROR("SSL error during " << ErrorDuringAction << ": " <<
+ errname);
}
}
diff --git a/lib/server/ServerStream.h b/lib/server/ServerStream.h
index 7eb99d13..5f615336 100644
--- a/lib/server/ServerStream.h
+++ b/lib/server/ServerStream.h
@@ -14,7 +14,6 @@
#include <errno.h>
#ifndef WIN32
- #include <syslog.h>
#include <sys/wait.h>
#endif
@@ -73,7 +72,10 @@ public:
{
if(childExit)
{
- ::syslog(LOG_ERR, "in server child, exception %s (%d/%d) -- terminating child", e.what(), e.GetType(), e.GetSubType());
+ BOX_ERROR("Error in child process, "
+ "terminating connection: exception " <<
+ e.what() << "(" << e.GetType() <<
+ "/" << e.GetSubType() << ")");
_exit(1);
}
else throw;
@@ -82,7 +84,9 @@ public:
{
if(childExit)
{
- ::syslog(LOG_ERR, "in server child, exception %s -- terminating child", e.what());
+ BOX_ERROR("Error in child process, "
+ "terminating connection: exception " <<
+ e.what());
_exit(1);
}
else throw;
@@ -91,7 +95,9 @@ public:
{
if(childExit)
{
- ::syslog(LOG_ERR, "in server child, unknown exception -- terminating child");
+ BOX_ERROR("Error in child process, "
+ "terminating connection: "
+ "unknown exception");
_exit(1);
}
else throw;
@@ -266,7 +272,7 @@ public:
}
// Log it
- ::syslog(LOG_INFO, "%s (handling in child %d)", logMessage.c_str(), pid);
+ BOX_WARNING("Error message from child process " << pid << ": " << logMessage);
}
else
{
diff --git a/lib/server/Socket.cpp b/lib/server/Socket.cpp
index afed4888..28dae69f 100644
--- a/lib/server/Socket.cpp
+++ b/lib/server/Socket.cpp
@@ -17,7 +17,6 @@
#ifndef WIN32
#include <sys/socket.h>
#include <netdb.h>
-#include <syslog.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#endif
@@ -124,18 +123,20 @@ void Socket::LogIncomingConnection(const struct sockaddr *addr, socklen_t addrle
switch(addr->sa_family)
{
case AF_UNIX:
- ::syslog(LOG_INFO, "Incoming connection from local (UNIX socket)");
+ BOX_INFO("Incoming connection from local (UNIX socket)");
break;
case AF_INET:
{
sockaddr_in *a = (sockaddr_in*)addr;
- ::syslog(LOG_INFO, "Incoming connection from %s port %d", inet_ntoa(a->sin_addr), ntohs(a->sin_port));
+ BOX_INFO("Incoming connection from " <<
+ inet_ntoa(a->sin_addr) << " port " <<
+ ntohs(a->sin_port));
}
break;
default:
- ::syslog(LOG_INFO, "Incoming connection of unknown type");
+ BOX_WARNING("Incoming connection of unknown type");
break;
}
}
diff --git a/lib/server/WinNamedPipeStream.cpp b/lib/server/WinNamedPipeStream.cpp
index 32ae42f2..d7e90793 100644
--- a/lib/server/WinNamedPipeStream.cpp
+++ b/lib/server/WinNamedPipeStream.cpp
@@ -63,8 +63,8 @@ WinNamedPipeStream::~WinNamedPipeStream()
}
catch (std::exception &e)
{
- ::syslog(LOG_ERR, "Caught exception while destroying "
- "named pipe, ignored.");
+ BOX_ERROR("Caught exception while destroying "
+ "named pipe, ignored: " << e.what());
}
}
}
@@ -100,8 +100,8 @@ void WinNamedPipeStream::Accept(const wchar_t* pName)
if (mSocketHandle == INVALID_HANDLE_VALUE)
{
- ::syslog(LOG_ERR, "CreateNamedPipeW failed: %s",
- GetErrorMessage(GetLastError()).c_str());
+ BOX_ERROR("Failed to CreateNamedPipeW(" << pName << "): " <<
+ GetErrorMessage(GetLastError()));
THROW_EXCEPTION(ServerException, SocketOpenError)
}
@@ -109,8 +109,8 @@ void WinNamedPipeStream::Accept(const wchar_t* pName)
if (!connected)
{
- ::syslog(LOG_ERR, "ConnectNamedPipe failed: %s",
- GetErrorMessage(GetLastError()).c_str());
+ BOX_ERROR("Failed to ConnectNamedPipe(" << pName << "): " <<
+ GetErrorMessage(GetLastError()));
Close();
THROW_EXCEPTION(ServerException, SocketOpenError)
}
@@ -126,8 +126,8 @@ void WinNamedPipeStream::Accept(const wchar_t* pName)
if (mReadableEvent == INVALID_HANDLE_VALUE)
{
- ::syslog(LOG_ERR, "Failed to create the Readable event: %s",
- GetErrorMessage(GetLastError()).c_str());
+ BOX_ERROR("Failed to create the Readable event: " <<
+ GetErrorMessage(GetLastError()));
Close();
THROW_EXCEPTION(CommonException, Internal)
}
@@ -144,8 +144,8 @@ void WinNamedPipeStream::Accept(const wchar_t* pName)
if (err != ERROR_IO_PENDING)
{
- ::syslog(LOG_ERR, "Failed to start overlapped read: "
- "%s", GetErrorMessage(err).c_str());
+ BOX_ERROR("Failed to start overlapped read: " <<
+ GetErrorMessage(err));
Close();
THROW_EXCEPTION(ConnectionException,
Conn_SocketReadError)
@@ -183,13 +183,13 @@ void WinNamedPipeStream::Connect(const wchar_t* pName)
DWORD err = GetLastError();
if (err == ERROR_PIPE_BUSY)
{
- ::syslog(LOG_ERR, "Failed to connect to backup "
- "daemon: it is busy with another connection");
+ BOX_ERROR("Failed to connect to backup daemon: "
+ "it is busy with another connection");
}
else
{
- ::syslog(LOG_ERR, "Failed to connect to backup "
- "daemon: %s", GetErrorMessage(err).c_str());
+ BOX_ERROR("Failed to connect to backup daemon: " <<
+ GetErrorMessage(err));
}
THROW_EXCEPTION(ServerException, SocketOpenError)
}
@@ -261,16 +261,14 @@ int WinNamedPipeStream::Read(void *pBuffer, int NBytes, int Timeout)
{
if (err == ERROR_BROKEN_PIPE)
{
- ::syslog(LOG_ERR, "Control "
- "client disconnected");
+ BOX_ERROR("Control client "
+ "disconnected");
}
else
{
- ::syslog(LOG_ERR,
- "Failed to wait for "
+ BOX_ERROR("Failed to wait for "
"ReadFile to complete: "
- "%s",
- GetErrorMessage(err).c_str());
+ << GetErrorMessage(err));
}
Close();
@@ -326,15 +324,13 @@ int WinNamedPipeStream::Read(void *pBuffer, int NBytes, int Timeout)
}
else if (err == ERROR_BROKEN_PIPE)
{
- ::syslog(LOG_ERR,
- "Control client disconnected");
+ BOX_ERROR("Control client disconnected");
mReadClosed = true;
}
else
{
- ::syslog(LOG_ERR, "Failed to start "
- "overlapped read: %s",
- GetErrorMessage(err).c_str());
+ BOX_ERROR("Failed to start overlapped read: "
+ << GetErrorMessage(err));
Close();
THROW_EXCEPTION(ConnectionException,
Conn_SocketReadError)
@@ -387,9 +383,8 @@ int WinNamedPipeStream::Read(void *pBuffer, int NBytes, int Timeout)
}
else
{
- ::syslog(LOG_ERR, "Failed to read from "
- "control socket: %s",
- GetErrorMessage(err).c_str());
+ BOX_ERROR("Failed to read from control socket: "
+ << GetErrorMessage(err));
THROW_EXCEPTION(ConnectionException,
Conn_SocketReadError)
}
@@ -440,8 +435,8 @@ void WinNamedPipeStream::Write(const void *pBuffer, int NBytes)
if (!Success)
{
DWORD err = GetLastError();
- ::syslog(LOG_ERR, "Failed to write to control socket: "
- "%s", GetErrorMessage(err).c_str());
+ BOX_ERROR("Failed to write to control socket: " <<
+ GetErrorMessage(err));
Close();
// ERROR_NO_DATA is a strange name for
@@ -474,8 +469,7 @@ void WinNamedPipeStream::Close()
{
if (mSocketHandle == INVALID_HANDLE_VALUE && mIsConnected)
{
- fprintf(stderr, "Inconsistent connected state\n");
- ::syslog(LOG_ERR, "Inconsistent connected state");
+ BOX_ERROR("Named pipe: inconsistent connected state");
mIsConnected = false;
}
@@ -488,29 +482,27 @@ void WinNamedPipeStream::Close()
{
if (!CancelIo(mSocketHandle))
{
- ::syslog(LOG_ERR, "Failed to cancel outstanding "
- "I/O: %s",
- GetErrorMessage(GetLastError()).c_str());
+ BOX_ERROR("Failed to cancel outstanding I/O: " <<
+ GetErrorMessage(GetLastError()));
}
if (mReadableEvent == INVALID_HANDLE_VALUE)
{
- ::syslog(LOG_ERR, "Failed to destroy Readable "
- "event: invalid handle");
+ BOX_ERROR("Failed to destroy Readable event: "
+ "invalid handle");
}
else if (!CloseHandle(mReadableEvent))
{
- ::syslog(LOG_ERR, "Failed to destroy Readable "
- "event: %s",
- GetErrorMessage(GetLastError()).c_str());
+ BOX_ERROR("Failed to destroy Readable event: " <<
+ GetErrorMessage(GetLastError()));
}
mReadableEvent = INVALID_HANDLE_VALUE;
if (!FlushFileBuffers(mSocketHandle))
{
- ::syslog(LOG_INFO, "FlushFileBuffers failed: %s",
- GetErrorMessage(GetLastError()).c_str());
+ BOX_ERROR("Failed to FlushFileBuffers: " <<
+ GetErrorMessage(GetLastError()));
}
if (!DisconnectNamedPipe(mSocketHandle))
@@ -518,9 +510,8 @@ void WinNamedPipeStream::Close()
DWORD err = GetLastError();
if (err != ERROR_PIPE_NOT_CONNECTED)
{
- ::syslog(LOG_ERR, "DisconnectNamedPipe "
- "failed: %s",
- GetErrorMessage(err).c_str());
+ BOX_ERROR("Failed to DisconnectNamedPipe: " <<
+ GetErrorMessage(err));
}
}
@@ -536,8 +527,8 @@ void WinNamedPipeStream::Close()
if (!result)
{
- ::syslog(LOG_ERR, "CloseHandle failed: %s",
- GetErrorMessage(GetLastError()).c_str());
+ BOX_ERROR("Failed to CloseHandle: " <<
+ GetErrorMessage(GetLastError()));
THROW_EXCEPTION(ServerException, SocketCloseError)
}
}
@@ -585,8 +576,8 @@ void WinNamedPipeStream::WriteAllBuffered()
if (!FlushFileBuffers(mSocketHandle))
{
- ::syslog(LOG_WARNING, "FlushFileBuffers failed: %s",
- GetErrorMessage(GetLastError()).c_str());
+ BOX_ERROR("Failed to FlushFileBuffers: " <<
+ GetErrorMessage(GetLastError()));
}
}