}
-/* For apcupsd this is in src/lib/wincompat.c */
+/*
+ * Write in Windows System log
+ */
extern "C" void syslog(int type, const char *fmt, ...)
{
-/*#ifndef HAVE_CONSOLE
- MessageBox(NULL, msg, "Bacula", MB_OK);
-#endif*/
+ va_list arg_ptr;
+ int len, maxlen;
+ POOLMEM *msg;
+
+ msg = get_pool_memory(PM_EMSG);
+
+ for (;;) {
+ maxlen = sizeof_pool_memory(msg) - 1;
+ va_start(arg_ptr, fmt);
+ len = bvsnprintf(msg, maxlen, fmt, arg_ptr);
+ va_end(arg_ptr);
+ if (len < 0 || len >= (maxlen-5)) {
+ msg = realloc_pool_memory(msg, maxlen + maxlen/2);
+ continue;
+ }
+ break;
+ }
+ LogErrorMsg((const char *)msg);
+ free_memory(msg);
}
void
/* syslog function, added by Nicolas Boichat */
void openlog(const char *ident, int option, int facility) {}
#endif //HAVE_MINGW
+
+/* Log an error message */
+void LogErrorMsg(const char *message)
+{
+ HANDLE eventHandler;
+ const char *strings[2];
+
+ /* Use the OS event logging to log the error */
+ eventHandler = RegisterEventSource(NULL, "Bacula");
+
+ strings[0] = _("\n\nBacula ERROR: ");
+ strings[1] = message;
+
+ if (eventHandler) {
+ ReportEvent(eventHandler, EVENTLOG_ERROR_TYPE,
+ 0, /* category */
+ 0, /* ID */
+ NULL, /* SID */
+ 2, /* Number of strings */
+ 0, /* raw data size */
+ (const char **)strings, /* error strings */
+ NULL); /* raw data */
+ DeregisterEventSource(eventHandler);
+ }
+}
* Version $Id$
*/
-#define log_error_message(msg) LogErrorMsg((msg), __FILE__, __LINE__)
+#define log_error_message(msg) LogLastErrorMsg((msg), __FILE__, __LINE__)
extern int BaculaAppMain();
-extern void LogErrorMsg(const char *msg, const char *fname, int lineno);
+extern void LogLastErrorMsg(const char *msg, const char *fname, int lineno);
extern int BaculaMain(int argc, char *argv[]);
extern BOOL ReportStatus(DWORD state, DWORD exitcode, DWORD waithint);
return result;
}
-/* Log an error message */
-void LogErrorMsg(const char *message, const char *fname, int lineno)
+/* Log an error message for the last Windows error */
+void LogLastErrorMsg(const char *message, const char *fname, int lineno)
{
char msgbuf[500];
HANDLE eventHandler;