summaryrefslogtreecommitdiffstats
path: root/crypto/heimdal/lib/roken/vsyslog.c
diff options
context:
space:
mode:
authorassar <assar@FreeBSD.org>2001-02-13 16:46:19 +0000
committerassar <assar@FreeBSD.org>2001-02-13 16:46:19 +0000
commit3a971fe69aad52dfd248901ae796e64a96ae3e37 (patch)
treeac7b5c62510ffa9f0316643bcb19a3fed3d5bef7 /crypto/heimdal/lib/roken/vsyslog.c
parent2934fc23653f64b32f4db32233d7eda11ca274f0 (diff)
parentebfe6dc471c206300fd82c7c0fd145f683aa52f6 (diff)
downloadFreeBSD-src-3a971fe69aad52dfd248901ae796e64a96ae3e37.zip
FreeBSD-src-3a971fe69aad52dfd248901ae796e64a96ae3e37.tar.gz
This commit was generated by cvs2svn to compensate for changes in r72445,
which included commits to RCS files with non-trunk default branches.
Diffstat (limited to 'crypto/heimdal/lib/roken/vsyslog.c')
-rw-r--r--crypto/heimdal/lib/roken/vsyslog.c72
1 files changed, 65 insertions, 7 deletions
diff --git a/crypto/heimdal/lib/roken/vsyslog.c b/crypto/heimdal/lib/roken/vsyslog.c
index 22e6a35..c72cf33 100644
--- a/crypto/heimdal/lib/roken/vsyslog.c
+++ b/crypto/heimdal/lib/roken/vsyslog.c
@@ -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).
* All rights reserved.
*
@@ -33,7 +33,7 @@
#ifdef HAVE_CONFIG_H
#include <config.h>
-RCSID("$Id: vsyslog.c,v 1.3 1999/12/02 16:58:54 joda Exp $");
+RCSID("$Id: vsyslog.c,v 1.6 2000/05/22 22:09:25 assar Exp $");
#endif
#ifndef HAVE_VSYSLOG
@@ -44,14 +44,72 @@ RCSID("$Id: vsyslog.c,v 1.3 1999/12/02 16:58:54 joda Exp $");
#include "roken.h"
+/*
+ * the theory behind this is that we might be trying to call vsyslog
+ * when there's no memory left, and we should try to be as useful as
+ * possible. And the format string should say something about what's
+ * failing.
+ */
+
+static void
+simple_vsyslog(int pri, const char *fmt, va_list ap)
+{
+ syslog (pri, "%s", fmt);
+}
+
+/*
+ * do like syslog but with a `va_list'
+ */
+
void
vsyslog(int pri, const char *fmt, va_list ap)
{
- char *p;
+ char *fmt2;
+ const char *p;
+ char *p2;
+ int saved_errno = errno;
+ int fmt_len = strlen (fmt);
+ int fmt2_len = fmt_len;
+ char *buf;
- vasprintf (&p, fmt, ap);
- syslog (pri, "%s", p);
- free (p);
-}
+ fmt2 = malloc (fmt_len + 1);
+ if (fmt2 == NULL) {
+ 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;
+ fmt2_len += e_len - 2;
+ tmp = realloc (fmt2, fmt2_len + 1);
+ 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;
+ }
+ *p2 = '\0';
+
+ vasprintf (&buf, fmt2, ap);
+ free (fmt2);
+ if (buf == NULL) {
+ simple_vsyslog (pri, fmt, ap);
+ return;
+ }
+ syslog (pri, "%s", buf);
+ free (buf);
+}
#endif
OpenPOWER on IntegriCloud