summaryrefslogtreecommitdiff
path: root/compat/win32/syslog.c
diff options
context:
space:
mode:
authorLibravatar Junio C Hamano <gitster@pobox.com>2010-11-23 16:05:46 -0800
committerLibravatar Junio C Hamano <gitster@pobox.com>2010-11-23 16:05:46 -0800
commit89ba4e7c7f71712133d1d3137f811b99ea43dd31 (patch)
tree0a831af2e55f0b533ff80a53972b0b17755e310f /compat/win32/syslog.c
parentUpdate draft release notes to 1.7.4 (diff)
parentdaemon: opt-out on features that require posix (diff)
downloadtgif-89ba4e7c7f71712133d1d3137f811b99ea43dd31.tar.xz
Merge branch 'ef/mingw-daemon'
* ef/mingw-daemon: daemon: opt-out on features that require posix daemon: make --inetd and --detach incompatible daemon: use socklen_t mingw: use poll-emulation from gnulib mingw: import poll-emulation from gnulib daemon: get remote host address from root-process Improve the mingw getaddrinfo stub to handle more use cases daemon: use full buffered mode for stderr daemon: use run-command api for async serving mingw: add kill emulation mingw: support waitpid with pid > 0 and WNOHANG mingw: use real pid inet_ntop: fix a couple of old-style decls compat: add inet_pton and inet_ntop prototypes mingw: implement syslog mingw: add network-wrappers for daemon
Diffstat (limited to 'compat/win32/syslog.c')
-rw-r--r--compat/win32/syslog.c72
1 files changed, 72 insertions, 0 deletions
diff --git a/compat/win32/syslog.c b/compat/win32/syslog.c
new file mode 100644
index 0000000000..42b95a9b51
--- /dev/null
+++ b/compat/win32/syslog.c
@@ -0,0 +1,72 @@
+#include "../../git-compat-util.h"
+#include "../../strbuf.h"
+
+static HANDLE ms_eventlog;
+
+void openlog(const char *ident, int logopt, int facility)
+{
+ if (ms_eventlog)
+ return;
+
+ ms_eventlog = RegisterEventSourceA(NULL, ident);
+
+ if (!ms_eventlog)
+ warning("RegisterEventSource() failed: %lu", GetLastError());
+}
+
+void syslog(int priority, const char *fmt, ...)
+{
+ struct strbuf sb = STRBUF_INIT;
+ struct strbuf_expand_dict_entry dict[] = {
+ {"1", "% 1"},
+ {NULL, NULL}
+ };
+ WORD logtype;
+ char *str;
+ int str_len;
+ va_list ap;
+
+ if (!ms_eventlog)
+ return;
+
+ va_start(ap, fmt);
+ str_len = vsnprintf(NULL, 0, fmt, ap);
+ va_end(ap);
+
+ if (str_len < 0) {
+ warning("vsnprintf failed: '%s'", strerror(errno));
+ return;
+ }
+
+ str = malloc(str_len + 1);
+ va_start(ap, fmt);
+ vsnprintf(str, str_len + 1, fmt, ap);
+ va_end(ap);
+ strbuf_expand(&sb, str, strbuf_expand_dict_cb, &dict);
+ free(str);
+
+ switch (priority) {
+ case LOG_EMERG:
+ case LOG_ALERT:
+ case LOG_CRIT:
+ case LOG_ERR:
+ logtype = EVENTLOG_ERROR_TYPE;
+ break;
+
+ case LOG_WARNING:
+ logtype = EVENTLOG_WARNING_TYPE;
+ break;
+
+ case LOG_NOTICE:
+ case LOG_INFO:
+ case LOG_DEBUG:
+ default:
+ logtype = EVENTLOG_INFORMATION_TYPE;
+ break;
+ }
+
+ ReportEventA(ms_eventlog, logtype, 0, 0, NULL, 1, 0,
+ (const char **)&sb.buf, NULL);
+
+ strbuf_release(&sb);
+}