From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=none (p=none dis=none) header.from=gibson.dropbear.id.au Authentication-Results: passt.top; dkim=pass (2048-bit key; secure) header.d=gibson.dropbear.id.au header.i=@gibson.dropbear.id.au header.a=rsa-sha256 header.s=202502 header.b=REe0kLT1; dkim-atps=neutral Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id E64675A9C3D for ; Wed, 05 Mar 2025 07:15:14 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202502; t=1741155310; bh=Rsg7HV4PcZ+zeT+/l8C9a9kirQJVZxoa+bmX8z2T3ds=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=REe0kLT1oRGnZnbjD+PzAjjGZoJ13ZqtZ+NN53dzqANwqd1IQsTb7vfEerBR/QCGr iKumHT1zUnxpqr94flZQkc/RQcZWF4o7PwgwREtjaPlf9EqWFaUbbqiQYPEMwsaZhF P5jrO6hLdT1Y+RWacR3Btd/E7HUK3Z3KxcVV7ZqiXNgetk702A4CVDpjp9Fa8Mj99n d7SrCkk9GWhZR2REhL2j6X2AZHo9YO6gO2kk7mQi+Cnn5Oh9nVBgnJr4QyQ5ZM33AL oHL5x0J3tpiauFJ3hD3O8Fthfj2mTGYnyzjAWwmEIHpIGcV7pEV+RV4Iio0gvJsNXv /44i7XQaemrwQ== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4Z72My3Qt8z4x89; Wed, 5 Mar 2025 17:15:10 +1100 (AEDT) From: David Gibson To: Stefano Brivio , passt-dev@passt.top Subject: [PATCH 2/6] log: Don't export passt_vsyslog() Date: Wed, 5 Mar 2025 17:15:04 +1100 Message-ID: <20250305061508.1699713-3-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250305061508.1699713-1-david@gibson.dropbear.id.au> References: <20250305061508.1699713-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: XEAY46TCTDGWBC5R7G7KUOTQUJXOYYKS X-Message-ID-Hash: XEAY46TCTDGWBC5R7G7KUOTQUJXOYYKS X-MailFrom: dgibson@gandalf.ozlabs.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: David Gibson X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: passt_vsyslog() is an exposed function in log.h. However it shouldn't be called from outside log.c: it writes specifically to the system log, and most code should call passt's logging helpers which might go to the syslog or to a log file. Make passt_vsyslog() local to log.c. This requires a code motion to avoid a forward declaration. Signed-off-by: David Gibson --- log.c | 48 ++++++++++++++++++++++++------------------------ log.h | 1 - 2 files changed, 24 insertions(+), 25 deletions(-) diff --git a/log.c b/log.c index b6bce214..6eda4c4c 100644 --- a/log.c +++ b/log.c @@ -249,6 +249,30 @@ static void logfile_write(bool newline, bool cont, int pri, log_written += n; } +/** + * passt_vsyslog() - vsyslog() implementation not using heap memory + * @newline: Append newline at the end of the message, if missing + * @pri: Facility and level map, same as priority for vsyslog() + * @format: Same as vsyslog() format + * @ap: Same as vsyslog() ap + */ +static void passt_vsyslog(bool newline, int pri, const char *format, va_list ap) +{ + char buf[BUFSIZ]; + int n; + + /* Send without timestamp, the system logger should add it */ + n = snprintf(buf, BUFSIZ, "<%i> %s: ", pri, log_ident); + + n += vsnprintf(buf + n, BUFSIZ - n, format, ap); + + if (newline && format[strlen(format)] != '\n') + n += snprintf(buf + n, BUFSIZ - n, "\n"); + + if (log_sock >= 0 && send(log_sock, buf, n, 0) != n && log_stderr) + FPRINTF(stderr, "Failed to send %i bytes to syslog\n", n); +} + /** * vlogmsg() - Print or send messages to log or output files as configured * @newline: Append newline at the end of the message, if missing @@ -373,30 +397,6 @@ void __setlogmask(int mask) setlogmask(mask); } -/** - * passt_vsyslog() - vsyslog() implementation not using heap memory - * @newline: Append newline at the end of the message, if missing - * @pri: Facility and level map, same as priority for vsyslog() - * @format: Same as vsyslog() format - * @ap: Same as vsyslog() ap - */ -void passt_vsyslog(bool newline, int pri, const char *format, va_list ap) -{ - char buf[BUFSIZ]; - int n; - - /* Send without timestamp, the system logger should add it */ - n = snprintf(buf, BUFSIZ, "<%i> %s: ", pri, log_ident); - - n += vsnprintf(buf + n, BUFSIZ - n, format, ap); - - if (newline && format[strlen(format)] != '\n') - n += snprintf(buf + n, BUFSIZ - n, "\n"); - - if (log_sock >= 0 && send(log_sock, buf, n, 0) != n && log_stderr) - FPRINTF(stderr, "Failed to send %i bytes to syslog\n", n); -} - /** * logfile_init() - Open log file and write header with PID, version, path * @name: Identifier for header: passt or pasta diff --git a/log.h b/log.h index 22c7b9ab..08aa88c1 100644 --- a/log.h +++ b/log.h @@ -55,7 +55,6 @@ void trace_init(int enable); void __openlog(const char *ident, int option, int facility); void logfile_init(const char *name, const char *path, size_t size); -void passt_vsyslog(bool newline, int pri, const char *format, va_list ap); void __setlogmask(int mask); #endif /* LOG_H */ -- 2.48.1