Blob Blame History Raw
From 3e1a7de638aec192ae7ac25baea7e8c343ab414b Mon Sep 17 00:00:00 2001
From: Lennart Poettering <lennart@poettering.net>
Date: Thu, 5 Jan 2012 03:25:10 +0100
Subject: [PATCH 113/126] log: minor optimization (cherry picked from commit
 674f8283698517047a7c0e78cff1e18932a97b05)

---
 src/log.c |   13 ++++++++-----
 1 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/src/log.c b/src/log.c
index 4f57821..3dfe654 100644
--- a/src/log.c
+++ b/src/log.c
@@ -95,7 +95,8 @@ static int log_open_kmsg(void) {
         if (kmsg_fd >= 0)
                 return 0;
 
-        if ((kmsg_fd = open("/dev/kmsg", O_WRONLY|O_NOCTTY|O_CLOEXEC)) < 0) {
+        kmsg_fd = open("/dev/kmsg", O_WRONLY|O_NOCTTY|O_CLOEXEC);
+        if (kmsg_fd < 0) {
                 log_error("Failed to open /dev/kmsg for logging: %s", strerror(errno));
                 return -errno;
         }
@@ -265,14 +266,16 @@ static int write_to_console(
         if (console_fd < 0)
                 return 0;
 
-        snprintf(location, sizeof(location), "(%s:%u) ", file, line);
-        char_array_0(location);
-
         highlight = LOG_PRI(level) <= LOG_ERR && show_color;
 
         zero(iovec);
-        if (show_location)
+
+        if (show_location) {
+                snprintf(location, sizeof(location), "(%s:%u) ", file, line);
+                char_array_0(location);
                 IOVEC_SET_STRING(iovec[n++], location);
+        }
+
         if (highlight)
                 IOVEC_SET_STRING(iovec[n++], ANSI_HIGHLIGHT_ON);
         IOVEC_SET_STRING(iovec[n++], buffer);
-- 
1.7.7.5