From: Lennart Poettering Date: Fri, 28 Nov 2014 01:30:49 +0000 (+0100) Subject: log: also set errno to the passed error code before processing format string in log_s... X-Git-Tag: v218~271 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=commitdiff_plain;h=6357ac664c9ce8ae5b83bdb98011da24185e4efa 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. --- diff --git a/src/shared/log.c b/src/shared/log.c index 56469b32b..eba5853ab 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);