From 100e21918131edef6aa4a619c60c92bfc3ed8d67 Mon Sep 17 00:00:00 2001 From: Fabrizio Bertocci Date: Thu, 25 Mar 2021 19:41:59 -0400 Subject: [PATCH] Replaced calling sendto() with send() since previous version was required to work around to the duplication of the send() function. Added implementation to automatically initialize the identity of the logger through the use of the global `program_invocation_short_name`. --- libc/sock/syslog.c | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/libc/sock/syslog.c b/libc/sock/syslog.c index bb6e3b671..c1ca4a1af 100644 --- a/libc/sock/syslog.c +++ b/libc/sock/syslog.c @@ -147,13 +147,9 @@ void vsyslog(int priority, const char *message, va_list ap) { * - First try to send it to syslogd * - If fails and LOG_CONS is provided, writes to /dev/console */ - // TODO: If we use send() it will end up calling the send stubs under - // sysv/calls/send.S and that will report ENOSYS (apparently that - // function serves only BSD). If we use sendto() it works as expected. - // Why send() does not call the send() function defined in sock/send.c ? - if (sendto(log_fd, buf, l, 0, NULL, 0) < 0 && (!is_lost_conn(errno) + if (send(log_fd, buf, l, 0) < 0 && (!is_lost_conn(errno) || connect(log_fd, (void *)&log_addr, sizeof(log_addr)) < 0 - || sendto(log_fd, buf, l, 0, NULL, 0) < 0) + || send(log_fd, buf, l, 0) < 0) && (log_opt & LOG_CONS)) { int fd = open("/dev/console", O_WRONLY|O_NOCTTY); if (fd >= 0) { @@ -252,24 +248,22 @@ int setlogmask(int maskpri) { * @asyncsignalsafe */ void openlog(const char *ident, int opt, int facility) { + size_t n; + if (log_facility == -1) { __initlog(); } - if (ident) { - size_t n = strnlen(ident, sizeof(log_ident) - 1); - memcpy(log_ident, ident, n); - log_ident[n] = 0; - } else { - log_ident[0] = 0; + if (!ident) { + ident = program_invocation_short_name; } + n = strnlen(ident, sizeof(log_ident) - 1); + memcpy(log_ident, ident, n); + log_ident[n] = 0; log_opt = opt; log_facility = facility; log_id = 0; - // TODO: If ident == NULL, retrieve the process name. - if ((opt & LOG_NDELAY) && log_fd<0) __openlog(); - }