From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/2956 Path: news.gmane.org!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: Proposed syslog patch [Re: [musl] Further bugs in syslog()] Date: Sat, 23 Mar 2013 00:05:58 -0400 Message-ID: <20130323040558.GU20323@brightrain.aerifal.cx> References: <20130323034538.GS20323@brightrain.aerifal.cx> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="rQ2U398070+RC21q" X-Trace: ger.gmane.org 1364011569 19269 80.91.229.3 (23 Mar 2013 04:06:09 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 23 Mar 2013 04:06:09 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-2957-gllmg-musl=m.gmane.org@lists.openwall.com Sat Mar 23 05:06:35 2013 Return-path: Envelope-to: gllmg-musl@plane.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1UJFj1-0003zr-ET for gllmg-musl@plane.gmane.org; Sat, 23 Mar 2013 05:06:35 +0100 Original-Received: (qmail 1578 invoked by uid 550); 23 Mar 2013 04:06:11 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Original-Received: (qmail 1570 invoked from network); 23 Mar 2013 04:06:11 -0000 Content-Disposition: inline In-Reply-To: <20130323034538.GS20323@brightrain.aerifal.cx> User-Agent: Mutt/1.5.21 (2010-09-15) Xref: news.gmane.org gmane.linux.lib.musl.general:2956 Archived-At: --rQ2U398070+RC21q Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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 --rQ2U398070+RC21q Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="syslog.diff" 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) --rQ2U398070+RC21q--