chiark / gitweb /
log: also set errno to the passed error code before processing format string in log_s...
authorLennart Poettering <lennart@poettering.net>
Fri, 28 Nov 2014 01:30:49 +0000 (02:30 +0100)
committerLennart Poettering <lennart@poettering.net>
Fri, 28 Nov 2014 02:16:56 +0000 (03:16 +0100)
That way the caller may use %m to print the specified error.

src/shared/log.c

index 56469b3..eba5853 100644 (file)
@@ -813,6 +813,9 @@ int log_struct_internal(
                          * since vasprintf() leaves it afterwards at
                          * an undefined location */
 
                          * 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);
                         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;
 
                 while (format) {
                         va_list aq;
 
+                        if (error != 0)
+                                errno = error;
+
                         va_copy(aq, ap);
                         vsnprintf(buf, sizeof(buf), format, aq);
                         va_end(aq);
                         va_copy(aq, ap);
                         vsnprintf(buf, sizeof(buf), format, aq);
                         va_end(aq);