]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
util-lib: split out syslog-related calls into syslog-util.[ch]
authorLennart Poettering <lennart@poettering.net>
Mon, 26 Oct 2015 23:40:25 +0000 (00:40 +0100)
committerLennart Poettering <lennart@poettering.net>
Tue, 27 Oct 2015 12:25:57 +0000 (13:25 +0100)
17 files changed:
Makefile.am
src/basic/log.c
src/basic/syslog-util.c [new file with mode: 0644]
src/basic/syslog-util.h [new file with mode: 0644]
src/basic/util.c
src/basic/util.h
src/core/dbus-execute.c
src/core/dbus-manager.c
src/core/execute.c
src/import/importd.c
src/journal/cat.c
src/journal/journalctl.c
src/journal/journald-stream.c
src/journal/journald-syslog.c
src/libudev/libudev-util.c
src/shared/bus-util.c
src/shared/conf-parser.c

index 549ac014e3d5c0db7b19c57c20c7f9afe1b14b65..78788f65e962bd40f0a779195b1778a0278796e7 100644 (file)
@@ -803,6 +803,8 @@ libbasic_la_SOURCES = \
        src/basic/proc-cmdline.h \
        src/basic/fs-util.c \
        src/basic/fs-util.h \
+       src/basic/syslog-util.c \
+       src/basic/syslog-util.h \
        src/basic/stat-util.c \
        src/basic/stat-util.h \
        src/basic/mount-util.c \
index d0db77eca0ab978b8b069e963a24cd10f96e6ff5..c99746f9167943e5e5830332d7353f15cc05f9d1 100644 (file)
@@ -43,6 +43,7 @@
 #include "socket-util.h"
 #include "string-table.h"
 #include "string-util.h"
+#include "syslog-util.h"
 #include "terminal-util.h"
 #include "util.h"
 
diff --git a/src/basic/syslog-util.c b/src/basic/syslog-util.c
new file mode 100644 (file)
index 0000000..0157794
--- /dev/null
@@ -0,0 +1,115 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
+/***
+  This file is part of systemd.
+
+  Copyright 2010 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 <syslog.h>
+
+#include "assert.h"
+#include "hexdecoct.h"
+#include "string-table.h"
+#include "syslog-util.h"
+
+int syslog_parse_priority(const char **p, int *priority, bool with_facility) {
+        int a = 0, b = 0, c = 0;
+        int k;
+
+        assert(p);
+        assert(*p);
+        assert(priority);
+
+        if ((*p)[0] != '<')
+                return 0;
+
+        if (!strchr(*p, '>'))
+                return 0;
+
+        if ((*p)[2] == '>') {
+                c = undecchar((*p)[1]);
+                k = 3;
+        } else if ((*p)[3] == '>') {
+                b = undecchar((*p)[1]);
+                c = undecchar((*p)[2]);
+                k = 4;
+        } else if ((*p)[4] == '>') {
+                a = undecchar((*p)[1]);
+                b = undecchar((*p)[2]);
+                c = undecchar((*p)[3]);
+                k = 5;
+        } else
+                return 0;
+
+        if (a < 0 || b < 0 || c < 0 ||
+            (!with_facility && (a || b || c > 7)))
+                return 0;
+
+        if (with_facility)
+                *priority = a*100 + b*10 + c;
+        else
+                *priority = (*priority & LOG_FACMASK) | c;
+
+        *p += k;
+        return 1;
+}
+
+static const char *const log_facility_unshifted_table[LOG_NFACILITIES] = {
+        [LOG_FAC(LOG_KERN)] = "kern",
+        [LOG_FAC(LOG_USER)] = "user",
+        [LOG_FAC(LOG_MAIL)] = "mail",
+        [LOG_FAC(LOG_DAEMON)] = "daemon",
+        [LOG_FAC(LOG_AUTH)] = "auth",
+        [LOG_FAC(LOG_SYSLOG)] = "syslog",
+        [LOG_FAC(LOG_LPR)] = "lpr",
+        [LOG_FAC(LOG_NEWS)] = "news",
+        [LOG_FAC(LOG_UUCP)] = "uucp",
+        [LOG_FAC(LOG_CRON)] = "cron",
+        [LOG_FAC(LOG_AUTHPRIV)] = "authpriv",
+        [LOG_FAC(LOG_FTP)] = "ftp",
+        [LOG_FAC(LOG_LOCAL0)] = "local0",
+        [LOG_FAC(LOG_LOCAL1)] = "local1",
+        [LOG_FAC(LOG_LOCAL2)] = "local2",
+        [LOG_FAC(LOG_LOCAL3)] = "local3",
+        [LOG_FAC(LOG_LOCAL4)] = "local4",
+        [LOG_FAC(LOG_LOCAL5)] = "local5",
+        [LOG_FAC(LOG_LOCAL6)] = "local6",
+        [LOG_FAC(LOG_LOCAL7)] = "local7"
+};
+
+DEFINE_STRING_TABLE_LOOKUP_WITH_FALLBACK(log_facility_unshifted, int, LOG_FAC(~0));
+
+bool log_facility_unshifted_is_valid(int facility) {
+        return facility >= 0 && facility <= LOG_FAC(~0);
+}
+
+static const char *const log_level_table[] = {
+        [LOG_EMERG] = "emerg",
+        [LOG_ALERT] = "alert",
+        [LOG_CRIT] = "crit",
+        [LOG_ERR] = "err",
+        [LOG_WARNING] = "warning",
+        [LOG_NOTICE] = "notice",
+        [LOG_INFO] = "info",
+        [LOG_DEBUG] = "debug"
+};
+
+DEFINE_STRING_TABLE_LOOKUP_WITH_FALLBACK(log_level, int, LOG_DEBUG);
+
+bool log_level_is_valid(int level) {
+        return level >= 0 && level <= LOG_DEBUG;
+}
diff --git a/src/basic/syslog-util.h b/src/basic/syslog-util.h
new file mode 100644 (file)
index 0000000..eb79c6d
--- /dev/null
@@ -0,0 +1,34 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
+#pragma once
+
+/***
+  This file is part of systemd.
+
+  Copyright 2010 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 <stdbool.h>
+
+int log_facility_unshifted_to_string_alloc(int i, char **s);
+int log_facility_unshifted_from_string(const char *s);
+bool log_facility_unshifted_is_valid(int faciliy);
+
+int log_level_to_string_alloc(int i, char **s);
+int log_level_from_string(const char *s);
+bool log_level_is_valid(int level);
+
+int syslog_parse_priority(const char **p, int *priority, bool with_facility);
index 8c5e88f00c57f6c08bf074b30924479bbb1775b8..55decc7eea0a52f216835c0d185ed034fcc4a249 100644 (file)
@@ -491,52 +491,6 @@ static const char *const sigchld_code_table[] = {
 
 DEFINE_STRING_TABLE_LOOKUP(sigchld_code, int);
 
-static const char *const log_facility_unshifted_table[LOG_NFACILITIES] = {
-        [LOG_FAC(LOG_KERN)] = "kern",
-        [LOG_FAC(LOG_USER)] = "user",
-        [LOG_FAC(LOG_MAIL)] = "mail",
-        [LOG_FAC(LOG_DAEMON)] = "daemon",
-        [LOG_FAC(LOG_AUTH)] = "auth",
-        [LOG_FAC(LOG_SYSLOG)] = "syslog",
-        [LOG_FAC(LOG_LPR)] = "lpr",
-        [LOG_FAC(LOG_NEWS)] = "news",
-        [LOG_FAC(LOG_UUCP)] = "uucp",
-        [LOG_FAC(LOG_CRON)] = "cron",
-        [LOG_FAC(LOG_AUTHPRIV)] = "authpriv",
-        [LOG_FAC(LOG_FTP)] = "ftp",
-        [LOG_FAC(LOG_LOCAL0)] = "local0",
-        [LOG_FAC(LOG_LOCAL1)] = "local1",
-        [LOG_FAC(LOG_LOCAL2)] = "local2",
-        [LOG_FAC(LOG_LOCAL3)] = "local3",
-        [LOG_FAC(LOG_LOCAL4)] = "local4",
-        [LOG_FAC(LOG_LOCAL5)] = "local5",
-        [LOG_FAC(LOG_LOCAL6)] = "local6",
-        [LOG_FAC(LOG_LOCAL7)] = "local7"
-};
-
-DEFINE_STRING_TABLE_LOOKUP_WITH_FALLBACK(log_facility_unshifted, int, LOG_FAC(~0));
-
-bool log_facility_unshifted_is_valid(int facility) {
-        return facility >= 0 && facility <= LOG_FAC(~0);
-}
-
-static const char *const log_level_table[] = {
-        [LOG_EMERG] = "emerg",
-        [LOG_ALERT] = "alert",
-        [LOG_CRIT] = "crit",
-        [LOG_ERR] = "err",
-        [LOG_WARNING] = "warning",
-        [LOG_NOTICE] = "notice",
-        [LOG_INFO] = "info",
-        [LOG_DEBUG] = "debug"
-};
-
-DEFINE_STRING_TABLE_LOOKUP_WITH_FALLBACK(log_level, int, LOG_DEBUG);
-
-bool log_level_is_valid(int level) {
-        return level >= 0 && level <= LOG_DEBUG;
-}
-
 static const char* const sched_policy_table[] = {
         [SCHED_OTHER] = "other",
         [SCHED_BATCH] = "batch",
@@ -1199,48 +1153,6 @@ int update_reboot_param_file(const char *param) {
         return 0;
 }
 
-int syslog_parse_priority(const char **p, int *priority, bool with_facility) {
-        int a = 0, b = 0, c = 0;
-        int k;
-
-        assert(p);
-        assert(*p);
-        assert(priority);
-
-        if ((*p)[0] != '<')
-                return 0;
-
-        if (!strchr(*p, '>'))
-                return 0;
-
-        if ((*p)[2] == '>') {
-                c = undecchar((*p)[1]);
-                k = 3;
-        } else if ((*p)[3] == '>') {
-                b = undecchar((*p)[1]);
-                c = undecchar((*p)[2]);
-                k = 4;
-        } else if ((*p)[4] == '>') {
-                a = undecchar((*p)[1]);
-                b = undecchar((*p)[2]);
-                c = undecchar((*p)[3]);
-                k = 5;
-        } else
-                return 0;
-
-        if (a < 0 || b < 0 || c < 0 ||
-            (!with_facility && (a || b || c > 7)))
-                return 0;
-
-        if (with_facility)
-                *priority = a*100 + b*10 + c;
-        else
-                *priority = (*priority & LOG_FACMASK) | c;
-
-        *p += k;
-        return 1;
-}
-
 int version(void) {
         puts(PACKAGE_STRING "\n"
              SYSTEMD_FEATURES);
index c3992349df31fd5cceaedc6370317b0be7ed32a7..6c3434d15b853da9bdeb83ce4e1100032cf1849e 100644 (file)
@@ -115,14 +115,6 @@ int ioprio_class_from_string(const char *s);
 const char *sigchld_code_to_string(int i) _const_;
 int sigchld_code_from_string(const char *s) _pure_;
 
-int log_facility_unshifted_to_string_alloc(int i, char **s);
-int log_facility_unshifted_from_string(const char *s);
-bool log_facility_unshifted_is_valid(int faciliy);
-
-int log_level_to_string_alloc(int i, char **s);
-int log_level_from_string(const char *s);
-bool log_level_is_valid(int level);
-
 int sched_policy_to_string_alloc(int i, char **s);
 int sched_policy_from_string(const char *s);
 
@@ -335,8 +327,6 @@ union inotify_event_buffer {
         uint8_t raw[INOTIFY_EVENT_MAX];
 };
 
-int syslog_parse_priority(const char **p, int *priority, bool with_facility);
-
 int version(void);
 
 bool fdname_is_valid(const char *s);
index 35f1b2913be00257091fc2413f6b7db3a3e798b2..67405a16726fce98b9b2f03a21b4a1858551a8a0 100644 (file)
@@ -43,6 +43,7 @@
 #include "seccomp-util.h"
 #endif
 #include "strv.h"
+#include "syslog-util.h"
 #include "utf8.h"
 
 BUS_DEFINE_PROPERTY_GET_ENUM(bus_property_get_exec_output, exec_output, ExecOutput);
index f737140363db0dbda552f72102f338fa784bdb30..3f631bd9a0feede575f6266f8f972115e2b2b55f 100644 (file)
@@ -44,6 +44,7 @@
 #include "stat-util.h"
 #include "string-util.h"
 #include "strv.h"
+#include "syslog-util.h"
 #include "virt.h"
 #include "watchdog.h"
 
index 2982125b824863a30dbadc752c4d7fcc8aeae899..3814fd438189526b0ff81eed3656ce3029868eef 100644 (file)
@@ -92,6 +92,7 @@
 #include "string-table.h"
 #include "string-util.h"
 #include "strv.h"
+#include "syslog-util.h"
 #include "terminal-util.h"
 #include "unit.h"
 #include "user-util.h"
index 2a03507d3a66a566815ab452f2ac3e2aa42423fa..3c57713fa55f1d80b48493a486a27a7fd500764d 100644 (file)
@@ -39,6 +39,7 @@
 #include "socket-util.h"
 #include "string-table.h"
 #include "strv.h"
+#include "syslog-util.h"
 #include "util.h"
 
 typedef struct Transfer Transfer;
index 95a1868b939a1746c6d39741d1e802e76bcb1eb4..7fd4198df88b16efb46a0f24e59c8ba7a89fd599 100644 (file)
@@ -31,6 +31,7 @@
 #include "fd-util.h"
 #include "parse-util.h"
 #include "string-util.h"
+#include "syslog-util.h"
 #include "util.h"
 
 static char *arg_identifier = NULL;
index 8b8c50b4369e74e27f45582d9000416ea72bd22d..1965522dfd16ba56113c31db6e5f0aeccfccefdf 100644 (file)
@@ -65,6 +65,7 @@
 #include "set.h"
 #include "sigbus.h"
 #include "strv.h"
+#include "syslog-util.h"
 #include "terminal-util.h"
 #include "unit-name.h"
 #include "user-util.h"
index a9c940690f7145600a6e98681393ac91d5cb8c60..8d9c416bc97627b56bab590b56e11cc8f0a3c547 100644 (file)
@@ -44,6 +44,7 @@
 #include "selinux-util.h"
 #include "socket-util.h"
 #include "string-util.h"
+#include "syslog-util.h"
 
 #define STDOUT_STREAMS_MAX 4096
 
index 7e9ba1256029933ae7c810e2dfd00a3973e291bf..488cccb6d9c29319c43a39fb972a8641264f36fa 100644 (file)
@@ -36,6 +36,7 @@
 #include "selinux-util.h"
 #include "socket-util.h"
 #include "string-util.h"
+#include "syslog-util.h"
 
 /* Warn once every 30s if we missed syslog message */
 #define WARN_FORWARD_SYSLOG_MISSED_USEC (30 * USEC_PER_SEC)
index a614230df43c4ff5c77d3918d768b3aef4059b7c..574cfeac85684dd9bdafb12f6fd8b861b81434b6 100644 (file)
@@ -29,6 +29,7 @@
 #include "MurmurHash2.h"
 #include "device-nodes.h"
 #include "libudev-private.h"
+#include "syslog-util.h"
 #include "utf8.h"
 
 /**
index 9fcc61dbd22c730ab52fef37e8cac58b4e663fa6..c854ff43442df80d76382e1770dc962d73b05e9e 100644 (file)
@@ -44,6 +44,7 @@
 #include "signal-util.h"
 #include "string-util.h"
 #include "strv.h"
+#include "syslog-util.h"
 #include "unit-name.h"
 #include "utf8.h"
 #include "util.h"
index 4235e95d92c72fa2aa8ce67bcf9cbee1f0798ff2..fa13eb80758f6ee20e6220adb7538f97967ce766 100644 (file)
@@ -39,6 +39,7 @@
 #include "strv.h"
 #include "utf8.h"
 #include "util.h"
+#include "syslog-util.h"
 
 int config_item_table_lookup(
                 const void *table,