(vsyslog): actually haandle %m

git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@8276 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
Assar Westerlund
2000-05-21 01:38:02 +00:00
parent 86d1fdc7f8
commit 5162fec2ba

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1995, 1996, 1997 Kungliga Tekniska H<>gskolan * Copyright (c) 1995 - 2000 Kungliga Tekniska H<>gskolan
* (Royal Institute of Technology, Stockholm, Sweden). * (Royal Institute of Technology, Stockholm, Sweden).
* All rights reserved. * All rights reserved.
* *
@@ -44,14 +44,58 @@ RCSID("$Id$");
#include "roken.h" #include "roken.h"
static void
simple_vsyslog(int pri, const char *fmt, va_list ap)
{
syslog (pri, "%s", fmt);
}
void void
vsyslog(int pri, const char *fmt, va_list ap) vsyslog(int pri, const char *fmt, va_list ap)
{ {
char *p; char *fmt2;
const char *p;
char *p2;
int saved_errno = errno;
int fmtlen = strlen (fmt);
char *buf;
vasprintf (&p, fmt, ap); fmt2 = malloc (fmtlen + 1);
syslog (pri, "%s", p); if (fmt2 == NULL) {
free (p); simple_vsyslog (pri, fmt, ap);
return;
}
for (p = fmt, p2 = fmt2; *p != '\0'; ++p) {
if (p[0] == '%' && p[1] == 'm') {
const char *e = strerror (saved_errno);
int e_len = strlen (e);
char *tmp;
int pos;
pos = p2 - fmt2;
tmp = realloc (fmt2, fmtlen + 1 + e_len - 2);
if (tmp == NULL) {
free (fmt2);
simple_vsyslog (pri, fmt, ap);
return;
}
fmt2 = tmp;
p2 = fmt2 + pos;
memmove (p2, e, e_len);
p2 += e_len;
++p;
} else
*p2++ = *p;
}
vasprintf (&buf, fmt2, ap);
free (fmt2);
if (buf == NULL) {
simple_vsyslog (pri, fmt, ap);
return;
}
syslog (pri, "%s", buf);
free (buf);
} }
#endif #endif