From: Mike Pape <dotzenlabs@xxxxxxxxx> Syslog does not usually exist on Windows, so we implement our own using Window's ReportEvent mechanism. Signed-off-by: Mike Pape <dotzenlabs@xxxxxxxxx> Signed-off-by: Erik Faye-Lund <kusmabite@xxxxxxxxx> --- compat/mingw.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ compat/mingw.h | 15 +++++++++++++++ daemon.c | 2 -- git-compat-util.h | 1 + 4 files changed, 65 insertions(+), 2 deletions(-) diff --git a/compat/mingw.c b/compat/mingw.c index 42ef9e2..54be905 100644 --- a/compat/mingw.c +++ b/compat/mingw.c @@ -1351,6 +1351,55 @@ int sigaction(int sig, struct sigaction *in, struct sigaction *out) return 0; } +static HANDLE ms_eventlog; + +void openlog(const char *ident, int logopt, int facility) +{ + if (ms_eventlog) + return; + ms_eventlog = RegisterEventSourceA(NULL, ident); +} + +void syslog(int priority, const char *fmt, const char *arg) +{ + WORD logtype; + + if (strcmp(fmt, "%s")) { + warning("format string of syslog() not implemented"); + return; + } + + 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 **)&arg, + NULL); +} + #undef signal sig_handler_t mingw_signal(int sig, sig_handler_t handler) { diff --git a/compat/mingw.h b/compat/mingw.h index 07513bb..d934e56 100644 --- a/compat/mingw.h +++ b/compat/mingw.h @@ -38,6 +38,19 @@ typedef int socklen_t; #define EAFNOSUPPORT WSAEAFNOSUPPORT #define ECONNABORTED WSAECONNABORTED +#define LOG_PID 0x01 + +#define LOG_EMERG 0 +#define LOG_ALERT 1 +#define LOG_CRIT 2 +#define LOG_ERR 3 +#define LOG_WARNING 4 +#define LOG_NOTICE 5 +#define LOG_INFO 6 +#define LOG_DEBUG 7 + +#define LOG_DAEMON (3<<3) + struct passwd { char *pw_name; char *pw_gecos; @@ -166,6 +179,8 @@ struct passwd *getpwuid(int uid); int setitimer(int type, struct itimerval *in, struct itimerval *out); int sigaction(int sig, struct sigaction *in, struct sigaction *out); int link(const char *oldpath, const char *newpath); +void openlog(const char *ident, int logopt, int facility); +void syslog(int priority, const char *fmt, const char *arg); /* * replacements of existing functions diff --git a/daemon.c b/daemon.c index 918e560..79ba1aa 100644 --- a/daemon.c +++ b/daemon.c @@ -4,8 +4,6 @@ #include "run-command.h" #include "strbuf.h" -#include <syslog.h> - #ifndef HOST_NAME_MAX #define HOST_NAME_MAX 256 #endif diff --git a/git-compat-util.h b/git-compat-util.h index 5c59687..30e6240 100644 --- a/git-compat-util.h +++ b/git-compat-util.h @@ -105,6 +105,7 @@ #include <netdb.h> #include <pwd.h> #include <inttypes.h> +#include <syslog.h> #if defined(__CYGWIN__) #undef _XOPEN_SOURCE #include <grp.h> -- 1.6.6.211.g26720 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html