chiark / gitweb /
shared: call va_end in all cases
[elogind.git] / src / shared / log.c
index 67a3e1b843bc41272f1420530557c1ce6ea786ee..b61845859f3cca5300b7750fa812a564cd2c3913 100644 (file)
@@ -30,6 +30,7 @@
 
 #include "log.h"
 #include "util.h"
+#include "missing.h"
 #include "macro.h"
 #include "socket-util.h"
 
@@ -72,14 +73,9 @@ static int log_open_console(void) {
                 return 0;
 
         if (getpid() == 1) {
-
                 console_fd = open_terminal("/dev/console", O_WRONLY|O_NOCTTY|O_CLOEXEC);
-                if (console_fd < 0) {
-                        log_error("Failed to open /dev/console for logging: %s", strerror(-console_fd));
+                if (console_fd < 0)
                         return console_fd;
-                }
-
-                log_debug("Successfully opened /dev/console for logging.");
         } else
                 console_fd = STDERR_FILENO;
 
@@ -101,12 +97,8 @@ static int log_open_kmsg(void) {
                 return 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));
+        if (kmsg_fd < 0)
                 return -errno;
-        }
-
-        log_debug("Successfully opened /dev/kmsg for logging.");
 
         return 0;
 }
@@ -173,13 +165,10 @@ static int log_open_syslog(void) {
         } else
                 syslog_is_stream = false;
 
-        log_debug("Successfully opened syslog for logging.");
-
         return 0;
 
 fail:
         log_close_syslog();
-        log_debug("Failed to open syslog for logging: %s", strerror(-r));
         return r;
 }
 
@@ -214,13 +203,10 @@ static int log_open_journal(void) {
                 goto fail;
         }
 
-        log_debug("Successfully opened journal for logging.");
-
         return 0;
 
 fail:
         log_close_journal();
-        log_debug("Failed to open journal for logging: %s", strerror(-r));
         return r;
 }
 
@@ -733,7 +719,6 @@ int log_struct_internal(
 
                         format = va_arg(ap, char *);
                 }
-                va_end(ap);
 
                 zero(mh);
                 mh.msg_iov = iovec;
@@ -745,6 +730,7 @@ int log_struct_internal(
                         r = 1;
 
         finish:
+                va_end(ap);
                 for (i = 1; i < n; i += 2)
                         free(iovec[i].iov_base);
 
@@ -804,19 +790,19 @@ int log_set_max_level_from_string(const char *e) {
 void log_parse_environment(void) {
         const char *e;
 
-        e = __secure_getenv("SYSTEMD_LOG_TARGET");
+        e = secure_getenv("SYSTEMD_LOG_TARGET");
         if (e && log_set_target_from_string(e) < 0)
                 log_warning("Failed to parse log target %s. Ignoring.", e);
 
-        e = __secure_getenv("SYSTEMD_LOG_LEVEL");
+        e = secure_getenv("SYSTEMD_LOG_LEVEL");
         if (e && log_set_max_level_from_string(e) < 0)
                 log_warning("Failed to parse log level %s. Ignoring.", e);
 
-        e = __secure_getenv("SYSTEMD_LOG_COLOR");
+        e = secure_getenv("SYSTEMD_LOG_COLOR");
         if (e && log_show_color_from_string(e) < 0)
                 log_warning("Failed to parse bool %s. Ignoring.", e);
 
-        e = __secure_getenv("SYSTEMD_LOG_LOCATION");
+        e = secure_getenv("SYSTEMD_LOG_LOCATION");
         if (e && log_show_location_from_string(e) < 0)
                 log_warning("Failed to parse bool %s. Ignoring.", e);
 }
@@ -859,6 +845,13 @@ int log_show_location_from_string(const char *e) {
         return 0;
 }
 
+bool log_on_console(void) {
+        if (log_target == LOG_TARGET_CONSOLE)
+                return true;
+
+        return syslog_fd < 0 && kmsg_fd < 0 && journal_fd < 0;
+}
+
 static const char *const log_target_table[] = {
         [LOG_TARGET_CONSOLE] = "console",
         [LOG_TARGET_KMSG] = "kmsg",