From ff3a241ccc98a19bae6a6be271055dec108a9679 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20H=C3=A4rdeman?= Date: Fri, 17 Oct 2025 21:45:38 +0200 Subject: [PATCH] odhcpd: shrink binary size by creating a logging function MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Moving the logging to a real function helps shrink the binary size back to what it was before the logging patches. Signed-off-by: David Härdeman Link: https://github.com/openwrt/odhcpd/pull/273 Signed-off-by: Álvaro Fernández Rojas --- src/odhcpd.c | 19 +++++++++++++++++++ src/odhcpd.h | 11 +---------- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/odhcpd.c b/src/odhcpd.c index 1f3cd1b..4b17a16 100644 --- a/src/odhcpd.c +++ b/src/odhcpd.c @@ -46,6 +46,25 @@ static int ioctl_sock = -1; static int urandom_fd = -1; +void __iflog(int lvl, const char *fmt, ...) +{ + va_list ap; + + if (lvl > config.log_level) + return; + + va_start(ap, fmt); + + if (config.log_syslog) { + vsyslog(lvl, fmt, ap); + } else { + vfprintf(stderr, fmt, ap); + fprintf(stderr, "\n"); + } + + va_end(ap); +} + static void sighandler(_unused int signal) { uloop_end(); diff --git a/src/odhcpd.h b/src/odhcpd.h index 9a41a59..dc77c03 100644 --- a/src/odhcpd.h +++ b/src/odhcpd.h @@ -69,16 +69,7 @@ struct nl_sock; extern struct vlist_tree leases; extern struct config config; -#define __iflog(lvl, fmt, ...) \ - do { \ - if (lvl > config.log_level) \ - break; \ - if (config.log_syslog) \ - syslog(lvl, fmt __VA_OPT__(, ) __VA_ARGS__); \ - else \ - fprintf(stderr, fmt "\n" __VA_OPT__(, ) __VA_ARGS__); \ - } while(0) - +void __iflog(int lvl, const char *fmt, ...); #define debug(fmt, ...) __iflog(LOG_DEBUG, fmt __VA_OPT__(, ) __VA_ARGS__) #define info(fmt, ...) __iflog(LOG_INFO, fmt __VA_OPT__(, ) __VA_ARGS__) #define notice(fmt, ...) __iflog(LOG_NOTICE, fmt __VA_OPT__(, ) __VA_ARGS__) -- 2.30.2