From 6357ac664c9ce8ae5b83bdb98011da24185e4efa Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 28 Nov 2014 02:30:49 +0100 Subject: [PATCH] log: also set errno to the passed error code before processing format string in log_struct() That way the caller may use %m to print the specified error. --- src/shared/log.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/shared/log.c b/src/shared/log.c index 56469b32b5d..eba5853ab0a 100644 --- a/src/shared/log.c +++ b/src/shared/log.c @@ -813,6 +813,9 @@ int log_struct_internal( * since vasprintf() leaves it afterwards at * an undefined location */ + if (error != 0) + errno = error; + va_copy(aq, ap); if (vasprintf(&buf, format, aq) < 0) { va_end(aq); @@ -856,6 +859,9 @@ int log_struct_internal( while (format) { va_list aq; + if (error != 0) + errno = error; + va_copy(aq, ap); vsnprintf(buf, sizeof(buf), format, aq); va_end(aq);