From 6357ac664c9ce8ae5b83bdb98011da24185e4efa Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 28 Nov 2014 02:30:49 +0100 Subject: 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(+) (limited to 'src/shared/log.c') diff --git a/src/shared/log.c b/src/shared/log.c index 56469b32b5..eba5853ab0 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); -- cgit v1.2.3-54-g00ecf