chiark / gitweb /
journald: split console transport stuff into its own file
authorLennart Poettering <lennart@poettering.net>
Wed, 22 Aug 2012 01:36:29 +0000 (03:36 +0200)
committerLennart Poettering <lennart@poettering.net>
Wed, 22 Aug 2012 01:36:29 +0000 (03:36 +0200)
Makefile.am
src/journal/journald-console.c [new file with mode: 0644]
src/journal/journald-console.h [new file with mode: 0644]
src/journal/journald-stream.c
src/journal/journald-syslog.c
src/journal/journald.c
src/journal/journald.h

index a72da90260629a5bf45271f106b10ba759139d5d..dfcb960b0754d9c48e4840e0a3ff142656dfd341 100644 (file)
@@ -2315,6 +2315,8 @@ systemd_journald_SOURCES = \
        src/journal/journald-syslog.h \
        src/journal/journald-stream.c \
        src/journal/journald-stream.h \
+       src/journal/journald-console.c \
+       src/journal/journald-console.h \
        src/journal/journal-rate-limit.c \
        src/journal/journal-rate-limit.h \
        src/journal/journal-internal.h
diff --git a/src/journal/journald-console.c b/src/journal/journald-console.c
new file mode 100644 (file)
index 0000000..6cd2397
--- /dev/null
@@ -0,0 +1,85 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
+/***
+  This file is part of systemd.
+
+  Copyright 2011 Lennart Poettering
+
+  systemd is free software; you can redistribute it and/or modify it
+  under the terms of the GNU Lesser General Public License as published by
+  the Free Software Foundation; either version 2.1 of the License, or
+  (at your option) any later version.
+
+  systemd is distributed in the hope that it will be useful, but
+  WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public License
+  along with systemd; If not, see <http://www.gnu.org/licenses/>.
+***/
+
+#include <fcntl.h>
+#include <unistd.h>
+
+#include "journald.h"
+#include "journald-console.h"
+
+void server_forward_console(
+                Server *s,
+                int priority,
+                const char *identifier,
+                const char *message,
+                struct ucred *ucred) {
+
+        struct iovec iovec[4];
+        char header_pid[16];
+        int n = 0, fd;
+        char *ident_buf = NULL;
+        const char *tty;
+
+        assert(s);
+        assert(message);
+
+        if (LOG_PRI(priority) > s->max_level_console)
+                return;
+
+        /* First: identifier and PID */
+        if (ucred) {
+                if (!identifier) {
+                        get_process_comm(ucred->pid, &ident_buf);
+                        identifier = ident_buf;
+                }
+
+                snprintf(header_pid, sizeof(header_pid), "[%lu]: ", (unsigned long) ucred->pid);
+                char_array_0(header_pid);
+
+                if (identifier)
+                        IOVEC_SET_STRING(iovec[n++], identifier);
+
+                IOVEC_SET_STRING(iovec[n++], header_pid);
+        } else if (identifier) {
+                IOVEC_SET_STRING(iovec[n++], identifier);
+                IOVEC_SET_STRING(iovec[n++], ": ");
+        }
+
+        /* Third: message */
+        IOVEC_SET_STRING(iovec[n++], message);
+        IOVEC_SET_STRING(iovec[n++], "\n");
+
+        tty = s->tty_path ? s->tty_path : "/dev/console";
+
+        fd = open_terminal(tty, O_WRONLY|O_NOCTTY|O_CLOEXEC);
+        if (fd < 0) {
+                log_debug("Failed to open %s for logging: %s", tty, strerror(errno));
+                goto finish;
+        }
+
+        if (writev(fd, iovec, n) < 0)
+                log_debug("Failed to write to %s for logging: %s", tty, strerror(errno));
+
+        close_nointr_nofail(fd);
+
+finish:
+        free(ident_buf);
+}
diff --git a/src/journal/journald-console.h b/src/journal/journald-console.h
new file mode 100644 (file)
index 0000000..068cc5b
--- /dev/null
@@ -0,0 +1,26 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
+#pragma once
+
+/***
+  This file is part of systemd.
+
+  Copyright 2011 Lennart Poettering
+
+  systemd is free software; you can redistribute it and/or modify it
+  under the terms of the GNU Lesser General Public License as published by
+  the Free Software Foundation; either version 2.1 of the License, or
+  (at your option) any later version.
+
+  systemd is distributed in the hope that it will be useful, but
+  WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public License
+  along with systemd; If not, see <http://www.gnu.org/licenses/>.
+***/
+
+#include "journald.h"
+
+void server_forward_console(Server *s, int priority, const char *identifier, const char *message, struct ucred *ucred);
index 98fdf781bff9a05596d8d17a7d528b8492d7eb70..3e4022ad6942cb4e086ed70c4d49ec24ffa20948 100644 (file)
@@ -32,6 +32,7 @@
 #include "journald-stream.h"
 #include "journald-syslog.h"
 #include "journald-kmsg.h"
+#include "journald-console.h"
 
 #define STDOUT_STREAMS_MAX 4096
 
index 12c5b2849ce66ea11e5841b0f62f9527f01c1ead..daed095c291a4394c7eb25079ddae76c139ad5b8 100644 (file)
@@ -26,6 +26,7 @@
 #include "journald.h"
 #include "journald-syslog.h"
 #include "journald-kmsg.h"
+#include "journald-console.h"
 
 static void forward_syslog_iovec(Server *s, const struct iovec *iovec, unsigned n_iovec, struct ucred *ucred, struct timeval *tv) {
         struct msghdr msghdr;
index cce11f73dcb9c5a2d1b3436566c11c147984122b..5836119bede27ddf963370ac11a04a8368550801 100644 (file)
@@ -57,6 +57,7 @@
 #include "journald-kmsg.h"
 #include "journald-syslog.h"
 #include "journald-stream.h"
+#include "journald-console.h"
 
 #ifdef HAVE_ACL
 #include <sys/acl.h>
@@ -772,61 +773,6 @@ finish:
         dispatch_message_real(s, iovec, n, m, ucred, tv, label, label_len, unit_id);
 }
 
-void server_forward_console(Server *s, int priority, const char *identifier, const char *message, struct ucred *ucred) {
-        struct iovec iovec[4];
-        char header_pid[16];
-        int n = 0, fd;
-        char *ident_buf = NULL;
-        const char *tty;
-
-        assert(s);
-        assert(message);
-
-        if (LOG_PRI(priority) > s->max_level_console)
-                return;
-
-        /* First: identifier and PID */
-        if (ucred) {
-                if (!identifier) {
-                        get_process_comm(ucred->pid, &ident_buf);
-                        identifier = ident_buf;
-                }
-
-                snprintf(header_pid, sizeof(header_pid), "[%lu]: ", (unsigned long) ucred->pid);
-                char_array_0(header_pid);
-
-                if (identifier)
-                        IOVEC_SET_STRING(iovec[n++], identifier);
-
-                IOVEC_SET_STRING(iovec[n++], header_pid);
-        } else if (identifier) {
-                IOVEC_SET_STRING(iovec[n++], identifier);
-                IOVEC_SET_STRING(iovec[n++], ": ");
-        }
-
-        /* Third: message */
-        IOVEC_SET_STRING(iovec[n++], message);
-        IOVEC_SET_STRING(iovec[n++], "\n");
-
-        tty = s->tty_path ? s->tty_path : "/dev/console";
-
-        fd = open_terminal(tty, O_WRONLY|O_NOCTTY|O_CLOEXEC);
-        if (fd < 0) {
-                log_debug("Failed to open %s for logging: %s", tty, strerror(errno));
-                goto finish;
-        }
-
-        if (writev(fd, iovec, n) < 0)
-                log_debug("Failed to write to %s for logging: %s", tty, strerror(errno));
-
-        close_nointr_nofail(fd);
-
-finish:
-        free(ident_buf);
-}
-
-
-
 static bool valid_user_field(const char *p, size_t l) {
         const char *a;
 
index c2921164480590a0067606c5666c4d8b869d857e..e3a06d3cae0fe54c7e234c9362506b7f7fa698ea 100644 (file)
@@ -108,7 +108,6 @@ typedef struct Server {
 #define N_IOVEC_UDEV_FIELDS 32
 
 void server_dispatch_message(Server *s, struct iovec *iovec, unsigned n, unsigned m, struct ucred *ucred, struct timeval *tv, const char *label, size_t label_len, const char *unit_id, int priority);
-
 void server_driver_message(Server *s, sd_id128_t message_id, const char *format, ...);
 
 /* gperf lookup function */
@@ -118,5 +117,3 @@ int config_parse_storage(const char *filename, unsigned line, const char *sectio
 
 const char *storage_to_string(Storage s);
 Storage storage_from_string(const char *s);
-
-void server_forward_console(Server *s, int priority, const char *identifier, const char *message, struct ucred *ucred);