From: Rich Felker <dalias@aerifal.cx>
To: musl@lists.openwall.com
Subject: Proposed syslog patch [Re: [musl] Further bugs in syslog()]
Date: Sat, 23 Mar 2013 00:05:58 -0400 [thread overview]
Message-ID: <20130323040558.GU20323@brightrain.aerifal.cx> (raw)
In-Reply-To: <20130323034538.GS20323@brightrain.aerifal.cx>
[-- Attachment #1: Type: text/plain, Size: 185 bytes --]
On Fri, Mar 22, 2013 at 11:45:39PM -0400, Rich Felker wrote:
> I'm going to review the proposed patches and probably put together a
> big syslog fix...
Comments on the attached?
Rich
[-- Attachment #2: syslog.diff --]
[-- Type: text/plain, Size: 2052 bytes --]
diff --git a/src/misc/syslog.c b/src/misc/syslog.c
index 8de34f8..81fb114 100644
--- a/src/misc/syslog.c
+++ b/src/misc/syslog.c
@@ -11,7 +11,7 @@
#include "libc.h"
static int lock[2];
-static const char *log_ident;
+static char *log_ident;
static int log_opt;
static int log_facility = LOG_USER;
static int log_mask = 0xff;
@@ -43,15 +43,10 @@ void closelog(void)
pthread_setcancelstate(cs, 0);
}
-static void __openlog(const char *ident, int opt, int facility)
+static void __openlog()
{
- log_ident = ident;
- log_opt = opt;
- log_facility = facility;
-
- if (!(opt & LOG_NDELAY) || log_fd>=0) return;
-
log_fd = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0);
+ connect(log_fd, (void *)&log_addr, sizeof log_addr);
}
void openlog(const char *ident, int opt, int facility)
@@ -59,7 +54,14 @@ void openlog(const char *ident, int opt, int facility)
int cs;
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
LOCK(lock);
- __openlog(ident, opt, facility);
+
+ free(log_ident);
+ log_ident = strdup(ident);
+ log_opt = opt;
+ log_facility = facility;
+
+ if ((opt & LOG_NDELAY) && log_fd<0) __openlog();
+
UNLOCK(lock);
pthread_setcancelstate(cs, 0);
}
@@ -74,11 +76,8 @@ static void _vsyslog(int priority, const char *message, va_list ap)
int l, l2;
if (log_fd < 0) {
- __openlog(log_ident, log_opt | LOG_NDELAY, log_facility);
- if (log_fd < 0) {
- UNLOCK(lock);
- return;
- }
+ __openlog();
+ if (log_fd < 0) return;
}
now = time(NULL);
@@ -90,14 +89,14 @@ static void _vsyslog(int priority, const char *message, va_list ap)
priority, timebuf,
log_ident ? log_ident : "",
"["+!pid, pid, "]"+!pid);
+ if (l >= sizeof buf) return;
l2 = vsnprintf(buf+l, sizeof buf - l, message, ap);
if (l2 >= 0) {
- l += l2;
+ if (l2 >= sizeof buf - l) l = sizeof buf - 1;
+ else l += l2;
if (buf[l-1] != '\n') buf[l++] = '\n';
- sendto(log_fd, buf, l, 0, (void *)&log_addr, 11);
+ send(log_fd, buf, l, 0);
}
-
- UNLOCK(lock);
}
void __vsyslog(int priority, const char *message, va_list ap)
next prev parent reply other threads:[~2013-03-23 4:05 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-03-23 3:45 Further bugs in syslog() Rich Felker
2013-03-23 3:53 ` Rich Felker
2013-03-23 4:05 ` Rich Felker [this message]
2013-03-23 16:17 ` Proposed syslog patch [Re: [musl] Further bugs in syslog()] Szabolcs Nagy
2013-03-23 21:27 ` Rich Felker
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20130323040558.GU20323@brightrain.aerifal.cx \
--to=dalias@aerifal.cx \
--cc=musl@lists.openwall.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).