chiark / gitweb /
basic/log: merge two big log_struct_internal invocations into one
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sun, 11 Dec 2016 19:34:45 +0000 (14:34 -0500)
committerSven Eden <yamakuzure@gmx.net>
Mon, 17 Jul 2017 15:58:35 +0000 (17:58 +0200)
We can take advantage of the fact a NULL argument terminates the list.

src/basic/log.c

index 2f54194ebd17bf4066ecf1a01418bd9f33ac1427..62af163d674a11d8496b1f42e2efddfd08b27600 100644 (file)
@@ -1156,8 +1156,8 @@ int log_syntax_internal(
 
         PROTECT_ERRNO;
         char buffer[LINE_MAX];
 
         PROTECT_ERRNO;
         char buffer[LINE_MAX];
-        int r;
         va_list ap;
         va_list ap;
+        const char *unit_fmt = NULL;
 
         if (error < 0)
                 error = -error;
 
         if (error < 0)
                 error = -error;
@@ -1176,24 +1176,15 @@ int log_syntax_internal(
         va_end(ap);
 
         if (unit)
         va_end(ap);
 
         if (unit)
-                r = log_struct_internal(
-                                level, error,
-                                file, line, func,
-                                getpid() == 1 ? "UNIT=%s" : "USER_UNIT=%s", unit,
-                                LOG_MESSAGE_ID(SD_MESSAGE_INVALID_CONFIGURATION),
-                                "CONFIG_FILE=%s", config_file,
-                                "CONFIG_LINE=%u", config_line,
-                                LOG_MESSAGE("[%s:%u] %s", config_file, config_line, buffer),
-                                NULL);
-        else
-                r = log_struct_internal(
-                                level, error,
-                                file, line, func,
-                                LOG_MESSAGE_ID(SD_MESSAGE_INVALID_CONFIGURATION),
-                                "CONFIG_FILE=%s", config_file,
-                                "CONFIG_LINE=%u", config_line,
-                                LOG_MESSAGE("[%s:%u] %s", config_file, config_line, buffer),
-                                NULL);
-
-        return r;
+                unit_fmt = getpid() == 1 ? "UNIT=%s" : "USER_UNIT=%s";
+
+        return log_struct_internal(
+                        level, error,
+                        file, line, func,
+                        LOG_MESSAGE_ID(SD_MESSAGE_INVALID_CONFIGURATION),
+                        "CONFIG_FILE=%s", config_file,
+                        "CONFIG_LINE=%u", config_line,
+                        LOG_MESSAGE("[%s:%u] %s", config_file, config_line, buffer),
+                        unit_fmt, unit,
+                        NULL);
 }
 }