chiark / gitweb /
journald: do not create split journals for dynamic users
[elogind.git] / src / basic / log.c
index a5ee8f86121138608ddac521cc018744d16d2ad9..da6aa409b5b99b7ebef64f2420627db857fe9b1a 100644 (file)
@@ -1,5 +1,3 @@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-
 /***
   This file is part of systemd.
 
@@ -73,7 +71,9 @@ static bool syslog_is_stream = false;
 static bool show_color = false;
 static bool show_location = false;
 
-/// UNNEEDED by elogind  static bool upgrade_syslog_to_journal = false;
+#if 0 /// UNNEEDED by elogind
+static bool upgrade_syslog_to_journal = false;
+#endif // 0
 
 /* Akin to glibc's __abort_msg; which is private and we hence cannot
  * use here. */
@@ -167,7 +167,7 @@ static int log_open_syslog(void) {
                 goto fail;
         }
 
-        if (connect(syslog_fd, &sa.sa, offsetof(struct sockaddr_un, sun_path) + strlen(sa.un.sun_path)) < 0) {
+        if (connect(syslog_fd, &sa.sa, SOCKADDR_UN_LEN(sa.un)) < 0) {
                 safe_close(syslog_fd);
 
                 /* Some legacy syslog systems still use stream
@@ -179,7 +179,7 @@ static int log_open_syslog(void) {
                         goto fail;
                 }
 
-                if (connect(syslog_fd, &sa.sa, offsetof(struct sockaddr_un, sun_path) + strlen(sa.un.sun_path)) < 0) {
+                if (connect(syslog_fd, &sa.sa, SOCKADDR_UN_LEN(sa.un)) < 0) {
                         r = -errno;
                         goto fail;
                 }
@@ -195,11 +195,13 @@ fail:
         return r;
 }
 
-#if 0 /// UNNEEDED by elogind
 void log_close_journal(void) {
+#if 0 /// elogind does not support journald
         journal_fd = safe_close(journal_fd);
+#endif // 0
 }
 
+#if 0 /// UNNEEDED by elogind
 static int log_open_journal(void) {
 
         static const union sockaddr_union sa = {
@@ -218,7 +220,7 @@ static int log_open_journal(void) {
                 goto fail;
         }
 
-        if (connect(journal_fd, &sa.sa, offsetof(struct sockaddr_un, sun_path) + strlen(sa.un.sun_path)) < 0) {
+        if (connect(journal_fd, &sa.sa, SOCKADDR_UN_LEN(sa.un)) < 0) {
                 r = -errno;
                 goto fail;
         }
@@ -241,7 +243,7 @@ int log_open(void) {
          * because there is no reason to close it. */
 
         if (log_target == LOG_TARGET_NULL) {
-                /// UNNEEDED by elogind log_close_journal();
+                log_close_journal();
                 log_close_syslog();
                 log_close_console();
                 return 0;
@@ -263,11 +265,12 @@ int log_open(void) {
                         }
                 }
 #endif // 0
+
                 if (log_target == LOG_TARGET_SYSLOG_OR_KMSG ||
                     log_target == LOG_TARGET_SYSLOG) {
                         r = log_open_syslog();
                         if (r >= 0) {
-                                /// UNNEEDED by elogind log_close_journal();
+                                log_close_journal();
                                 log_close_console();
                                 return r;
                         }
@@ -275,12 +278,12 @@ int log_open(void) {
 
                 if (log_target == LOG_TARGET_AUTO ||
                     log_target == LOG_TARGET_SAFE ||
-                    /// UNNEEDED by elogind log_target == LOG_TARGET_JOURNAL_OR_KMSG ||
+                    log_target == LOG_TARGET_JOURNAL_OR_KMSG ||
                     log_target == LOG_TARGET_SYSLOG_OR_KMSG ||
                     log_target == LOG_TARGET_KMSG) {
                         r = log_open_kmsg();
                         if (r >= 0) {
-                                /// UNNEEDED by elogind log_close_journal();
+                                log_close_journal();
                                 log_close_syslog();
                                 log_close_console();
                                 return r;
@@ -288,7 +291,7 @@ int log_open(void) {
                 }
         }
 
-        /// UNNEEDED by elogind log_close_journal();
+        log_close_journal();
         log_close_syslog();
 
         return log_open_console();
@@ -311,7 +314,7 @@ void log_set_target(LogTarget target) {
 }
 
 void log_close(void) {
-        /// UNNEDED by elogind log_close_journal();
+        log_close_journal();
         log_close_syslog();
         log_close_kmsg();
         log_close_console();
@@ -343,7 +346,7 @@ static int write_to_console(
                 const char *object,
                 const char *buffer) {
 
-        char location[64], prefix[1 + DECIMAL_STR_MAX(int) + 2];
+        char location[256], prefix[1 + DECIMAL_STR_MAX(int) + 2];
         struct iovec iovec[6] = {};
         unsigned n = 0;
         bool highlight;
@@ -359,7 +362,7 @@ static int write_to_console(
         highlight = LOG_PRI(level) <= LOG_ERR && show_color;
 
         if (show_location) {
-                xsprintf(location, "(%s:%i) ", file, line);
+                snprintf(location, sizeof(location), "(%s:%i) ", file, line);
                 IOVEC_SET_STRING(iovec[n++], location);
         }
 
@@ -625,7 +628,7 @@ static int log_dispatch(
                     (log_target == LOG_TARGET_AUTO ||
                      log_target == LOG_TARGET_SAFE ||
                      log_target == LOG_TARGET_SYSLOG_OR_KMSG ||
-                     /// UNNEEDED by elogind log_target == LOG_TARGET_JOURNAL_OR_KMSG ||
+                     log_target == LOG_TARGET_JOURNAL_OR_KMSG ||
                      log_target == LOG_TARGET_KMSG)) {
 
                         k = write_to_kmsg(level, error, file, line, func, object_field, object, buffer);