chiark / gitweb /
execute: talk directly to the journald, instead to the stdout-syslog-bridge
authorLennart Poettering <lennart@poettering.net>
Thu, 5 Jan 2012 20:39:08 +0000 (21:39 +0100)
committerLennart Poettering <lennart@poettering.net>
Thu, 5 Jan 2012 20:39:08 +0000 (21:39 +0100)
src/execute.c
src/execute.h
src/special.h
src/unit.c

index abbbfddedc69413d4297638e4c0a457228898ff3..a35733259efbdca0a787d99737fe8dedc110c743 100644 (file)
@@ -173,24 +173,23 @@ static int open_null_as(int flags, int nfd) {
 
 static int connect_logger_as(const ExecContext *context, ExecOutput output, const char *ident, int nfd) {
         int fd, r;
-        union {
-                struct sockaddr sa;
-                struct sockaddr_un un;
-        } sa;
+        union sockaddr_union sa;
 
         assert(context);
         assert(output < _EXEC_OUTPUT_MAX);
         assert(ident);
         assert(nfd >= 0);
 
-        if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0)
+        fd = socket(AF_UNIX, SOCK_STREAM, 0);
+        if (fd < 0)
                 return -errno;
 
         zero(sa);
-        sa.sa.sa_family = AF_UNIX;
-        strncpy(sa.un.sun_path, STDOUT_SYSLOG_BRIDGE_SOCKET, sizeof(sa.un.sun_path));
+        sa.un.sun_family = AF_UNIX;
+        strncpy(sa.un.sun_path, "/run/systemd/journal/stdout", sizeof(sa.un.sun_path));
 
-        if (connect(fd, &sa.sa, offsetof(struct sockaddr_un, sun_path) + sizeof(STDOUT_SYSLOG_BRIDGE_SOCKET) - 1) < 0) {
+        r = connect(fd, &sa.sa, offsetof(struct sockaddr_un, sun_path) + strlen(sa.un.sun_path));
+        if (r < 0) {
                 close_nointr_nofail(fd);
                 return -errno;
         }
@@ -200,26 +199,19 @@ static int connect_logger_as(const ExecContext *context, ExecOutput output, cons
                 return -errno;
         }
 
-        /* We speak a very simple protocol between log server
-         * and client: one line for the log destination (kmsg
-         * or syslog), followed by the priority field,
-         * followed by the process name. Since we replaced
-         * stdin/stderr we simple use stdio to write to
-         * it. Note that we use stderr, to minimize buffer
-         * flushing issues. */
-
         dprintf(fd,
                 "%s\n"
                 "%i\n"
-                "%s\n"
+                "%i\n"
+                "%i\n"
+                "%i\n"
                 "%i\n",
-                output == EXEC_OUTPUT_KMSG ?             "kmsg" :
-                output == EXEC_OUTPUT_KMSG_AND_CONSOLE ? "kmsg+console" :
-                output == EXEC_OUTPUT_SYSLOG ?           "syslog" :
-                                                         "syslog+console",
-                context->syslog_priority,
                 context->syslog_identifier ? context->syslog_identifier : ident,
-                context->syslog_level_prefix);
+                context->syslog_priority,
+                !!context->syslog_level_prefix,
+                output == EXEC_OUTPUT_SYSLOG || output == EXEC_OUTPUT_SYSLOG_AND_CONSOLE,
+                output == EXEC_OUTPUT_KMSG || output == EXEC_OUTPUT_KMSG_AND_CONSOLE,
+                output == EXEC_OUTPUT_SYSLOG_AND_CONSOLE || output == EXEC_OUTPUT_KMSG_AND_CONSOLE);
 
         if (fd != nfd) {
                 r = dup2(fd, nfd) < 0 ? -errno : nfd;
index 77a2257e9be8ef91b425af0d0e640196eb5414b4..4f05c9fa4b29f9ef4385a3c1ab0e2f4941e60dc2 100644 (file)
@@ -40,8 +40,6 @@ struct CGroupAttribute;
 #include "list.h"
 #include "util.h"
 
-#define STDOUT_SYSLOG_BRIDGE_SOCKET "/run/systemd/stdout-syslog-bridge"
-
 typedef enum KillMode {
         KILL_CONTROL_GROUP = 0,
         KILL_PROCESS,
index 3fe34c955ca9cd2b3c44a5868abb18a4e5d31483..65b236a39410acd2db8c467d7eb5269fee339566 100644 (file)
@@ -70,7 +70,7 @@
 /* Services systemd relies on */
 #define SPECIAL_DBUS_SERVICE "dbus.service"
 #define SPECIAL_DBUS_SOCKET "dbus.socket"
-#define SPECIAL_STDOUT_SYSLOG_BRIDGE_SOCKET "systemd-stdout-syslog-bridge.socket"
+#define SPECIAL_JOURNALD_SOCKET "journald.socket"
 #define SPECIAL_SYSLOG_SOCKET "syslog.socket"
 
 /* Magic init signals */
index 3191071ae2c9337823814cd9decc12e259fb4924..b31b92fc24ebb054ae1f898f097aec81e2821db2 100644 (file)
@@ -573,7 +573,7 @@ int unit_add_exec_dependencies(Unit *u, ExecContext *c) {
          * logging daemon is run first. */
 
         if (u->meta.manager->running_as == MANAGER_SYSTEM)
-                if ((r = unit_add_two_dependencies_by_name(u, UNIT_REQUIRES, UNIT_AFTER, SPECIAL_STDOUT_SYSLOG_BRIDGE_SOCKET, NULL, true)) < 0)
+                if ((r = unit_add_two_dependencies_by_name(u, UNIT_REQUIRES, UNIT_AFTER, SPECIAL_JOURNALD_SOCKET, NULL, true)) < 0)
                         return r;
 
         return 0;