summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorChris Wilson <chris+github@qwirx.com>2015-12-24 16:04:05 +0000
committerChris Wilson <chris+github@qwirx.com>2015-12-24 16:04:05 +0000
commit429ad54fb3619360ec138473a04f127454aef713 (patch)
tree0e392b3926dc038776cd7259ba7f996c5f4f86ef /lib
parent10816862330aac6305229ea2e71d171b908ae0b9 (diff)
Throw an exception if we try to openlog() without closelog() first on Windows.
Use INVALID_HANDLE_VALUE for invalid handle values, instead of 0.
Diffstat (limited to 'lib')
-rw-r--r--lib/win32/emu.cpp19
1 files changed, 14 insertions, 5 deletions
diff --git a/lib/win32/emu.cpp b/lib/win32/emu.cpp
index 1479c8b4..18624eeb 100644
--- a/lib/win32/emu.cpp
+++ b/lib/win32/emu.cpp
@@ -1422,7 +1422,7 @@ BOOL AddEventSource
return TRUE;
}
-static HANDLE gSyslogH = 0;
+static HANDLE gSyslogH = INVALID_HANDLE_VALUE;
static bool sHaveWarnedEventLogFull = false;
void openlog(const char * daemonName, int, int)
@@ -1431,13 +1431,18 @@ void openlog(const char * daemonName, int, int)
nameStr += daemonName;
nameStr += ")";
- // register a default event source, so that we can
- // log errors with the process of adding or registering our own.
+ // Don't try to open a new handle when one is already open. It will leak handles.
+ assert(gSyslogH == INVALID_HANDLE_VALUE);
+
+ // Register a default event source, so that we can log errors with the process of
+ // adding or registering our own, which follows. If this fails, there's not much we
+ // can do about it, certainly not send anything to the event log!
gSyslogH = RegisterEventSource(
NULL, // uses local computer
nameStr.c_str()); // source name
if (gSyslogH == NULL)
{
+ gSyslogH = INVALID_HANDLE_VALUE;
}
char* name = strdup(nameStr.c_str());
@@ -1465,7 +1470,11 @@ void openlog(const char * daemonName, int, int)
void closelog(void)
{
- DeregisterEventSource(gSyslogH);
+ if(gSyslogH != INVALID_HANDLE_VALUE)
+ {
+ DeregisterEventSource(gSyslogH);
+ gSyslogH = INVALID_HANDLE_VALUE;
+ }
}
void syslog(int loglevel, const char *frmt, ...)
@@ -1520,7 +1529,7 @@ void syslog(int loglevel, const char *frmt, ...)
va_end(args);
- if (gSyslogH == 0)
+ if (gSyslogH == INVALID_HANDLE_VALUE)
{
printf("%s\r\n", buffer);
fflush(stdout);