From: Rich Felker <dalias@libc.org>
To: musl@lists.openwall.com
Subject: Re: [PATCH] implement the LOG_PERROR option in syslog
Date: Fri, 11 Jul 2014 20:55:25 -0400 [thread overview]
Message-ID: <20140712005525.GB179@brightrain.aerifal.cx> (raw)
In-Reply-To: <20140711044950.GY179@brightrain.aerifal.cx>
[-- Attachment #1: Type: text/plain, Size: 332 bytes --]
On Fri, Jul 11, 2014 at 12:49:50AM -0400, Rich Felker wrote:
> Anyway, for adding the feature you want, where you just want to know
> the number of initial bytes to skip writing to stderr, I would just
> use %n to get the offset.
Attached is a patch to do this. I'll commit it soon if nobody notices
any problems right away.
Rich
[-- Attachment #2: syslog_perror.diff --]
[-- Type: text/plain, Size: 1072 bytes --]
diff --git a/src/misc/syslog.c b/src/misc/syslog.c
index 57f1d75..d2ea4aa 100644
--- a/src/misc/syslog.c
+++ b/src/misc/syslog.c
@@ -80,6 +80,7 @@ static void _vsyslog(int priority, const char *message, va_list ap)
int errno_save = errno;
int pid;
int l, l2;
+ int hlen;
if (log_fd < 0) {
__openlog();
@@ -93,8 +94,8 @@ static void _vsyslog(int priority, const char *message, va_list ap)
strftime(timebuf, sizeof timebuf, "%b %e %T", &tm);
pid = (log_opt & LOG_PID) ? getpid() : 0;
- l = snprintf(buf, sizeof buf, "<%d>%s %s%s%.0d%s: ",
- priority, timebuf, log_ident, "["+!pid, pid, "]"+!pid);
+ l = snprintf(buf, sizeof buf, "<%d>%s %n%s%s%.0d%s: ",
+ priority, timebuf, &hlen, log_ident, "["+!pid, pid, "]"+!pid);
errno = errno_save;
l2 = vsnprintf(buf+l, sizeof buf - l, message, ap);
if (l2 >= 0) {
@@ -102,6 +103,7 @@ static void _vsyslog(int priority, const char *message, va_list ap)
else l += l2;
if (buf[l-1] != '\n') buf[l++] = '\n';
send(log_fd, buf, l, 0);
+ if (log_opt & LOG_PERROR) write(2, buf+hlen, l-hlen);
}
}
next prev parent reply other threads:[~2014-07-12 0:55 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-09 12:42 Clément Vasseur
2014-07-11 4:49 ` Rich Felker
2014-07-12 0:55 ` Rich Felker [this message]
2014-07-12 1:08 ` Clément Vasseur
2014-07-12 1:15 ` Rich Felker
2014-07-12 8:33 ` Laurent Bercot
2014-07-12 13:58 ` 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=20140712005525.GB179@brightrain.aerifal.cx \
--to=dalias@libc.org \
--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).