From: David Gibson <david@gibson.dropbear.id.au>
To: Stefano Brivio <sbrivio@redhat.com>
Cc: passt-dev@passt.top, Andrea Bolognani <abologna@redhat.com>
Subject: Re: [PATCH] log: Send identifier string in log messages, openlog() won't work for us
Date: Fri, 24 Feb 2023 10:31:27 +1100 [thread overview]
Message-ID: <Y/f3T1HYbGNcB2Lo@yekko> (raw)
In-Reply-To: <20230223173555.3896768-1-sbrivio@redhat.com>
[-- Attachment #1: Type: text/plain, Size: 2575 bytes --]
On Thu, Feb 23, 2023 at 06:35:55PM +0100, Stefano Brivio wrote:
> openlog() can be used to set "ident" and have all the log messages
> prefixed by it, but only if we call syslog() -- this is implemented
> by C libraries.
>
> We don't log messages with syslog(), though, as we have a custom
> implementation to ensure we don't need dynamic memory allocation.
> This means that it's perfectly useless to call openlog(), and that we
> have to prefix every message we log by the identifier on our own.
>
> Reported-by: Andrea Bolognani <abologna@redhat.com>
> Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
> ---
> log.c | 12 +++++-------
> 1 file changed, 5 insertions(+), 7 deletions(-)
>
> diff --git a/log.c b/log.c
> index f23e8ef..bfde6ce 100644
> --- a/log.c
> +++ b/log.c
> @@ -106,7 +106,7 @@ void trace_init(int enable)
> }
>
> /**
> - * __openlog() - Non-optional openlog() wrapper, to allow custom vsyslog()
> + * __openlog() - Non-optional openlog() implementation, for custom vsyslog()
> * @ident: openlog() identity (program name)
> * @option: openlog() options
> * @facility: openlog() facility (LOG_DAEMON)
> @@ -136,8 +136,6 @@ void __openlog(const char *ident, int option, int facility)
> log_mask |= facility;
> strncpy(log_ident, ident, sizeof(log_ident) - 1);
> log_opt = option;
> -
> - openlog(ident, option, facility);
> }
>
> /**
> @@ -158,11 +156,11 @@ void __setlogmask(int mask)
> */
> void passt_vsyslog(int pri, const char *format, va_list ap)
> {
> + int prefix_len, n;
> char buf[BUFSIZ];
> - int n;
>
> - /* Send without name and timestamp, the system logger should add them */
> - n = snprintf(buf, BUFSIZ, "<%i> ", pri);
> + /* Send without timestamp, the system logger should add it */
> + n = prefix_len = snprintf(buf, BUFSIZ, "<%i> %s: ", pri, log_ident);
>
> n += vsnprintf(buf + n, BUFSIZ - n, format, ap);
>
> @@ -170,7 +168,7 @@ void passt_vsyslog(int pri, const char *format, va_list ap)
> n += snprintf(buf + n, BUFSIZ - n, "\n");
>
> if (log_opt & LOG_PERROR)
> - fprintf(stderr, "%s", buf + sizeof("<0>"));
> + fprintf(stderr, "%s", buf + prefix_len);
>
> if (send(log_sock, buf, n, 0) != n)
> fprintf(stderr, "Failed to send %i bytes to syslog\n", n);
--
David Gibson | I'll have my music baroque, and my code
david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
prev parent reply other threads:[~2023-02-24 4:03 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-23 17:35 [PATCH] log: Send identifier string in log messages, openlog() won't work for us Stefano Brivio
2023-02-23 18:15 ` Andrea Bolognani
2023-02-24 6:59 ` Stefano Brivio
2023-02-24 19:44 ` Andrea Bolognani
2023-02-23 23:31 ` David Gibson [this message]
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=Y/f3T1HYbGNcB2Lo@yekko \
--to=david@gibson.dropbear.id.au \
--cc=abologna@redhat.com \
--cc=passt-dev@passt.top \
--cc=sbrivio@redhat.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://passt.top/passt
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 IMAP folder(s).