|
|
1ff636 |
From 91cb89c1b79ef3c475d91319edb0c052cb9f2724 Mon Sep 17 00:00:00 2001
|
|
|
1ff636 |
From: Lukas Nykryn <lnykryn@redhat.com>
|
|
|
1ff636 |
Date: Wed, 15 Apr 2015 13:52:02 +0200
|
|
|
1ff636 |
Subject: [PATCH] Revert "journald: allow restarting journald without losing
|
|
|
1ff636 |
stream connections"
|
|
|
1ff636 |
|
|
|
1ff636 |
This reverts commit 13790add4bf648fed816361794d8277a75253410.
|
|
|
1ff636 |
---
|
|
|
1ff636 |
src/journal/journald-server.c | 26 +--
|
|
|
23b3cf |
src/journal/journald-stream.c | 376 ++++--------------------------
|
|
|
1ff636 |
src/journal/journald-stream.h | 3 +-
|
|
|
1ff636 |
units/systemd-journald.service.in | 1 -
|
|
|
1ff636 |
4 files changed, 61 insertions(+), 345 deletions(-)
|
|
|
1ff636 |
|
|
|
1ff636 |
diff --git a/src/journal/journald-server.c b/src/journal/journald-server.c
|
|
|
c62b8e |
index 7ee8174ea2..04839c950c 100644
|
|
|
1ff636 |
--- a/src/journal/journald-server.c
|
|
|
1ff636 |
+++ b/src/journal/journald-server.c
|
|
|
1ff636 |
@@ -1455,7 +1455,6 @@ static int server_open_hostname(Server *s) {
|
|
|
1ff636 |
}
|
|
|
1ff636 |
|
|
|
1ff636 |
int server_init(Server *s) {
|
|
|
1ff636 |
- _cleanup_fdset_free_ FDSet *fds = NULL;
|
|
|
1ff636 |
int n, r, fd;
|
|
|
1ff636 |
|
|
|
1ff636 |
assert(s);
|
|
|
1ff636 |
@@ -1552,33 +1551,26 @@ int server_init(Server *s) {
|
|
|
1ff636 |
s->audit_fd = fd;
|
|
|
1ff636 |
|
|
|
1ff636 |
} else {
|
|
|
1ff636 |
+ log_warning("Unknown socket passed as file descriptor %d, ignoring.", fd);
|
|
|
1ff636 |
|
|
|
1ff636 |
- if (!fds) {
|
|
|
1ff636 |
- fds = fdset_new();
|
|
|
1ff636 |
- if (!fds)
|
|
|
1ff636 |
- return log_oom();
|
|
|
1ff636 |
- }
|
|
|
1ff636 |
+ /* Let's close the fd, better be safe than
|
|
|
1ff636 |
+ sorry. The fd might reference some resource
|
|
|
1ff636 |
+ that we really want to release if we don't
|
|
|
1ff636 |
+ make use of it. */
|
|
|
1ff636 |
|
|
|
1ff636 |
- r = fdset_put(fds, fd);
|
|
|
1ff636 |
- if (r < 0)
|
|
|
1ff636 |
- return log_oom();
|
|
|
1ff636 |
+ safe_close(fd);
|
|
|
1ff636 |
}
|
|
|
1ff636 |
}
|
|
|
1ff636 |
|
|
|
1ff636 |
- r = server_open_stdout_socket(s, fds);
|
|
|
1ff636 |
+ r = server_open_syslog_socket(s);
|
|
|
1ff636 |
if (r < 0)
|
|
|
1ff636 |
return r;
|
|
|
1ff636 |
|
|
|
1ff636 |
- if (fdset_size(fds) > 0) {
|
|
|
1ff636 |
- log_warning("%u unknown file descriptors passed, closing.", fdset_size(fds));
|
|
|
1ff636 |
- fds = fdset_free(fds);
|
|
|
1ff636 |
- }
|
|
|
1ff636 |
-
|
|
|
1ff636 |
- r = server_open_syslog_socket(s);
|
|
|
1ff636 |
+ r = server_open_native_socket(s);
|
|
|
1ff636 |
if (r < 0)
|
|
|
1ff636 |
return r;
|
|
|
1ff636 |
|
|
|
1ff636 |
- r = server_open_native_socket(s);
|
|
|
1ff636 |
+ r = server_open_stdout_socket(s);
|
|
|
1ff636 |
if (r < 0)
|
|
|
1ff636 |
return r;
|
|
|
1ff636 |
|
|
|
1ff636 |
diff --git a/src/journal/journald-stream.c b/src/journal/journald-stream.c
|
|
|
c62b8e |
index 942a857803..11b852d39d 100644
|
|
|
1ff636 |
--- a/src/journal/journald-stream.c
|
|
|
1ff636 |
+++ b/src/journal/journald-stream.c
|
|
|
1ff636 |
@@ -28,11 +28,8 @@
|
|
|
1ff636 |
#endif
|
|
|
1ff636 |
|
|
|
1ff636 |
#include "sd-event.h"
|
|
|
1ff636 |
-#include "sd-daemon.h"
|
|
|
1ff636 |
#include "socket-util.h"
|
|
|
1ff636 |
#include "selinux-util.h"
|
|
|
1ff636 |
-#include "mkdir.h"
|
|
|
1ff636 |
-#include "fileio.h"
|
|
|
1ff636 |
#include "journald-server.h"
|
|
|
1ff636 |
#include "journald-stream.h"
|
|
|
1ff636 |
#include "journald-syslog.h"
|
|
|
1ff636 |
@@ -72,153 +69,14 @@ struct StdoutStream {
|
|
|
1ff636 |
bool forward_to_kmsg:1;
|
|
|
1ff636 |
bool forward_to_console:1;
|
|
|
1ff636 |
|
|
|
1ff636 |
- bool fdstore:1;
|
|
|
1ff636 |
-
|
|
|
1ff636 |
char buffer[LINE_MAX+1];
|
|
|
1ff636 |
size_t length;
|
|
|
1ff636 |
|
|
|
1ff636 |
sd_event_source *event_source;
|
|
|
1ff636 |
|
|
|
1ff636 |
- char *state_file;
|
|
|
1ff636 |
-
|
|
|
1ff636 |
LIST_FIELDS(StdoutStream, stdout_stream);
|
|
|
1ff636 |
};
|
|
|
1ff636 |
|
|
|
1ff636 |
-void stdout_stream_free(StdoutStream *s) {
|
|
|
1ff636 |
- if (!s)
|
|
|
1ff636 |
- return;
|
|
|
1ff636 |
-
|
|
|
1ff636 |
- if (s->server) {
|
|
|
1ff636 |
- assert(s->server->n_stdout_streams > 0);
|
|
|
1ff636 |
- s->server->n_stdout_streams --;
|
|
|
1ff636 |
- LIST_REMOVE(stdout_stream, s->server->stdout_streams, s);
|
|
|
1ff636 |
- }
|
|
|
1ff636 |
-
|
|
|
1ff636 |
- if (s->event_source) {
|
|
|
1ff636 |
- sd_event_source_set_enabled(s->event_source, SD_EVENT_OFF);
|
|
|
1ff636 |
- s->event_source = sd_event_source_unref(s->event_source);
|
|
|
1ff636 |
- }
|
|
|
1ff636 |
-
|
|
|
1ff636 |
- safe_close(s->fd);
|
|
|
1ff636 |
-
|
|
|
1ff636 |
-#ifdef HAVE_SELINUX
|
|
|
1ff636 |
- if (s->security_context)
|
|
|
1ff636 |
- freecon(s->security_context);
|
|
|
1ff636 |
-#endif
|
|
|
1ff636 |
-
|
|
|
1ff636 |
- free(s->identifier);
|
|
|
1ff636 |
- free(s->unit_id);
|
|
|
1ff636 |
- free(s->state_file);
|
|
|
1ff636 |
-
|
|
|
1ff636 |
- free(s);
|
|
|
1ff636 |
-}
|
|
|
1ff636 |
-
|
|
|
1ff636 |
-DEFINE_TRIVIAL_CLEANUP_FUNC(StdoutStream*, stdout_stream_free);
|
|
|
1ff636 |
-
|
|
|
1ff636 |
-static void stdout_stream_destroy(StdoutStream *s) {
|
|
|
1ff636 |
- if (!s)
|
|
|
1ff636 |
- return;
|
|
|
1ff636 |
-
|
|
|
1ff636 |
- if (s->state_file)
|
|
|
1ff636 |
- unlink(s->state_file);
|
|
|
1ff636 |
-
|
|
|
1ff636 |
- stdout_stream_free(s);
|
|
|
1ff636 |
-}
|
|
|
1ff636 |
-
|
|
|
1ff636 |
-static int stdout_stream_save(StdoutStream *s) {
|
|
|
1ff636 |
- _cleanup_free_ char *temp_path = NULL;
|
|
|
1ff636 |
- _cleanup_fclose_ FILE *f = NULL;
|
|
|
1ff636 |
- int r;
|
|
|
1ff636 |
-
|
|
|
1ff636 |
- assert(s);
|
|
|
1ff636 |
-
|
|
|
1ff636 |
- if (s->state != STDOUT_STREAM_RUNNING)
|
|
|
1ff636 |
- return 0;
|
|
|
1ff636 |
-
|
|
|
1ff636 |
- if (!s->state_file) {
|
|
|
1ff636 |
- struct stat st;
|
|
|
1ff636 |
-
|
|
|
1ff636 |
- r = fstat(s->fd, &st);
|
|
|
1ff636 |
- if (r < 0)
|
|
|
1ff636 |
- return log_warning_errno(errno, "Failed to stat connected stream: %m");
|
|
|
1ff636 |
-
|
|
|
1ff636 |
- /* We use device and inode numbers as identifier for the stream */
|
|
|
1ff636 |
- if (asprintf(&s->state_file, "/run/systemd/journal/streams/%lu:%lu", (unsigned long) st.st_dev, (unsigned long) st.st_ino) < 0)
|
|
|
1ff636 |
- return log_oom();
|
|
|
1ff636 |
- }
|
|
|
1ff636 |
-
|
|
|
1ff636 |
- mkdir_p("/run/systemd/journal/streams", 0755);
|
|
|
1ff636 |
-
|
|
|
1ff636 |
- r = fopen_temporary(s->state_file, &f, &temp_path);
|
|
|
1ff636 |
- if (r < 0)
|
|
|
1ff636 |
- goto finish;
|
|
|
1ff636 |
-
|
|
|
1ff636 |
- fprintf(f,
|
|
|
1ff636 |
- "# This is private data. Do not parse\n"
|
|
|
1ff636 |
- "PRIORITY=%i\n"
|
|
|
1ff636 |
- "LEVEL_PREFIX=%i\n"
|
|
|
1ff636 |
- "FORWARD_TO_SYSLOG=%i\n"
|
|
|
1ff636 |
- "FORWARD_TO_KMSG=%i\n"
|
|
|
1ff636 |
- "FORWARD_TO_CONSOLE=%i\n",
|
|
|
1ff636 |
- s->priority,
|
|
|
1ff636 |
- s->level_prefix,
|
|
|
1ff636 |
- s->forward_to_syslog,
|
|
|
1ff636 |
- s->forward_to_kmsg,
|
|
|
1ff636 |
- s->forward_to_console);
|
|
|
1ff636 |
-
|
|
|
1ff636 |
- if (!isempty(s->identifier)) {
|
|
|
1ff636 |
- _cleanup_free_ char *escaped;
|
|
|
1ff636 |
-
|
|
|
1ff636 |
- escaped = cescape(s->identifier);
|
|
|
1ff636 |
- if (!escaped) {
|
|
|
1ff636 |
- r = -ENOMEM;
|
|
|
1ff636 |
- goto finish;
|
|
|
1ff636 |
- }
|
|
|
1ff636 |
-
|
|
|
1ff636 |
- fprintf(f, "IDENTIFIER=%s\n", escaped);
|
|
|
1ff636 |
- }
|
|
|
1ff636 |
-
|
|
|
1ff636 |
- if (!isempty(s->unit_id)) {
|
|
|
1ff636 |
- _cleanup_free_ char *escaped;
|
|
|
1ff636 |
-
|
|
|
1ff636 |
- escaped = cescape(s->unit_id);
|
|
|
1ff636 |
- if (!escaped) {
|
|
|
1ff636 |
- r = -ENOMEM;
|
|
|
1ff636 |
- goto finish;
|
|
|
1ff636 |
- }
|
|
|
1ff636 |
-
|
|
|
1ff636 |
- fprintf(f, "UNIT=%s\n", escaped);
|
|
|
1ff636 |
- }
|
|
|
1ff636 |
-
|
|
|
1ff636 |
- r = fflush_and_check(f);
|
|
|
1ff636 |
- if (r < 0)
|
|
|
1ff636 |
- goto finish;
|
|
|
1ff636 |
-
|
|
|
1ff636 |
- if (rename(temp_path, s->state_file) < 0) {
|
|
|
1ff636 |
- r = -errno;
|
|
|
1ff636 |
- goto finish;
|
|
|
1ff636 |
- }
|
|
|
1ff636 |
-
|
|
|
1ff636 |
- free(temp_path);
|
|
|
1ff636 |
- temp_path = NULL;
|
|
|
1ff636 |
-
|
|
|
1ff636 |
- /* Store the connection fd in PID 1, so that we get it passed
|
|
|
1ff636 |
- * in again on next start */
|
|
|
1ff636 |
- if (!s->fdstore) {
|
|
|
1ff636 |
- sd_pid_notify_with_fds(0, false, "FDSTORE=1", &s->fd, 1);
|
|
|
1ff636 |
- s->fdstore = true;
|
|
|
1ff636 |
- }
|
|
|
1ff636 |
-
|
|
|
1ff636 |
-finish:
|
|
|
1ff636 |
- if (temp_path)
|
|
|
1ff636 |
- unlink(temp_path);
|
|
|
1ff636 |
-
|
|
|
1ff636 |
- if (r < 0)
|
|
|
1ff636 |
- log_error_errno(r, "Failed to save stream data %s: %m", s->state_file);
|
|
|
1ff636 |
-
|
|
|
1ff636 |
- return r;
|
|
|
1ff636 |
-}
|
|
|
1ff636 |
-
|
|
|
1ff636 |
static int stdout_stream_log(StdoutStream *s, const char *p) {
|
|
|
1ff636 |
struct iovec iovec[N_IOVEC_META_FIELDS + 5];
|
|
|
1ff636 |
int priority;
|
|
|
1ff636 |
@@ -371,9 +229,6 @@ static int stdout_stream_line(StdoutStream *s, char *p) {
|
|
|
1ff636 |
|
|
|
1ff636 |
s->forward_to_console = !!r;
|
|
|
1ff636 |
s->state = STDOUT_STREAM_RUNNING;
|
|
|
1ff636 |
-
|
|
|
1ff636 |
- /* Try to save the stream, so that journald can be restarted and we can recover */
|
|
|
1ff636 |
- (void) stdout_stream_save(s);
|
|
|
1ff636 |
return 0;
|
|
|
1ff636 |
|
|
|
1ff636 |
case STDOUT_STREAM_RUNNING:
|
|
|
1ff636 |
@@ -468,63 +323,40 @@ static int stdout_stream_process(sd_event_source *es, int fd, uint32_t revents,
|
|
|
1ff636 |
return 1;
|
|
|
1ff636 |
|
|
|
1ff636 |
terminate:
|
|
|
1ff636 |
- stdout_stream_destroy(s);
|
|
|
1ff636 |
+ stdout_stream_free(s);
|
|
|
1ff636 |
return 0;
|
|
|
1ff636 |
}
|
|
|
1ff636 |
|
|
|
1ff636 |
-static int stdout_stream_install(Server *s, int fd, StdoutStream **ret) {
|
|
|
1ff636 |
- _cleanup_(stdout_stream_freep) StdoutStream *stream = NULL;
|
|
|
1ff636 |
- int r;
|
|
|
1ff636 |
-
|
|
|
1ff636 |
+void stdout_stream_free(StdoutStream *s) {
|
|
|
1ff636 |
assert(s);
|
|
|
1ff636 |
- assert(fd >= 0);
|
|
|
1ff636 |
|
|
|
1ff636 |
- stream = new0(StdoutStream, 1);
|
|
|
1ff636 |
- if (!stream)
|
|
|
1ff636 |
- return log_oom();
|
|
|
1ff636 |
+ if (s->server) {
|
|
|
1ff636 |
+ assert(s->server->n_stdout_streams > 0);
|
|
|
1ff636 |
+ s->server->n_stdout_streams --;
|
|
|
1ff636 |
+ LIST_REMOVE(stdout_stream, s->server->stdout_streams, s);
|
|
|
1ff636 |
+ }
|
|
|
1ff636 |
|
|
|
1ff636 |
- stream->fd = -1;
|
|
|
1ff636 |
- stream->priority = LOG_INFO;
|
|
|
1ff636 |
+ if (s->event_source) {
|
|
|
1ff636 |
+ sd_event_source_set_enabled(s->event_source, SD_EVENT_OFF);
|
|
|
1ff636 |
+ s->event_source = sd_event_source_unref(s->event_source);
|
|
|
1ff636 |
+ }
|
|
|
1ff636 |
|
|
|
1ff636 |
- r = getpeercred(fd, &stream->ucred);
|
|
|
1ff636 |
- if (r < 0)
|
|
|
1ff636 |
- return log_error_errno(r, "Failed to determine peer credentials: %m");
|
|
|
1ff636 |
+ safe_close(s->fd);
|
|
|
1ff636 |
|
|
|
1ff636 |
#ifdef HAVE_SELINUX
|
|
|
1ff636 |
- if (mac_selinux_use()) {
|
|
|
1ff636 |
- if (getpeercon(fd, &stream->security_context) < 0 && errno != ENOPROTOOPT)
|
|
|
1ff636 |
- log_error_errno(errno, "Failed to determine peer security context: %m");
|
|
|
1ff636 |
- }
|
|
|
1ff636 |
+ if (s->security_context)
|
|
|
1ff636 |
+ freecon(s->security_context);
|
|
|
1ff636 |
#endif
|
|
|
1ff636 |
|
|
|
1ff636 |
- (void) shutdown(fd, SHUT_WR);
|
|
|
1ff636 |
-
|
|
|
1ff636 |
- r = sd_event_add_io(s->event, &stream->event_source, fd, EPOLLIN, stdout_stream_process, stream);
|
|
|
1ff636 |
- if (r < 0)
|
|
|
1ff636 |
- return log_error_errno(r, "Failed to add stream to event loop: %m");
|
|
|
1ff636 |
-
|
|
|
1ff636 |
- r = sd_event_source_set_priority(stream->event_source, SD_EVENT_PRIORITY_NORMAL+5);
|
|
|
1ff636 |
- if (r < 0)
|
|
|
1ff636 |
- return log_error_errno(r, "Failed to adjust stdout event source priority: %m");
|
|
|
1ff636 |
-
|
|
|
1ff636 |
- stream->fd = fd;
|
|
|
1ff636 |
-
|
|
|
1ff636 |
- stream->server = s;
|
|
|
1ff636 |
- LIST_PREPEND(stdout_stream, s->stdout_streams, stream);
|
|
|
1ff636 |
- s->n_stdout_streams ++;
|
|
|
1ff636 |
-
|
|
|
1ff636 |
- if (ret)
|
|
|
1ff636 |
- *ret = stream;
|
|
|
1ff636 |
-
|
|
|
1ff636 |
- stream = NULL;
|
|
|
1ff636 |
-
|
|
|
1ff636 |
- return 0;
|
|
|
1ff636 |
+ free(s->identifier);
|
|
|
1ff636 |
+ free(s->unit_id);
|
|
|
1ff636 |
+ free(s);
|
|
|
1ff636 |
}
|
|
|
1ff636 |
|
|
|
1ff636 |
static int stdout_stream_new(sd_event_source *es, int listen_fd, uint32_t revents, void *userdata) {
|
|
|
1ff636 |
- _cleanup_close_ int fd = -1;
|
|
|
1ff636 |
Server *s = userdata;
|
|
|
1ff636 |
- int r;
|
|
|
1ff636 |
+ StdoutStream *stream;
|
|
|
1ff636 |
+ int fd, r;
|
|
|
1ff636 |
|
|
|
1ff636 |
assert(s);
|
|
|
1ff636 |
|
|
|
1ff636 |
@@ -544,163 +376,60 @@ static int stdout_stream_new(sd_event_source *es, int listen_fd, uint32_t revent
|
|
|
1ff636 |
|
|
|
1ff636 |
if (s->n_stdout_streams >= STDOUT_STREAMS_MAX) {
|
|
|
1ff636 |
log_warning("Too many stdout streams, refusing connection.");
|
|
|
1ff636 |
+ safe_close(fd);
|
|
|
1ff636 |
return 0;
|
|
|
1ff636 |
}
|
|
|
1ff636 |
|
|
|
1ff636 |
- r = stdout_stream_install(s, fd, NULL);
|
|
|
1ff636 |
- if (r < 0)
|
|
|
1ff636 |
- return r;
|
|
|
1ff636 |
-
|
|
|
1ff636 |
- fd = -1;
|
|
|
1ff636 |
- return 0;
|
|
|
1ff636 |
-}
|
|
|
1ff636 |
-
|
|
|
1ff636 |
-static int stdout_stream_load(StdoutStream *stream, const char *fname) {
|
|
|
1ff636 |
- _cleanup_free_ char
|
|
|
1ff636 |
- *priority = NULL,
|
|
|
1ff636 |
- *level_prefix = NULL,
|
|
|
1ff636 |
- *forward_to_syslog = NULL,
|
|
|
1ff636 |
- *forward_to_kmsg = NULL,
|
|
|
1ff636 |
- *forward_to_console = NULL;
|
|
|
1ff636 |
- int r;
|
|
|
1ff636 |
-
|
|
|
1ff636 |
- assert(stream);
|
|
|
1ff636 |
- assert(fname);
|
|
|
1ff636 |
-
|
|
|
1ff636 |
- if (!stream->state_file) {
|
|
|
1ff636 |
- stream->state_file = strappend("/run/systemd/journal/streams/", fname);
|
|
|
1ff636 |
- if (!stream->state_file)
|
|
|
1ff636 |
- return log_oom();
|
|
|
1ff636 |
- }
|
|
|
1ff636 |
-
|
|
|
1ff636 |
- r = parse_env_file(stream->state_file, NEWLINE,
|
|
|
1ff636 |
- "PRIORITY", &priority,
|
|
|
1ff636 |
- "LEVEL_PREFIX", &level_prefix,
|
|
|
1ff636 |
- "FORWARD_TO_SYSLOG", &forward_to_syslog,
|
|
|
1ff636 |
- "FORWARD_TO_KMSG", &forward_to_kmsg,
|
|
|
1ff636 |
- "FORWARD_TO_CONSOLE", &forward_to_console,
|
|
|
1ff636 |
- "IDENTIFIER", &stream->identifier,
|
|
|
1ff636 |
- "UNIT", &stream->unit_id,
|
|
|
1ff636 |
- NULL);
|
|
|
1ff636 |
- if (r < 0)
|
|
|
1ff636 |
- return log_error_errno(r, "Failed to read: %s", stream->state_file);
|
|
|
1ff636 |
-
|
|
|
1ff636 |
- if (priority) {
|
|
|
1ff636 |
- int p;
|
|
|
1ff636 |
-
|
|
|
1ff636 |
- p = log_level_from_string(priority);
|
|
|
1ff636 |
- if (p >= 0)
|
|
|
1ff636 |
- stream->priority = p;
|
|
|
1ff636 |
+ stream = new0(StdoutStream, 1);
|
|
|
1ff636 |
+ if (!stream) {
|
|
|
1ff636 |
+ safe_close(fd);
|
|
|
1ff636 |
+ return log_oom();
|
|
|
1ff636 |
}
|
|
|
1ff636 |
|
|
|
1ff636 |
- if (level_prefix) {
|
|
|
1ff636 |
- r = parse_boolean(level_prefix);
|
|
|
1ff636 |
- if (r >= 0)
|
|
|
1ff636 |
- stream->level_prefix = r;
|
|
|
1ff636 |
- }
|
|
|
1ff636 |
+ stream->fd = fd;
|
|
|
1ff636 |
|
|
|
1ff636 |
- if (forward_to_syslog) {
|
|
|
1ff636 |
- r = parse_boolean(forward_to_syslog);
|
|
|
1ff636 |
- if (r >= 0)
|
|
|
1ff636 |
- stream->forward_to_syslog = r;
|
|
|
1ff636 |
+ r = getpeercred(fd, &stream->ucred);
|
|
|
1ff636 |
+ if (r < 0) {
|
|
|
1ff636 |
+ log_error_errno(errno, "Failed to determine peer credentials: %m");
|
|
|
1ff636 |
+ goto fail;
|
|
|
1ff636 |
}
|
|
|
1ff636 |
|
|
|
1ff636 |
- if (forward_to_kmsg) {
|
|
|
1ff636 |
- r = parse_boolean(forward_to_kmsg);
|
|
|
1ff636 |
- if (r >= 0)
|
|
|
1ff636 |
- stream->forward_to_kmsg = r;
|
|
|
1ff636 |
+#ifdef HAVE_SELINUX
|
|
|
1ff636 |
+ if (mac_selinux_use()) {
|
|
|
1ff636 |
+ if (getpeercon(fd, &stream->security_context) < 0 && errno != ENOPROTOOPT)
|
|
|
1ff636 |
+ log_error_errno(errno, "Failed to determine peer security context: %m");
|
|
|
1ff636 |
}
|
|
|
1ff636 |
+#endif
|
|
|
1ff636 |
|
|
|
1ff636 |
- if (forward_to_console) {
|
|
|
1ff636 |
- r = parse_boolean(forward_to_console);
|
|
|
1ff636 |
- if (r >= 0)
|
|
|
1ff636 |
- stream->forward_to_console = r;
|
|
|
1ff636 |
+ if (shutdown(fd, SHUT_WR) < 0) {
|
|
|
1ff636 |
+ log_error_errno(errno, "Failed to shutdown writing side of socket: %m");
|
|
|
1ff636 |
+ goto fail;
|
|
|
1ff636 |
}
|
|
|
1ff636 |
|
|
|
1ff636 |
- return 0;
|
|
|
1ff636 |
-}
|
|
|
1ff636 |
-
|
|
|
1ff636 |
-static int stdout_stream_restore(Server *s, const char *fname, int fd) {
|
|
|
1ff636 |
- StdoutStream *stream;
|
|
|
1ff636 |
- int r;
|
|
|
1ff636 |
-
|
|
|
1ff636 |
- assert(s);
|
|
|
1ff636 |
- assert(fname);
|
|
|
1ff636 |
- assert(fd >= 0);
|
|
|
1ff636 |
-
|
|
|
1ff636 |
- if (s->n_stdout_streams >= STDOUT_STREAMS_MAX) {
|
|
|
1ff636 |
- log_warning("Too many stdout streams, refusing restoring of stream.");
|
|
|
1ff636 |
- return -ENOBUFS;
|
|
|
1ff636 |
+ r = sd_event_add_io(s->event, &stream->event_source, fd, EPOLLIN, stdout_stream_process, stream);
|
|
|
1ff636 |
+ if (r < 0) {
|
|
|
1ff636 |
+ log_error_errno(r, "Failed to add stream to event loop: %m");
|
|
|
1ff636 |
+ goto fail;
|
|
|
1ff636 |
}
|
|
|
1ff636 |
|
|
|
1ff636 |
- r = stdout_stream_install(s, fd, &stream);
|
|
|
1ff636 |
- if (r < 0)
|
|
|
1ff636 |
- return r;
|
|
|
1ff636 |
-
|
|
|
1ff636 |
- stream->state = STDOUT_STREAM_RUNNING;
|
|
|
1ff636 |
- stream->fdstore = true;
|
|
|
1ff636 |
-
|
|
|
1ff636 |
- /* Ignore all parsing errors */
|
|
|
1ff636 |
- (void) stdout_stream_load(stream, fname);
|
|
|
1ff636 |
-
|
|
|
1ff636 |
- return 0;
|
|
|
1ff636 |
-}
|
|
|
1ff636 |
-
|
|
|
1ff636 |
-static int server_restore_streams(Server *s, FDSet *fds) {
|
|
|
1ff636 |
- _cleanup_closedir_ DIR *d = NULL;
|
|
|
1ff636 |
- struct dirent *de;
|
|
|
1ff636 |
- int r;
|
|
|
1ff636 |
-
|
|
|
1ff636 |
- d = opendir("/run/systemd/journal/streams");
|
|
|
1ff636 |
- if (!d) {
|
|
|
1ff636 |
- if (errno == ENOENT)
|
|
|
1ff636 |
- return 0;
|
|
|
1ff636 |
-
|
|
|
1ff636 |
- return log_warning_errno(errno, "Failed to enumerate /run/systemd/journal/streams: %m");
|
|
|
1ff636 |
+ r = sd_event_source_set_priority(stream->event_source, SD_EVENT_PRIORITY_NORMAL+5);
|
|
|
1ff636 |
+ if (r < 0) {
|
|
|
1ff636 |
+ log_error_errno(r, "Failed to adjust stdout event source priority: %m");
|
|
|
1ff636 |
+ goto fail;
|
|
|
1ff636 |
}
|
|
|
1ff636 |
|
|
|
1ff636 |
- FOREACH_DIRENT(de, d, goto fail) {
|
|
|
1ff636 |
- unsigned long st_dev, st_ino;
|
|
|
1ff636 |
- bool found = false;
|
|
|
1ff636 |
- Iterator i;
|
|
|
1ff636 |
- int fd;
|
|
|
1ff636 |
-
|
|
|
1ff636 |
- if (sscanf(de->d_name, "%lu:%lu", &st_dev, &st_ino) != 2)
|
|
|
1ff636 |
- continue;
|
|
|
1ff636 |
-
|
|
|
1ff636 |
- FDSET_FOREACH(fd, fds, i) {
|
|
|
1ff636 |
- struct stat st;
|
|
|
1ff636 |
-
|
|
|
1ff636 |
- if (fstat(fd, &st) < 0)
|
|
|
1ff636 |
- return log_error_errno(errno, "Failed to stat %s: %m", de->d_name);
|
|
|
1ff636 |
-
|
|
|
1ff636 |
- if (S_ISSOCK(st.st_mode) && st.st_dev == st_dev && st.st_ino == st_ino) {
|
|
|
1ff636 |
- found = true;
|
|
|
1ff636 |
- break;
|
|
|
1ff636 |
- }
|
|
|
1ff636 |
- }
|
|
|
1ff636 |
-
|
|
|
1ff636 |
- if (!found) {
|
|
|
1ff636 |
- /* No file descriptor? Then let's delete the state file */
|
|
|
1ff636 |
- log_debug("Cannot restore stream file %s", de->d_name);
|
|
|
1ff636 |
- unlinkat(dirfd(d), de->d_name, 0);
|
|
|
1ff636 |
- continue;
|
|
|
1ff636 |
- }
|
|
|
1ff636 |
-
|
|
|
1ff636 |
- fdset_remove(fds, fd);
|
|
|
1ff636 |
-
|
|
|
1ff636 |
- r = stdout_stream_restore(s, de->d_name, fd);
|
|
|
1ff636 |
- if (r < 0)
|
|
|
1ff636 |
- safe_close(fd);
|
|
|
1ff636 |
- }
|
|
|
1ff636 |
+ stream->server = s;
|
|
|
1ff636 |
+ LIST_PREPEND(stdout_stream, s->stdout_streams, stream);
|
|
|
1ff636 |
+ s->n_stdout_streams ++;
|
|
|
1ff636 |
|
|
|
1ff636 |
return 0;
|
|
|
1ff636 |
|
|
|
1ff636 |
fail:
|
|
|
1ff636 |
- return log_error_errno(errno, "Failed to read streams directory: %m");
|
|
|
1ff636 |
+ stdout_stream_free(stream);
|
|
|
1ff636 |
+ return 0;
|
|
|
1ff636 |
}
|
|
|
1ff636 |
|
|
|
1ff636 |
-int server_open_stdout_socket(Server *s, FDSet *fds) {
|
|
|
1ff636 |
+int server_open_stdout_socket(Server *s) {
|
|
|
1ff636 |
int r;
|
|
|
1ff636 |
|
|
|
1ff636 |
assert(s);
|
|
|
1ff636 |
@@ -736,8 +465,5 @@ int server_open_stdout_socket(Server *s, FDSet *fds) {
|
|
|
1ff636 |
if (r < 0)
|
|
|
1ff636 |
return log_error_errno(r, "Failed to adjust priority of stdout server event source: %m");
|
|
|
1ff636 |
|
|
|
1ff636 |
- /* Try to restore streams, but don't bother if this fails */
|
|
|
1ff636 |
- (void) server_restore_streams(s, fds);
|
|
|
1ff636 |
-
|
|
|
1ff636 |
return 0;
|
|
|
1ff636 |
}
|
|
|
1ff636 |
diff --git a/src/journal/journald-stream.h b/src/journal/journald-stream.h
|
|
|
c62b8e |
index 94bf955d78..8cad012967 100644
|
|
|
1ff636 |
--- a/src/journal/journald-stream.h
|
|
|
1ff636 |
+++ b/src/journal/journald-stream.h
|
|
|
1ff636 |
@@ -21,9 +21,8 @@
|
|
|
1ff636 |
along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
|
|
1ff636 |
***/
|
|
|
1ff636 |
|
|
|
1ff636 |
-#include "fdset.h"
|
|
|
1ff636 |
#include "journald-server.h"
|
|
|
1ff636 |
|
|
|
1ff636 |
-int server_open_stdout_socket(Server *s, FDSet *fds);
|
|
|
1ff636 |
+int server_open_stdout_socket(Server *s);
|
|
|
1ff636 |
|
|
|
1ff636 |
void stdout_stream_free(StdoutStream *s);
|
|
|
1ff636 |
diff --git a/units/systemd-journald.service.in b/units/systemd-journald.service.in
|
|
|
c62b8e |
index a3540c65d2..87704bb9c1 100644
|
|
|
1ff636 |
--- a/units/systemd-journald.service.in
|
|
|
1ff636 |
+++ b/units/systemd-journald.service.in
|
|
|
1ff636 |
@@ -23,7 +23,6 @@ NotifyAccess=all
|
|
|
1ff636 |
StandardOutput=null
|
|
|
1ff636 |
CapabilityBoundingSet=CAP_SYS_ADMIN CAP_DAC_OVERRIDE CAP_SYS_PTRACE CAP_SYSLOG CAP_AUDIT_CONTROL CAP_AUDIT_READ CAP_CHOWN CAP_DAC_READ_SEARCH CAP_FOWNER CAP_SETUID CAP_SETGID CAP_MAC_OVERRIDE
|
|
|
1ff636 |
WatchdogSec=1min
|
|
|
1ff636 |
-FileDescriptorStoreMax=1024
|
|
|
1ff636 |
|
|
|
1ff636 |
# Increase the default a bit in order to allow many simultaneous
|
|
|
1ff636 |
# services being run since we keep one fd open per service. Also, when
|