chiark / gitweb /
systemd: add hardware watchdog support
[elogind.git] / src / log.c
index 949936762a14c91830bd917029afeca91a205b47..9fffc1dbc00ba2123cae35afbf3d4eb0156865eb 100644 (file)
--- a/src/log.c
+++ b/src/log.c
@@ -37,6 +37,7 @@
 
 static LogTarget log_target = LOG_TARGET_CONSOLE;
 static int log_max_level = LOG_INFO;
+static int log_facility = LOG_DAEMON;
 
 static int console_fd = STDERR_FILENO;
 static int syslog_fd = -1;
@@ -151,7 +152,7 @@ static int log_open_syslog(void) {
                 goto fail;
         }
 
-        if (connect(syslog_fd, &sa.sa, sizeof(sa)) < 0) {
+        if (connect(syslog_fd, &sa.sa, offsetof(struct sockaddr_un, sun_path) + strlen(sa.un.sun_path)) < 0) {
                 close_nointr_nofail(syslog_fd);
 
                 /* Some legacy syslog systems still use stream
@@ -163,7 +164,7 @@ static int log_open_syslog(void) {
                         goto fail;
                 }
 
-                if (connect(syslog_fd, &sa.sa, sizeof(sa)) < 0) {
+                if (connect(syslog_fd, &sa.sa, offsetof(struct sockaddr_un, sun_path) + strlen(sa.un.sun_path)) < 0) {
                         r = -errno;
                         goto fail;
                 }
@@ -310,6 +311,10 @@ void log_set_max_level(int level) {
         log_max_level = level;
 }
 
+void log_set_facility(int facility) {
+        log_facility = facility;
+}
+
 static int write_to_console(
                 int level,
                 const char*file,
@@ -457,11 +462,13 @@ static int write_to_journal(
 
         snprintf(header, sizeof(header),
                  "PRIORITY=%i\n"
+                 "SYSLOG_FACILITY=%i\n"
                  "CODE_FILE=%s\n"
                  "CODE_LINE=%i\n"
                  "CODE_FUNCTION=%s\n"
                  "MESSAGE=",
                  LOG_PRI(level),
+                 LOG_FAC(level),
                  file,
                  line,
                  func);
@@ -497,7 +504,7 @@ static int log_dispatch(
 
         /* Patch in LOG_DAEMON facility if necessary */
         if ((level & LOG_FACMASK) == 0)
-                level = LOG_DAEMON | LOG_PRI(level);
+                level = log_facility | LOG_PRI(level);
 
         do {
                 char *e;