[systemd-commits] 2 commits - src/kmsg-syslogd.c src/logger.c src/util.c src/util.h units/systemd-initctl.socket
Lennart Poettering
lennart at kemper.freedesktop.org
Sun Apr 3 13:15:23 PDT 2011
src/kmsg-syslogd.c | 57 ++++++++-----------------------------------
src/logger.c | 38 ----------------------------
src/util.c | 36 +++++++++++++++++++++++++++
src/util.h | 2 +
units/systemd-initctl.socket | 2 -
5 files changed, 51 insertions(+), 84 deletions(-)
New commits:
commit 99ee2e92956b5f31a55172acffea0c2b5745fa81
Author: Lennart Poettering <lennart at poettering.net>
Date: Sun Apr 3 22:14:56 2011 +0200
initctl: /dev/initctl is a named pipe, not a socket
diff --git a/units/systemd-initctl.socket b/units/systemd-initctl.socket
index 403b322..7a3a023 100644
--- a/units/systemd-initctl.socket
+++ b/units/systemd-initctl.socket
@@ -8,7 +8,7 @@
# See systemd.special(7) for details
[Unit]
-Description=/dev/initctl Compatibility Socket
+Description=/dev/initctl Compatibility Named Pipe
DefaultDependencies=no
Before=sockets.target
commit 7c3b203c5c69fc37c8d143851cd395cbf8920786
Author: Lennart Poettering <lennart at poettering.net>
Date: Sun Apr 3 22:14:34 2011 +0200
kmsg-syslogd: pass facility value into kmsg
diff --git a/src/kmsg-syslogd.c b/src/kmsg-syslogd.c
index c78011f..60d3244 100644
--- a/src/kmsg-syslogd.c
+++ b/src/kmsg-syslogd.c
@@ -154,50 +154,6 @@ fail:
return r;
}
-static int read_priority(const char **buf) {
- int priority;
- size_t n;
- const char *p;
- int a, b, c;
-
- assert(buf);
- assert(*buf);
-
- p = *buf;
- n = strlen(p);
-
- if (n < 3 || p[0] != '<')
- goto fail;
-
- if (p[2] == '>') {
- a = b = 0;
- c = undecchar(p[1]);
- p += 3;
- } else if (n >= 4 && p[3] == '>') {
- a = 0;
- b = undecchar(p[1]);
- c = undecchar(p[2]);
- p += 4;
- } else if (n >= 5 && p[4] == '>') {
- a = undecchar(p[1]);
- b = undecchar(p[2]);
- c = undecchar(p[3]);
- p += 5;
- } else
- goto fail;
-
- if (a < 0 || b < 0 || c < 0)
- goto fail;
-
- *buf = p;
-
- priority = 100*a + 10*b + c;
- return LOG_PRI(priority);
-
-fail:
- return LOG_INFO;
-}
-
static void skip_date(const char **buf) {
enum {
LETTER,
@@ -334,17 +290,26 @@ static void skip_pid(const char **buf) {
static int write_message(Server *s, const char *buf, struct ucred *ucred) {
ssize_t k;
- char priority[4], pid[16];
+ char priority[6], pid[16];
struct iovec iovec[5];
unsigned i = 0;
char *process = NULL;
int r = 0;
+ int prio = LOG_USER | LOG_INFO;
assert(s);
assert(buf);
+ parse_syslog_priority((char**) &buf, &prio);
+
+ if (*buf == 0)
+ return 0;
+
+ if ((prio & LOG_FACMASK) == 0)
+ prio = LOG_USER | LOG_PRI(prio);
+
/* First, set priority field */
- snprintf(priority, sizeof(priority), "<%i>", read_priority(&buf));
+ snprintf(priority, sizeof(priority), "<%i>", prio);
char_array_0(priority);
IOVEC_SET_STRING(iovec[i++], priority);
diff --git a/src/logger.c b/src/logger.c
index eb62688..faa6c97 100644
--- a/src/logger.c
+++ b/src/logger.c
@@ -93,42 +93,6 @@ struct Stream {
LIST_FIELDS(Stream, stream);
};
-static void parse_priority(char **p, int *priority) {
- int a = 0, b = 0, c = 0;
- int k;
-
- assert(p);
- assert(*p);
- assert(priority);
-
- if ((*p)[0] != '<')
- return;
-
- if (!strchr(*p, '>'))
- return;
-
- 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;
-
- if (a < 0 || b < 0 || c < 0)
- return;
-
- *priority = a*100+b*10+c;
- *p += k;
-}
-
static int stream_log(Stream *s, char *p, usec_t ts) {
char header_priority[16], header_time[64], header_pid[16];
@@ -141,7 +105,7 @@ static int stream_log(Stream *s, char *p, usec_t ts) {
priority = s->priority;
if (s->prefix)
- parse_priority(&p, &priority);
+ parse_syslog_priority(&p, &priority);
if (*p == 0)
return 0;
diff --git a/src/util.c b/src/util.c
index 2a5f307..a1686ed 100644
--- a/src/util.c
+++ b/src/util.c
@@ -4191,6 +4191,42 @@ bool plymouth_running(void) {
return access("/run/plymouth/pid", F_OK) >= 0;
}
+void parse_syslog_priority(char **p, int *priority) {
+ int a = 0, b = 0, c = 0;
+ int k;
+
+ assert(p);
+ assert(*p);
+ assert(priority);
+
+ if ((*p)[0] != '<')
+ return;
+
+ if (!strchr(*p, '>'))
+ return;
+
+ 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;
+
+ if (a < 0 || b < 0 || c < 0)
+ return;
+
+ *priority = a*100+b*10+c;
+ *p += k;
+}
+
static const char *const ioprio_class_table[] = {
[IOPRIO_CLASS_NONE] = "none",
[IOPRIO_CLASS_RT] = "realtime",
diff --git a/src/util.h b/src/util.h
index cc63dd1..ff38b35 100644
--- a/src/util.h
+++ b/src/util.h
@@ -394,6 +394,8 @@ bool nulstr_contains(const char*nulstr, const char *needle);
bool plymouth_running(void);
+void parse_syslog_priority(char **p, int *priority);
+
#define NULSTR_FOREACH(i, l) \
for ((i) = (l); (i) && *(i); (i) = strchr((i), 0)+1)
More information about the systemd-commits
mailing list