[systemd-commits] 5 commits - man/sd_session_is_active.xml src/execute.c src/execute.h src/journal src/login src/logs-show.c src/special.h src/systemd src/unit.c
Lennart Poettering
lennart at kemper.freedesktop.org
Thu Jan 5 14:14:36 PST 2012
man/sd_session_is_active.xml | 22 +++++
src/execute.c | 38 +++-------
src/execute.h | 2
src/journal/journal-send.c | 17 ++--
src/journal/journald.c | 154 ++++++++++++++++++++---------------------
src/login/libsystemd-login.sym | 1
src/login/sd-login.c | 28 +++++++
src/logs-show.c | 14 +--
src/special.h | 2
src/systemd/sd-journal.h | 3
src/systemd/sd-login.h | 3
src/unit.c | 2
12 files changed, 165 insertions(+), 121 deletions(-)
New commits:
commit eff406331adb23e27e4bd29a3b69322fc359ca3d
Author: Lennart Poettering <lennart at poettering.net>
Date: Thu Jan 5 23:14:22 2012 +0100
login: implement sd_session_get_service()
diff --git a/man/sd_session_is_active.xml b/man/sd_session_is_active.xml
index 88b22fd..516275e 100644
--- a/man/sd_session_is_active.xml
+++ b/man/sd_session_is_active.xml
@@ -46,6 +46,7 @@
<refname>sd_session_is_active</refname>
<refname>sd_session_get_uid</refname>
<refname>sd_session_get_seat</refname>
+ <refname>sd_session_get_service</refname>
<refpurpose>Determine state of a specific session</refpurpose>
</refnamediv>
@@ -69,6 +70,12 @@
<paramdef>const char* <parameter>session</parameter></paramdef>
<paramdef>char** <parameter>seat</parameter></paramdef>
</funcprototype>
+
+ <funcprototype>
+ <funcdef>int <function>sd_session_get_service</function></funcdef>
+ <paramdef>const char* <parameter>session</parameter></paramdef>
+ <paramdef>char** <parameter>service</parameter></paramdef>
+ </funcprototype>
</funcsynopsis>
</refsynopsisdiv>
@@ -94,6 +101,15 @@
returned string needs to be freed with the libc
<citerefentry><refentrytitle>free</refentrytitle><manvolnum>3</manvolnum></citerefentry>
call after use.</para>
+
+ <para><function>sd_session_get_service()</function>
+ may be used to determine the name of the service (as
+ passed during PAM session setup) that registered the
+ session identified by the specified session
+ identifier. The returned string needs to be freed with
+ the libc
+ <citerefentry><refentrytitle>free</refentrytitle><manvolnum>3</manvolnum></citerefentry>
+ call after use.</para>
</refsect1>
<refsect1>
@@ -102,7 +118,8 @@
<para>If the test succeeds
<function>sd_session_is_active()</function> returns a
positive integer, if it fails 0. On success
- <function>sd_session_get_uid()</function> and
+ <function>sd_session_get_uid()</function>,
+ <function>sd_session_get_service()</function> and
<function>sd_session_get_seat()</function> return 0 or
a positive integer. On failure, these calls return a
negative errno-style error code.</para>
@@ -112,7 +129,8 @@
<title>Notes</title>
<para>The <function>sd_session_is_active()</function>,
- <function>sd_session_get_uid()</function>, and
+ <function>sd_session_get_uid()</function>,
+ <function>sd_session_get_service()</function> and
<function>sd_session_get_seat()</function> interfaces
are available as shared library, which can be compiled
and linked to with the
diff --git a/src/login/libsystemd-login.sym b/src/login/libsystemd-login.sym
index 15e505e..3100c17 100644
--- a/src/login/libsystemd-login.sym
+++ b/src/login/libsystemd-login.sym
@@ -37,4 +37,5 @@ local:
LIBSYSTEMD_LOGIN_38 {
global:
sd_pid_get_unit;
+ sd_session_get_service;
} LIBSYSTEMD_LOGIN_31;
diff --git a/src/login/sd-login.c b/src/login/sd-login.c
index 8893b1d..ed98412 100644
--- a/src/login/sd-login.c
+++ b/src/login/sd-login.c
@@ -415,6 +415,34 @@ _public_ int sd_session_get_seat(const char *session, char **seat) {
return 0;
}
+_public_ int sd_session_get_service(const char *session, char **service) {
+ char *p, *s = NULL;
+ int r;
+
+ if (!session)
+ return -EINVAL;
+ if (!service)
+ return -EINVAL;
+
+ p = strappend("/run/systemd/sessions/", session);
+ if (!p)
+ return -ENOMEM;
+
+ r = parse_env_file(p, NEWLINE, "SERVICE", &s, NULL);
+ free(p);
+
+ if (r < 0) {
+ free(s);
+ return r;
+ }
+
+ if (isempty(s))
+ return -ENOENT;
+
+ *service = s;
+ return 0;
+}
+
_public_ int sd_seat_get_active(const char *seat, char **session, uid_t *uid) {
char *p, *s = NULL, *t = NULL;
int r;
diff --git a/src/systemd/sd-login.h b/src/systemd/sd-login.h
index 00de671..7d76f9a 100644
--- a/src/systemd/sd-login.h
+++ b/src/systemd/sd-login.h
@@ -83,6 +83,9 @@ int sd_session_get_uid(const char *session, uid_t *uid);
/* Determine seat of session */
int sd_session_get_seat(const char *session, char **seat);
+/* Determine the (PAM) service name this session was registered by. */
+int sd_session_get_service(const char *session, char **service);
+
/* Return active session and user of seat */
int sd_seat_get_active(const char *seat, char **session, uid_t *uid);
commit 4cd9a9d9ecf3a8835e21930f3215a5f5b74144be
Author: Lennart Poettering <lennart at poettering.net>
Date: Thu Jan 5 21:43:49 2012 +0100
journal: rename syslog tag to identifier since that's what we call it on the server side.
diff --git a/src/journal/journal-send.c b/src/journal/journal-send.c
index c382264..ddf503b 100644
--- a/src/journal/journal-send.c
+++ b/src/journal/journal-send.c
@@ -209,7 +209,7 @@ _public_ int sd_journal_sendv(const struct iovec *iov, int n) {
return 0;
}
-_public_ int sd_journal_stream_fd(const char *tag, int priority, int priority_prefix) {
+_public_ int sd_journal_stream_fd(const char *identifier, int priority, int level_prefix) {
union sockaddr_union sa;
int fd;
char *header;
@@ -238,17 +238,17 @@ _public_ int sd_journal_stream_fd(const char *tag, int priority, int priority_pr
return -errno;
}
- if (!tag)
- tag = "";
+ if (!identifier)
+ identifier = "";
- l = strlen(tag);
+ l = strlen(identifier);
header = alloca(l + 1 + 2 + 2 + 2 + 2 + 2);
- memcpy(header, tag, l);
+ memcpy(header, identifier, l);
header[l++] = '\n';
header[l++] = '0' + priority;
header[l++] = '\n';
- header[l++] = '0' + !!priority_prefix;
+ header[l++] = '0' + !!level_prefix;
header[l++] = '\n';
header[l++] = '0';
header[l++] = '\n';
diff --git a/src/journal/journald.c b/src/journal/journald.c
index 419ce26..b996e41 100644
--- a/src/journal/journald.c
+++ b/src/journal/journald.c
@@ -63,7 +63,7 @@
#define N_IOVEC_META_FIELDS 16
typedef enum StdoutStreamState {
- STDOUT_STREAM_TAG,
+ STDOUT_STREAM_IDENTIFIER,
STDOUT_STREAM_PRIORITY,
STDOUT_STREAM_LEVEL_PREFIX,
STDOUT_STREAM_FORWARD_TO_SYSLOG,
@@ -80,7 +80,7 @@ struct StdoutStream {
struct ucred ucred;
- char *tag;
+ char *identifier;
int priority;
bool level_prefix:1;
bool forward_to_syslog:1;
@@ -733,13 +733,13 @@ static void forward_syslog_raw(Server *s, const char *buffer, struct ucred *ucre
forward_syslog_iovec(s, &iovec, 1, ucred, tv);
}
-static void forward_syslog(Server *s, int priority, const char *tag, const char *message, struct ucred *ucred, struct timeval *tv) {
+static void forward_syslog(Server *s, int priority, const char *identifier, const char *message, struct ucred *ucred, struct timeval *tv) {
struct iovec iovec[5];
char header_priority[6], header_time[64], header_pid[16];
int n = 0;
time_t t;
struct tm *tm;
- char *tag_buf = NULL;
+ char *ident_buf = NULL;
assert(s);
assert(priority >= 0);
@@ -760,22 +760,22 @@ static void forward_syslog(Server *s, int priority, const char *tag, const char
return;
IOVEC_SET_STRING(iovec[n++], header_time);
- /* Third: tag and PID */
+ /* Third: identifier and PID */
if (ucred) {
- if (!tag) {
- get_process_comm(ucred->pid, &tag_buf);
- tag = tag_buf;
+ 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 (tag)
- IOVEC_SET_STRING(iovec[n++], tag);
+ if (identifier)
+ IOVEC_SET_STRING(iovec[n++], identifier);
IOVEC_SET_STRING(iovec[n++], header_pid);
- } else if (tag) {
- IOVEC_SET_STRING(iovec[n++], tag);
+ } else if (identifier) {
+ IOVEC_SET_STRING(iovec[n++], identifier);
IOVEC_SET_STRING(iovec[n++], ": ");
}
@@ -784,7 +784,7 @@ static void forward_syslog(Server *s, int priority, const char *tag, const char
forward_syslog_iovec(s, iovec, n, ucred, tv);
- free(tag_buf);
+ free(ident_buf);
}
static int fixup_priority(int priority) {
@@ -795,11 +795,11 @@ static int fixup_priority(int priority) {
return priority;
}
-static void forward_kmsg(Server *s, int priority, const char *tag, const char *message, struct ucred *ucred) {
+static void forward_kmsg(Server *s, int priority, const char *identifier, const char *message, struct ucred *ucred) {
struct iovec iovec[5];
char header_priority[6], header_pid[16];
int n = 0;
- char *tag_buf = NULL;
+ char *ident_buf = NULL;
int fd;
assert(s);
@@ -816,22 +816,22 @@ static void forward_kmsg(Server *s, int priority, const char *tag, const char *m
char_array_0(header_priority);
IOVEC_SET_STRING(iovec[n++], header_priority);
- /* Second: tag and PID */
+ /* Second: identifier and PID */
if (ucred) {
- if (!tag) {
- get_process_comm(ucred->pid, &tag_buf);
- tag = tag_buf;
+ 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 (tag)
- IOVEC_SET_STRING(iovec[n++], tag);
+ if (identifier)
+ IOVEC_SET_STRING(iovec[n++], identifier);
IOVEC_SET_STRING(iovec[n++], header_pid);
- } else if (tag) {
- IOVEC_SET_STRING(iovec[n++], tag);
+ } else if (identifier) {
+ IOVEC_SET_STRING(iovec[n++], identifier);
IOVEC_SET_STRING(iovec[n++], ": ");
}
@@ -851,34 +851,34 @@ static void forward_kmsg(Server *s, int priority, const char *tag, const char *m
close_nointr_nofail(fd);
finish:
- free(tag_buf);
+ free(ident_buf);
}
-static void forward_console(Server *s, const char *tag, const char *message, struct ucred *ucred) {
+static void forward_console(Server *s, const char *identifier, const char *message, struct ucred *ucred) {
struct iovec iovec[4];
char header_pid[16];
int n = 0, fd;
- char *tag_buf = NULL;
+ char *ident_buf = NULL;
assert(s);
assert(message);
- /* First: tag and PID */
+ /* First: identifier and PID */
if (ucred) {
- if (!tag) {
- get_process_comm(ucred->pid, &tag_buf);
- tag = tag_buf;
+ 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 (tag)
- IOVEC_SET_STRING(iovec[n++], tag);
+ if (identifier)
+ IOVEC_SET_STRING(iovec[n++], identifier);
IOVEC_SET_STRING(iovec[n++], header_pid);
- } else if (tag) {
- IOVEC_SET_STRING(iovec[n++], tag);
+ } else if (identifier) {
+ IOVEC_SET_STRING(iovec[n++], identifier);
IOVEC_SET_STRING(iovec[n++], ": ");
}
@@ -898,16 +898,16 @@ static void forward_console(Server *s, const char *tag, const char *message, str
close_nointr_nofail(fd);
finish:
- free(tag_buf);
+ free(ident_buf);
}
-static void read_tag(const char **buf, char **tag) {
+static void read_identifier(const char **buf, char **identifier) {
const char *p;
char *t;
size_t l, e;
assert(buf);
- assert(tag);
+ assert(identifier);
p = *buf;
@@ -940,18 +940,18 @@ static void read_tag(const char **buf, char **tag) {
t = strndup(p, l);
if (t)
- *tag = t;
+ *identifier = t;
*buf = p + e;
*buf += strspn(*buf, WHITESPACE);
}
static void process_syslog_message(Server *s, const char *buf, struct ucred *ucred, struct timeval *tv) {
- char *message = NULL, *syslog_priority = NULL, *syslog_facility = NULL, *syslog_tag = NULL;
+ char *message = NULL, *syslog_priority = NULL, *syslog_facility = NULL, *syslog_identifier = NULL;
struct iovec iovec[N_IOVEC_META_FIELDS + 5];
unsigned n = 0;
int priority = LOG_USER | LOG_INFO;
- char *tag = NULL;
+ char *identifier = NULL;
assert(s);
assert(buf);
@@ -961,13 +961,13 @@ static void process_syslog_message(Server *s, const char *buf, struct ucred *ucr
parse_syslog_priority((char**) &buf, &priority);
skip_syslog_date((char**) &buf);
- read_tag(&buf, &tag);
+ read_identifier(&buf, &identifier);
if (s->forward_to_kmsg)
- forward_kmsg(s, priority, tag, buf, ucred);
+ forward_kmsg(s, priority, identifier, buf, ucred);
if (s->forward_to_console)
- forward_console(s, tag, buf, ucred);
+ forward_console(s, identifier, buf, ucred);
IOVEC_SET_STRING(iovec[n++], "_TRANSPORT=syslog");
@@ -978,10 +978,10 @@ static void process_syslog_message(Server *s, const char *buf, struct ucred *ucr
if (asprintf(&syslog_facility, "SYSLOG_FACILITY=%i", LOG_FAC(priority)) >= 0)
IOVEC_SET_STRING(iovec[n++], syslog_facility);
- if (tag) {
- syslog_tag = strappend("SYSLOG_TAG=", tag);
- if (syslog_tag)
- IOVEC_SET_STRING(iovec[n++], syslog_tag);
+ if (identifier) {
+ syslog_identifier = strappend("SYSLOG_IDENTIFIER=", identifier);
+ if (syslog_identifier)
+ IOVEC_SET_STRING(iovec[n++], syslog_identifier);
}
message = strappend("MESSAGE=", buf);
@@ -991,10 +991,10 @@ static void process_syslog_message(Server *s, const char *buf, struct ucred *ucr
dispatch_message(s, iovec, n, ELEMENTSOF(iovec), ucred, tv, priority);
free(message);
- free(tag);
+ free(identifier);
free(syslog_priority);
free(syslog_facility);
- free(syslog_tag);
+ free(syslog_identifier);
}
static bool valid_user_field(const char *p, size_t l) {
@@ -1038,7 +1038,7 @@ static void process_native_message(Server *s, const void *buffer, size_t buffer_
const char *p;
size_t remaining;
int priority = LOG_INFO;
- char *tag = NULL, *message = NULL;
+ char *identifier = NULL, *message = NULL;
assert(s);
assert(buffer || n == 0);
@@ -1128,13 +1128,13 @@ static void process_native_message(Server *s, const void *buffer, size_t buffer_
priority = (priority & LOG_PRIMASK) | (((p[16] - '0')*10 + (p[17] - '0')) << 3);
else if (l >= 12 &&
- memcmp(p, "SYSLOG_TAG=", 11) == 0) {
+ memcmp(p, "SYSLOG_IDENTIFIER=", 11) == 0) {
char *t;
t = strndup(p + 11, l - 11);
if (t) {
- free(tag);
- tag = t;
+ free(identifier);
+ identifier = t;
}
} else if (l >= 8 &&
memcmp(p, "MESSAGE=", 8) == 0) {
@@ -1199,13 +1199,13 @@ static void process_native_message(Server *s, const void *buffer, size_t buffer_
if (message) {
if (s->forward_to_syslog)
- forward_syslog(s, priority, tag, message, ucred, tv);
+ forward_syslog(s, priority, identifier, message, ucred, tv);
if (s->forward_to_kmsg)
- forward_kmsg(s, priority, tag, message, ucred);
+ forward_kmsg(s, priority, identifier, message, ucred);
if (s->forward_to_console)
- forward_console(s, tag, message, ucred);
+ forward_console(s, identifier, message, ucred);
}
dispatch_message(s, iovec, n, m, ucred, tv, priority);
@@ -1220,13 +1220,13 @@ finish:
free(iovec[j].iov_base);
}
- free(tag);
+ free(identifier);
free(message);
}
static int stdout_stream_log(StdoutStream *s, const char *p) {
struct iovec iovec[N_IOVEC_META_FIELDS + 5];
- char *message = NULL, *syslog_priority = NULL, *syslog_facility = NULL, *syslog_tag = NULL;
+ char *message = NULL, *syslog_priority = NULL, *syslog_facility = NULL, *syslog_identifier = NULL;
unsigned n = 0;
int priority;
@@ -1239,13 +1239,13 @@ static int stdout_stream_log(StdoutStream *s, const char *p) {
parse_syslog_priority((char**) &p, &priority);
if (s->forward_to_syslog || s->server->forward_to_syslog)
- forward_syslog(s->server, fixup_priority(priority), s->tag, p, &s->ucred, NULL);
+ forward_syslog(s->server, fixup_priority(priority), s->identifier, p, &s->ucred, NULL);
if (s->forward_to_kmsg || s->server->forward_to_kmsg)
- forward_kmsg(s->server, priority, s->tag, p, &s->ucred);
+ forward_kmsg(s->server, priority, s->identifier, p, &s->ucred);
if (s->forward_to_console || s->server->forward_to_console)
- forward_console(s->server, s->tag, p, &s->ucred);
+ forward_console(s->server, s->identifier, p, &s->ucred);
IOVEC_SET_STRING(iovec[n++], "_TRANSPORT=stdout");
@@ -1256,10 +1256,10 @@ static int stdout_stream_log(StdoutStream *s, const char *p) {
if (asprintf(&syslog_facility, "SYSLOG_FACILITY=%i", LOG_FAC(priority)) >= 0)
IOVEC_SET_STRING(iovec[n++], syslog_facility);
- if (s->tag) {
- syslog_tag = strappend("SYSLOG_TAG=", s->tag);
- if (syslog_tag)
- IOVEC_SET_STRING(iovec[n++], syslog_tag);
+ if (s->identifier) {
+ syslog_identifier = strappend("SYSLOG_IDENTIFIER=", s->identifier);
+ if (syslog_identifier)
+ IOVEC_SET_STRING(iovec[n++], syslog_identifier);
}
message = strappend("MESSAGE=", p);
@@ -1271,7 +1271,7 @@ static int stdout_stream_log(StdoutStream *s, const char *p) {
free(message);
free(syslog_priority);
free(syslog_facility);
- free(syslog_tag);
+ free(syslog_identifier);
return 0;
}
@@ -1286,9 +1286,9 @@ static int stdout_stream_line(StdoutStream *s, char *p) {
switch (s->state) {
- case STDOUT_STREAM_TAG:
- s->tag = strdup(p);
- if (!s->tag) {
+ case STDOUT_STREAM_IDENTIFIER:
+ s->identifier = strdup(p);
+ if (!s->identifier) {
log_error("Out of memory");
return -ENOMEM;
}
@@ -1456,7 +1456,7 @@ static void stdout_stream_free(StdoutStream *s) {
close_nointr_nofail(s->fd);
}
- free(s->tag);
+ free(s->identifier);
free(s);
}
diff --git a/src/logs-show.c b/src/logs-show.c
index 358aea1..d067ab8 100644
--- a/src/logs-show.c
+++ b/src/logs-show.c
@@ -92,8 +92,8 @@ static int output_short(sd_journal *j, unsigned line, bool show_all) {
const void *data;
size_t length;
size_t n = 0;
- char *hostname = NULL, *tag = NULL, *comm = NULL, *pid = NULL, *message = NULL;
- size_t hostname_len = 0, tag_len = 0, comm_len = 0, pid_len = 0, message_len = 0;
+ char *hostname = NULL, *identifier = NULL, *comm = NULL, *pid = NULL, *message = NULL;
+ size_t hostname_len = 0, identifier_len = 0, comm_len = 0, pid_len = 0, message_len = 0;
assert(j);
@@ -105,7 +105,7 @@ static int output_short(sd_journal *j, unsigned line, bool show_all) {
else if (r > 0)
continue;
- r = parse_field(data, length, "SYSLOG_TAG=", &tag, &tag_len);
+ r = parse_field(data, length, "SYSLOG_IDENTIFIER=", &identifier, &identifier_len);
if (r < 0)
goto finish;
else if (r > 0)
@@ -153,9 +153,9 @@ static int output_short(sd_journal *j, unsigned line, bool show_all) {
n += hostname_len + 1;
}
- if (tag && shall_print(show_all, tag, tag_len)) {
- printf(" %.*s", (int) tag_len, tag);
- n += tag_len + 1;
+ if (identifier && shall_print(show_all, identifier, identifier_len)) {
+ printf(" %.*s", (int) identifier_len, identifier);
+ n += identifier_len + 1;
} else if (comm && shall_print(show_all, comm, comm_len)) {
printf(" %.*s", (int) comm_len, comm);
n += comm_len + 1;
@@ -190,7 +190,7 @@ static int output_short(sd_journal *j, unsigned line, bool show_all) {
finish:
free(hostname);
- free(tag);
+ free(identifier);
free(comm);
free(pid);
free(message);
diff --git a/src/systemd/sd-journal.h b/src/systemd/sd-journal.h
index d1fb149..e7d1e01 100644
--- a/src/systemd/sd-journal.h
+++ b/src/systemd/sd-journal.h
@@ -31,7 +31,6 @@
/* TODO:
*
- * - add options for copy-to-console, copy-to-kmsg
* - OR of matches is borked...
* - extend hash tables table as we go
* - accelerate looking for "all hostnames" and suchlike.
@@ -55,7 +54,7 @@ int sd_journal_printv(int priority, const char *format, va_list ap);
int sd_journal_send(const char *format, ...) __attribute__((sentinel));
int sd_journal_sendv(const struct iovec *iov, int n);
-int sd_journal_stream_fd(const char *tag, int priority, int priority_prefix);
+int sd_journal_stream_fd(const char *identifier, int priority, int level_prefix);
/* Browse journal stream */
commit 258cdffc2f9f8cd3d243bd19f507bc73009d77d9
Author: Lennart Poettering <lennart at poettering.net>
Date: Thu Jan 5 21:39:59 2012 +0100
journal: rename priority_prefix to level_prefix, since that's how we call it in PID 1
diff --git a/src/journal/journald.c b/src/journal/journald.c
index 22ac7d9..419ce26 100644
--- a/src/journal/journald.c
+++ b/src/journal/journald.c
@@ -65,7 +65,7 @@
typedef enum StdoutStreamState {
STDOUT_STREAM_TAG,
STDOUT_STREAM_PRIORITY,
- STDOUT_STREAM_PRIORITY_PREFIX,
+ STDOUT_STREAM_LEVEL_PREFIX,
STDOUT_STREAM_FORWARD_TO_SYSLOG,
STDOUT_STREAM_FORWARD_TO_KMSG,
STDOUT_STREAM_FORWARD_TO_CONSOLE,
@@ -82,7 +82,7 @@ struct StdoutStream {
char *tag;
int priority;
- bool priority_prefix:1;
+ bool level_prefix:1;
bool forward_to_syslog:1;
bool forward_to_kmsg:1;
bool forward_to_console:1;
@@ -1235,7 +1235,7 @@ static int stdout_stream_log(StdoutStream *s, const char *p) {
priority = s->priority;
- if (s->priority_prefix)
+ if (s->level_prefix)
parse_syslog_priority((char**) &p, &priority);
if (s->forward_to_syslog || s->server->forward_to_syslog)
@@ -1303,17 +1303,17 @@ static int stdout_stream_line(StdoutStream *s, char *p) {
return -EINVAL;
}
- s->state = STDOUT_STREAM_PRIORITY_PREFIX;
+ s->state = STDOUT_STREAM_LEVEL_PREFIX;
return 0;
- case STDOUT_STREAM_PRIORITY_PREFIX:
+ case STDOUT_STREAM_LEVEL_PREFIX:
r = parse_boolean(p);
if (r < 0) {
- log_warning("Failed to parse priority prefix line.");
+ log_warning("Failed to parse level prefix line.");
return -EINVAL;
}
- s->priority_prefix = !!r;
+ s->level_prefix = !!r;
s->state = STDOUT_STREAM_FORWARD_TO_SYSLOG;
return 0;
commit 86b9b8e70d54e79db3ff4f67bbd5280ecfc82537
Author: Lennart Poettering <lennart at poettering.net>
Date: Thu Jan 5 21:39:31 2012 +0100
sd-journal: close reading side of sd_journal_stream_fd() file descriptors
diff --git a/src/journal/journal-send.c b/src/journal/journal-send.c
index 176aac2..c382264 100644
--- a/src/journal/journal-send.c
+++ b/src/journal/journal-send.c
@@ -233,6 +233,11 @@ _public_ int sd_journal_stream_fd(const char *tag, int priority, int priority_pr
return -errno;
}
+ if (shutdown(fd, SHUT_RD) < 0) {
+ close_nointr_nofail(fd);
+ return -errno;
+ }
+
if (!tag)
tag = "";
commit 54fe0cdbe313558a712a15dc3bc516a46c1f7b6e
Author: Lennart Poettering <lennart at poettering.net>
Date: Thu Jan 5 21:39:08 2012 +0100
execute: talk directly to the journald, instead to the stdout-syslog-bridge
diff --git a/src/execute.c b/src/execute.c
index abbbfdd..a357332 100644
--- a/src/execute.c
+++ b/src/execute.c
@@ -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;
diff --git a/src/execute.h b/src/execute.h
index 77a2257..4f05c9f 100644
--- a/src/execute.h
+++ b/src/execute.h
@@ -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,
diff --git a/src/special.h b/src/special.h
index 3fe34c9..65b236a 100644
--- a/src/special.h
+++ b/src/special.h
@@ -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 */
diff --git a/src/unit.c b/src/unit.c
index 3191071..b31b92f 100644
--- a/src/unit.c
+++ b/src/unit.c
@@ -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;
More information about the systemd-commits
mailing list