summaryrefslogtreecommitdiff
path: root/compat/win32/syslog.c
diff options
context:
space:
mode:
authorErik Faye-Lund <kusmabite@gmail.com>2011-10-06 17:52:48 (GMT)
committerJunio C Hamano <gitster@pobox.com>2011-10-07 23:12:25 (GMT)
commit2a6b149c64f6ba8cc3eef70c6901ee0c67a137a7 (patch)
tree12e4f74786a964b36a2be47a786a53bf2b30f89a /compat/win32/syslog.c
parent703f05ad5835cff92b12c29aecf8d724c8c847e2 (diff)
downloadgit-2a6b149c64f6ba8cc3eef70c6901ee0c67a137a7.zip
git-2a6b149c64f6ba8cc3eef70c6901ee0c67a137a7.tar.gz
git-2a6b149c64f6ba8cc3eef70c6901ee0c67a137a7.tar.bz2
mingw: avoid using strbuf in syslog
strbuf can call die, which again can call syslog from git-daemon. Endless recursion is no fun; fix it by hand-rolling the logic. As a side-effect malloc/realloc errors are changed into non-fatal warnings; this is probably an improvement anyway. Signed-off-by: Erik Faye-Lund <kusmabite@gmail.com> Noticed-by: Johannes Sixt <j.sixt@viscovery.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'compat/win32/syslog.c')
-rw-r--r--compat/win32/syslog.c30
1 files changed, 18 insertions, 12 deletions
diff --git a/compat/win32/syslog.c b/compat/win32/syslog.c
index 42b95a9..d015e43 100644
--- a/compat/win32/syslog.c
+++ b/compat/win32/syslog.c
@@ -1,5 +1,4 @@
#include "../../git-compat-util.h"
-#include "../../strbuf.h"
static HANDLE ms_eventlog;
@@ -16,13 +15,8 @@ void openlog(const char *ident, int logopt, int facility)
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;
+ char *str, *pos;
int str_len;
va_list ap;
@@ -39,11 +33,24 @@ void syslog(int priority, const char *fmt, ...)
}
str = malloc(str_len + 1);
+ if (!str) {
+ warning("malloc failed: '%s'", strerror(errno));
+ return;
+ }
+
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);
+
+ while ((pos = strstr(str, "%1")) != NULL) {
+ str = realloc(str, ++str_len + 1);
+ if (!str) {
+ warning("realloc failed: '%s'", strerror(errno));
+ return;
+ }
+ memmove(pos + 2, pos + 1, strlen(pos));
+ pos[1] = ' ';
+ }
switch (priority) {
case LOG_EMERG:
@@ -66,7 +73,6 @@ void syslog(int priority, const char *fmt, ...)
}
ReportEventA(ms_eventlog, logtype, 0, 0, NULL, 1, 0,
- (const char **)&sb.buf, NULL);
-
- strbuf_release(&sb);
+ (const char **)&str, NULL);
+ free(str);
}