diff options
author | Stefano Brivio <sbrivio@redhat.com> | 2024-06-15 00:25:23 +0200 |
---|---|---|
committer | Stefano Brivio <sbrivio@redhat.com> | 2024-06-21 15:32:40 +0200 |
commit | c1140df889aeb90f944c1caabdf6f73522dbb250 (patch) | |
tree | 0dca35df181b089e4f128b8d518e3816ba2b1d3c /log.c | |
parent | afd9cdc9bb48fdff18d6506e6f5051de35490397 (diff) | |
download | passt-c1140df889aeb90f944c1caabdf6f73522dbb250.tar passt-c1140df889aeb90f944c1caabdf6f73522dbb250.tar.gz passt-c1140df889aeb90f944c1caabdf6f73522dbb250.tar.bz2 passt-c1140df889aeb90f944c1caabdf6f73522dbb250.tar.lz passt-c1140df889aeb90f944c1caabdf6f73522dbb250.tar.xz passt-c1140df889aeb90f944c1caabdf6f73522dbb250.tar.zst passt-c1140df889aeb90f944c1caabdf6f73522dbb250.zip |
log: Add _perror() logging function variants
In many places, we have direct perror() calls, which completely bypass
logging functions and log files.
They are definitely convenient: offer similar convenience with
_perror() logging variants, so that we can drop those direct perror()
calls.
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
Diffstat (limited to 'log.c')
-rw-r--r-- | log.c | 22 |
1 files changed, 22 insertions, 0 deletions
@@ -78,6 +78,11 @@ void vlogmsg(int pri, const char *format, va_list ap) } } +/** + * logmsg() - vlogmsg() wrapper for variable argument lists + * @pri: Facility and level map, same as priority for vsyslog() + * @format: Message + */ void logmsg(int pri, const char *format, ...) { va_list ap; @@ -87,6 +92,23 @@ void logmsg(int pri, const char *format, ...) va_end(ap); } +/** + * logmsg_perror() - vlogmsg() wrapper with perror()-like functionality + * @pri: Facility and level map, same as priority for vsyslog() + * @format: Message + */ +void logmsg_perror(int pri, const char *format, ...) +{ + int errno_copy = errno; + va_list ap; + + va_start(ap, format); + vlogmsg(pri, format, ap); + va_end(ap); + + logmsg(pri, ": %s", strerror(errno_copy)); +} + /* Prefixes for log file messages, indexed by priority */ const char *logfile_prefix[] = { NULL, NULL, NULL, /* Unused: LOG_EMERG, LOG_ALERT, LOG_CRIT */ |