summaryrefslogtreecommitdiff
path: root/src/journal
diff options
context:
space:
mode:
Diffstat (limited to 'src/journal')
-rw-r--r--src/journal/cat.c2
-rw-r--r--src/journal/catalog.c3
-rw-r--r--src/journal/compress.c2
-rw-r--r--src/journal/coredump-vacuum.c2
-rw-r--r--src/journal/coredump.c8
-rw-r--r--src/journal/coredumpctl.c5
-rw-r--r--src/journal/fsprg.h1
-rw-r--r--src/journal/journal-authenticate.c1
-rw-r--r--src/journal/journal-file.c4
-rw-r--r--src/journal/journal-send.c3
-rw-r--r--src/journal/journal-vacuum.c4
-rw-r--r--src/journal/journal-verify.c2
-rw-r--r--src/journal/journalctl.c8
-rw-r--r--src/journal/journald-audit.c3
-rw-r--r--src/journal/journald-console.c10
-rw-r--r--src/journal/journald-kmsg.c3
-rw-r--r--src/journal/journald-native.c4
-rw-r--r--src/journal/journald-rate-limit.c1
-rw-r--r--src/journal/journald-server.c138
-rw-r--r--src/journal/journald-server.h17
-rw-r--r--src/journal/journald-stream.c74
-rw-r--r--src/journal/journald-stream.h4
-rw-r--r--src/journal/journald-syslog.c4
-rw-r--r--src/journal/journald-wall.c1
-rw-r--r--src/journal/journald.c8
-rw-r--r--src/journal/mmap-cache.c1
-rw-r--r--src/journal/sd-journal.c26
-rw-r--r--src/journal/stacktrace.c1
-rw-r--r--src/journal/test-catalog.c2
-rw-r--r--src/journal/test-compress-benchmark.c2
-rw-r--r--src/journal/test-compress.c2
-rw-r--r--src/journal/test-journal-flush.c1
-rw-r--r--src/journal/test-journal-init.c1
-rw-r--r--src/journal/test-journal-interleaving.c5
-rw-r--r--src/journal/test-journal-match.c1
-rw-r--r--src/journal/test-journal-stream.c11
-rw-r--r--src/journal/test-journal-syslog.c1
-rw-r--r--src/journal/test-mmap-cache.c3
38 files changed, 325 insertions, 44 deletions
diff --git a/src/journal/cat.c b/src/journal/cat.c
index ff1887604a..7fd4198df8 100644
--- a/src/journal/cat.c
+++ b/src/journal/cat.c
@@ -29,7 +29,9 @@
#include "sd-journal.h"
#include "fd-util.h"
+#include "parse-util.h"
#include "string-util.h"
+#include "syslog-util.h"
#include "util.h"
static char *arg_identifier = NULL;
diff --git a/src/journal/catalog.c b/src/journal/catalog.c
index d5bc17b4b6..95a6857472 100644
--- a/src/journal/catalog.c
+++ b/src/journal/catalog.c
@@ -29,12 +29,15 @@
#include "sd-id128.h"
+#include "alloc-util.h"
#include "catalog.h"
#include "conf-files.h"
#include "fd-util.h"
+#include "fileio.h"
#include "hashmap.h"
#include "log.h"
#include "mkdir.h"
+#include "path-util.h"
#include "siphash24.h"
#include "sparse-endian.h"
#include "strbuf.h"
diff --git a/src/journal/compress.c b/src/journal/compress.c
index 9308e8b789..e1ca0a8818 100644
--- a/src/journal/compress.c
+++ b/src/journal/compress.c
@@ -33,12 +33,14 @@
#include <lz4frame.h>
#endif
+#include "alloc-util.h"
#include "compress.h"
#include "fd-util.h"
#include "io-util.h"
#include "journal-def.h"
#include "macro.h"
#include "sparse-endian.h"
+#include "string-table.h"
#include "string-util.h"
#include "util.h"
diff --git a/src/journal/coredump-vacuum.c b/src/journal/coredump-vacuum.c
index bad6ea4242..39bc2e4270 100644
--- a/src/journal/coredump-vacuum.c
+++ b/src/journal/coredump-vacuum.c
@@ -21,7 +21,9 @@
#include <sys/statvfs.h>
+#include "alloc-util.h"
#include "coredump-vacuum.h"
+#include "dirent-util.h"
#include "fd-util.h"
#include "hashmap.h"
#include "macro.h"
diff --git a/src/journal/coredump.c b/src/journal/coredump.c
index 7336db219b..2e543537f6 100644
--- a/src/journal/coredump.c
+++ b/src/journal/coredump.c
@@ -34,22 +34,28 @@
#include "sd-login.h"
#include "acl-util.h"
-#include "capability.h"
+#include "alloc-util.h"
+#include "capability-util.h"
#include "cgroup-util.h"
#include "compress.h"
#include "conf-parser.h"
#include "copy.h"
#include "coredump-vacuum.h"
+#include "dirent-util.h"
#include "escape.h"
#include "fd-util.h"
#include "fileio.h"
+#include "fs-util.h"
+#include "io-util.h"
#include "journald-native.h"
#include "log.h"
#include "macro.h"
#include "mkdir.h"
+#include "parse-util.h"
#include "process-util.h"
#include "special.h"
#include "stacktrace.h"
+#include "string-table.h"
#include "string-util.h"
#include "strv.h"
#include "user-util.h"
diff --git a/src/journal/coredumpctl.c b/src/journal/coredumpctl.c
index f891ddffc6..af4d051138 100644
--- a/src/journal/coredumpctl.c
+++ b/src/journal/coredumpctl.c
@@ -28,12 +28,15 @@
#include "sd-journal.h"
+#include "alloc-util.h"
#include "compress.h"
#include "fd-util.h"
+#include "fileio.h"
#include "journal-internal.h"
#include "log.h"
#include "macro.h"
#include "pager.h"
+#include "parse-util.h"
#include "path-util.h"
#include "process-util.h"
#include "set.h"
@@ -41,8 +44,8 @@
#include "signal-util.h"
#include "string-util.h"
#include "terminal-util.h"
-#include "util.h"
#include "user-util.h"
+#include "util.h"
static enum {
ACTION_NONE,
diff --git a/src/journal/fsprg.h b/src/journal/fsprg.h
index 150d034828..5959b1fed2 100644
--- a/src/journal/fsprg.h
+++ b/src/journal/fsprg.h
@@ -29,6 +29,7 @@
#include <inttypes.h>
#include "macro.h"
+#include "util.h"
#ifdef __cplusplus
extern "C" {
diff --git a/src/journal/journal-authenticate.c b/src/journal/journal-authenticate.c
index dc51a5ab2f..0c4ac5cdc3 100644
--- a/src/journal/journal-authenticate.c
+++ b/src/journal/journal-authenticate.c
@@ -27,6 +27,7 @@
#include "journal-authenticate.h"
#include "journal-def.h"
#include "journal-file.h"
+#include "hexdecoct.h"
static uint64_t journal_file_tag_seqnum(JournalFile *f) {
uint64_t r;
diff --git a/src/journal/journal-file.c b/src/journal/journal-file.c
index f193cb90ce..12b39dbb27 100644
--- a/src/journal/journal-file.c
+++ b/src/journal/journal-file.c
@@ -28,15 +28,19 @@
#include <sys/uio.h>
#include <unistd.h>
+#include "alloc-util.h"
#include "btrfs-util.h"
+#include "chattr-util.h"
#include "compress.h"
#include "fd-util.h"
#include "journal-authenticate.h"
#include "journal-def.h"
#include "journal-file.h"
#include "lookup3.h"
+#include "parse-util.h"
#include "random-util.h"
#include "string-util.h"
+#include "xattr-util.h"
#define DEFAULT_DATA_HASH_TABLE_SIZE (2047ULL*sizeof(HashItem))
#define DEFAULT_FIELD_HASH_TABLE_SIZE (333ULL*sizeof(HashItem))
diff --git a/src/journal/journal-send.c b/src/journal/journal-send.c
index f388c30d2e..fa5dee73c3 100644
--- a/src/journal/journal-send.c
+++ b/src/journal/journal-send.c
@@ -31,10 +31,13 @@
#include "sd-journal.h"
+#include "alloc-util.h"
#include "fd-util.h"
+#include "fileio.h"
#include "io-util.h"
#include "memfd-util.h"
#include "socket-util.h"
+#include "stdio-util.h"
#include "string-util.h"
#include "util.h"
diff --git a/src/journal/journal-vacuum.c b/src/journal/journal-vacuum.c
index dca5bf5000..4b5fc76eb1 100644
--- a/src/journal/journal-vacuum.c
+++ b/src/journal/journal-vacuum.c
@@ -25,12 +25,16 @@
#include "sd-id128.h"
+#include "alloc-util.h"
+#include "dirent-util.h"
#include "fd-util.h"
#include "journal-def.h"
#include "journal-file.h"
#include "journal-vacuum.h"
+#include "parse-util.h"
#include "string-util.h"
#include "util.h"
+#include "xattr-util.h"
struct vacuum_info {
uint64_t usage;
diff --git a/src/journal/journal-verify.c b/src/journal/journal-verify.c
index de4f73a471..b78ce98b17 100644
--- a/src/journal/journal-verify.c
+++ b/src/journal/journal-verify.c
@@ -24,8 +24,10 @@
#include <fcntl.h>
#include <stddef.h>
+#include "alloc-util.h"
#include "compress.h"
#include "fd-util.h"
+#include "fileio.h"
#include "journal-authenticate.h"
#include "journal-def.h"
#include "journal-file.h"
diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c
index 6e452a4d51..a35783e3ff 100644
--- a/src/journal/journalctl.c
+++ b/src/journal/journalctl.c
@@ -39,12 +39,16 @@
#include "sd-journal.h"
#include "acl-util.h"
+#include "alloc-util.h"
#include "bus-error.h"
#include "bus-util.h"
#include "catalog.h"
+#include "chattr-util.h"
#include "fd-util.h"
#include "fileio.h"
+#include "fs-util.h"
#include "fsprg.h"
+#include "glob-util.h"
#include "hostname-util.h"
#include "io-util.h"
#include "journal-def.h"
@@ -52,14 +56,18 @@
#include "journal-qrcode.h"
#include "journal-vacuum.h"
#include "journal-verify.h"
+#include "locale-util.h"
#include "log.h"
#include "logs-show.h"
#include "mkdir.h"
#include "pager.h"
+#include "parse-util.h"
#include "path-util.h"
+#include "rlimit-util.h"
#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"
diff --git a/src/journal/journald-audit.c b/src/journal/journald-audit.c
index 4c102fd530..3c13fe0d67 100644
--- a/src/journal/journald-audit.c
+++ b/src/journal/journald-audit.c
@@ -19,8 +19,11 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
+#include "alloc-util.h"
#include "audit-type.h"
#include "fd-util.h"
+#include "hexdecoct.h"
+#include "io-util.h"
#include "journald-audit.h"
#include "missing.h"
#include "string-util.h"
diff --git a/src/journal/journald-console.c b/src/journal/journald-console.c
index 5f3eb05275..860832cfc8 100644
--- a/src/journal/journald-console.c
+++ b/src/journal/journald-console.c
@@ -23,13 +23,17 @@
#include <fcntl.h>
#include <sys/socket.h>
+#include "alloc-util.h"
+#include "fd-util.h"
#include "fileio.h"
-#include "journald-server.h"
-#include "journald-console.h"
#include "formats-util.h"
+#include "io-util.h"
+#include "journald-console.h"
+#include "journald-server.h"
+#include "parse-util.h"
#include "process-util.h"
+#include "stdio-util.h"
#include "terminal-util.h"
-#include "fd-util.h"
static bool prefix_timestamp(void) {
diff --git a/src/journal/journald-kmsg.c b/src/journal/journald-kmsg.c
index 5a05632e56..489f6f689c 100644
--- a/src/journal/journald-kmsg.c
+++ b/src/journal/journald-kmsg.c
@@ -31,10 +31,13 @@
#include "escape.h"
#include "fd-util.h"
#include "formats-util.h"
+#include "io-util.h"
#include "journald-kmsg.h"
#include "journald-server.h"
#include "journald-syslog.h"
+#include "parse-util.h"
#include "process-util.h"
+#include "stdio-util.h"
#include "string-util.h"
void server_forward_kmsg(
diff --git a/src/journal/journald-native.c b/src/journal/journald-native.c
index 7d4aac687e..6fff4fe473 100644
--- a/src/journal/journald-native.c
+++ b/src/journal/journald-native.c
@@ -24,7 +24,10 @@
#include <sys/mman.h>
#include <unistd.h>
+#include "alloc-util.h"
#include "fd-util.h"
+#include "fs-util.h"
+#include "io-util.h"
#include "journald-console.h"
#include "journald-kmsg.h"
#include "journald-native.h"
@@ -32,6 +35,7 @@
#include "journald-syslog.h"
#include "journald-wall.h"
#include "memfd-util.h"
+#include "parse-util.h"
#include "path-util.h"
#include "selinux-util.h"
#include "socket-util.h"
diff --git a/src/journal/journald-rate-limit.c b/src/journal/journald-rate-limit.c
index 6e9557c06e..434ddc8ac9 100644
--- a/src/journal/journald-rate-limit.c
+++ b/src/journal/journald-rate-limit.c
@@ -22,6 +22,7 @@
#include <errno.h>
#include <string.h>
+#include "alloc-util.h"
#include "hashmap.h"
#include "list.h"
#include "random-util.h"
diff --git a/src/journal/journald-server.c b/src/journal/journald-server.c
index 7cefea323e..299b0a848f 100644
--- a/src/journal/journald-server.c
+++ b/src/journal/journald-server.c
@@ -34,13 +34,18 @@
#include "sd-messages.h"
#include "acl-util.h"
+#include "alloc-util.h"
+#include "audit-util.h"
#include "cgroup-util.h"
#include "conf-parser.h"
+#include "dirent-util.h"
#include "extract-word.h"
#include "fd-util.h"
#include "formats-util.h"
+#include "fs-util.h"
#include "hashmap.h"
#include "hostname-util.h"
+#include "io-util.h"
#include "journal-authenticate.h"
#include "journal-file.h"
#include "journal-internal.h"
@@ -54,11 +59,14 @@
#include "journald-syslog.h"
#include "missing.h"
#include "mkdir.h"
+#include "parse-util.h"
+#include "proc-cmdline.h"
#include "process-util.h"
#include "rm-rf.h"
#include "selinux-util.h"
#include "signal-util.h"
#include "socket-util.h"
+#include "string-table.h"
#include "string-util.h"
#define USER_JOURNALS_MAX 1024
@@ -70,6 +78,8 @@
#define RECHECK_SPACE_USEC (30*USEC_PER_SEC)
+#define NOTIFY_SNDBUF_SIZE (8*1024*1024)
+
static int determine_space_for(
Server *s,
JournalMetrics *metrics,
@@ -1449,6 +1459,126 @@ static int server_open_hostname(Server *s) {
return 0;
}
+static int dispatch_notify_event(sd_event_source *es, int fd, uint32_t revents, void *userdata) {
+ Server *s = userdata;
+ int r;
+
+ assert(s);
+ assert(s->notify_event_source == es);
+ assert(s->notify_fd == fd);
+
+ if (revents != EPOLLOUT) {
+ log_error("Invalid events on notify file descriptor.");
+ return -EINVAL;
+ }
+
+ /* The $NOTIFY_SOCKET is writable again, now send exactly one
+ * message on it. Either it's the initial READY=1 event or an
+ * stdout stream event. If there's nothing to write anymore,
+ * turn our event source off. The next time there's something
+ * to send it will be turned on again. */
+
+ if (!s->sent_notify_ready) {
+ static const char p[] =
+ "READY=1\n"
+ "STATUS=Processing requests...";
+ ssize_t l;
+
+ l = send(s->notify_fd, p, strlen(p), MSG_DONTWAIT);
+ if (l < 0) {
+ if (errno == EAGAIN)
+ return 0;
+
+ return log_error_errno(errno, "Failed to send READY=1 notification message: %m");
+ }
+
+ s->sent_notify_ready = true;
+ log_debug("Sent READY=1 notification.");
+
+ } else if (s->stdout_streams_notify_queue)
+ /* Dispatch one stream notification event */
+ stdout_stream_send_notify(s->stdout_streams_notify_queue);
+
+ /* Leave us enabled if there's still more to to do. */
+ if (s->stdout_streams_notify_queue)
+ return 0;
+
+ /* There was nothing to do anymore, let's turn ourselves off. */
+ r = sd_event_source_set_enabled(es, SD_EVENT_OFF);
+ if (r < 0)
+ return log_error_errno(r, "Failed to turn off notify event source: %m");
+
+ return 0;
+}
+
+static int server_connect_notify(Server *s) {
+ union sockaddr_union sa = {
+ .un.sun_family = AF_UNIX,
+ };
+ const char *e;
+ int r;
+
+ assert(s);
+ assert(s->notify_fd < 0);
+ assert(!s->notify_event_source);
+
+ /*
+ So here's the problem: we'd like to send notification
+ messages to PID 1, but we cannot do that via sd_notify(),
+ since that's synchronous, and we might end up blocking on
+ it. Specifically: given that PID 1 might block on
+ dbus-daemon during IPC, and dbus-daemon is logging to us,
+ and might hence block on us, we might end up in a deadlock
+ if we block on sending PID 1 notification messages -- by
+ generating a full blocking circle. To avoid this, let's
+ create a non-blocking socket, and connect it to the
+ notification socket, and then wait for POLLOUT before we
+ send anything. This should efficiently avoid any deadlocks,
+ as we'll never block on PID 1, hence PID 1 can safely block
+ on dbus-daemon which can safely block on us again.
+
+ Don't think that this issue is real? It is, see:
+ https://github.com/systemd/systemd/issues/1505
+ */
+
+ e = getenv("NOTIFY_SOCKET");
+ if (!e)
+ return 0;
+
+ if ((e[0] != '@' && e[0] != '/') || e[1] == 0) {
+ log_error("NOTIFY_SOCKET set to an invalid value: %s", e);
+ return -EINVAL;
+ }
+
+ if (strlen(e) > sizeof(sa.un.sun_path)) {
+ log_error("NOTIFY_SOCKET path too long: %s", e);
+ return -EINVAL;
+ }
+
+ s->notify_fd = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0);
+ if (s->notify_fd < 0)
+ return log_error_errno(errno, "Failed to create notify socket: %m");
+
+ (void) fd_inc_sndbuf(s->notify_fd, NOTIFY_SNDBUF_SIZE);
+
+ strncpy(sa.un.sun_path, e, sizeof(sa.un.sun_path));
+ if (sa.un.sun_path[0] == '@')
+ sa.un.sun_path[0] = 0;
+
+ r = connect(s->notify_fd, &sa.sa, offsetof(struct sockaddr_un, sun_path) + strlen(e));
+ if (r < 0)
+ return log_error_errno(errno, "Failed to connect to notify socket: %m");
+
+ r = sd_event_add_io(s->event, &s->notify_event_source, s->notify_fd, EPOLLOUT, dispatch_notify_event, s);
+ if (r < 0)
+ return log_error_errno(r, "Failed to watch notification socket: %m");
+
+ /* This should fire pretty soon, which we'll use to send the
+ * READY=1 event. */
+
+ return 0;
+}
+
int server_init(Server *s) {
_cleanup_fdset_free_ FDSet *fds = NULL;
int n, r, fd;
@@ -1457,7 +1587,7 @@ int server_init(Server *s) {
assert(s);
zero(*s);
- s->syslog_fd = s->native_fd = s->stdout_fd = s->dev_kmsg_fd = s->audit_fd = s->hostname_fd = -1;
+ s->syslog_fd = s->native_fd = s->stdout_fd = s->dev_kmsg_fd = s->audit_fd = s->hostname_fd = s->notify_fd = -1;
s->compress = true;
s->seal = true;
@@ -1503,8 +1633,6 @@ int server_init(Server *s) {
if (r < 0)
return log_error_errno(r, "Failed to create event loop: %m");
- sd_event_set_watchdog(s->event, true);
-
n = sd_listen_fds(true);
if (n < 0)
return log_error_errno(n, "Failed to read listening file descriptors from environment: %m");
@@ -1629,6 +1757,8 @@ int server_init(Server *s) {
server_cache_boot_id(s);
server_cache_machine_id(s);
+ (void) server_connect_notify(s);
+
return system_journal_open(s, false);
}
@@ -1677,6 +1807,7 @@ void server_done(Server *s) {
sd_event_source_unref(s->sigterm_event_source);
sd_event_source_unref(s->sigint_event_source);
sd_event_source_unref(s->hostname_event_source);
+ sd_event_source_unref(s->notify_event_source);
sd_event_unref(s->event);
safe_close(s->syslog_fd);
@@ -1685,6 +1816,7 @@ void server_done(Server *s) {
safe_close(s->dev_kmsg_fd);
safe_close(s->audit_fd);
safe_close(s->hostname_fd);
+ safe_close(s->notify_fd);
if (s->rate_limit)
journal_rate_limit_free(s->rate_limit);
diff --git a/src/journal/journald-server.h b/src/journal/journald-server.h
index 535c0ab9ab..170602ea16 100644
--- a/src/journal/journald-server.h
+++ b/src/journal/journald-server.h
@@ -25,10 +25,13 @@
#include <sys/types.h>
#include "sd-event.h"
-#include "journal-file.h"
+
+typedef struct Server Server;
+
#include "hashmap.h"
-#include "audit.h"
+#include "journal-file.h"
#include "journald-rate-limit.h"
+#include "journald-stream.h"
#include "list.h"
typedef enum Storage {
@@ -48,15 +51,14 @@ typedef enum SplitMode {
_SPLIT_INVALID = -1
} SplitMode;
-typedef struct StdoutStream StdoutStream;
-
-typedef struct Server {
+struct Server {
int syslog_fd;
int native_fd;
int stdout_fd;
int dev_kmsg_fd;
int audit_fd;
int hostname_fd;
+ int notify_fd;
sd_event *event;
@@ -71,6 +73,7 @@ typedef struct Server {
sd_event_source *sigterm_event_source;
sd_event_source *sigint_event_source;
sd_event_source *hostname_event_source;
+ sd_event_source *notify_event_source;
JournalFile *runtime_journal;
JournalFile *system_journal;
@@ -111,6 +114,7 @@ typedef struct Server {
usec_t oldest_file_usec;
LIST_HEAD(StdoutStream, stdout_streams);
+ LIST_HEAD(StdoutStream, stdout_streams_notify_queue);
unsigned n_stdout_streams;
char *tty_path;
@@ -132,6 +136,7 @@ typedef struct Server {
struct udev *udev;
+ bool sent_notify_ready;
bool sync_scheduled;
char machine_id_field[sizeof("_MACHINE_ID=") + 32];
@@ -140,7 +145,7 @@ typedef struct Server {
/* Cached cgroup root, so that we don't have to query that all the time */
char *cgroup_root;
-} Server;
+};
#define SERVER_MACHINE_ID(s) ((s)->machine_id_field + strlen("_MACHINE_ID="))
diff --git a/src/journal/journald-stream.c b/src/journal/journald-stream.c
index 0dd511519c..fb6afee171 100644
--- a/src/journal/journald-stream.c
+++ b/src/journal/journald-stream.c
@@ -29,9 +29,12 @@
#include "sd-daemon.h"
#include "sd-event.h"
+#include "alloc-util.h"
+#include "dirent-util.h"
#include "escape.h"
#include "fd-util.h"
#include "fileio.h"
+#include "io-util.h"
#include "journald-console.h"
#include "journald-kmsg.h"
#include "journald-server.h"
@@ -39,9 +42,12 @@
#include "journald-syslog.h"
#include "journald-wall.h"
#include "mkdir.h"
+#include "parse-util.h"
#include "selinux-util.h"
#include "socket-util.h"
+#include "stdio-util.h"
#include "string-util.h"
+#include "syslog-util.h"
#define STDOUT_STREAMS_MAX 4096
@@ -73,6 +79,7 @@ struct StdoutStream {
bool forward_to_console:1;
bool fdstore:1;
+ bool in_notify_queue:1;
char buffer[LINE_MAX+1];
size_t length;
@@ -82,6 +89,7 @@ struct StdoutStream {
char *state_file;
LIST_FIELDS(StdoutStream, stdout_stream);
+ LIST_FIELDS(StdoutStream, stdout_stream_notify_queue);
};
void stdout_stream_free(StdoutStream *s) {
@@ -92,6 +100,9 @@ void stdout_stream_free(StdoutStream *s) {
assert(s->server->n_stdout_streams > 0);
s->server->n_stdout_streams --;
LIST_REMOVE(stdout_stream, s->server->stdout_streams, s);
+
+ if (s->in_notify_queue)
+ LIST_REMOVE(stdout_stream_notify_queue, s->server->stdout_streams_notify_queue, s);
}
if (s->event_source) {
@@ -115,7 +126,7 @@ static void stdout_stream_destroy(StdoutStream *s) {
return;
if (s->state_file)
- unlink(s->state_file);
+ (void) unlink(s->state_file);
stdout_stream_free(s);
}
@@ -194,11 +205,15 @@ static int stdout_stream_save(StdoutStream *s) {
goto fail;
}
- /* Store the connection fd in PID 1, so that we get it passed
- * in again on next start */
- if (!s->fdstore) {
- sd_pid_notify_with_fds(0, false, "FDSTORE=1", &s->fd, 1);
- s->fdstore = true;
+ if (!s->fdstore && !s->in_notify_queue) {
+ LIST_PREPEND(stdout_stream_notify_queue, s->server->stdout_streams_notify_queue, s);
+ s->in_notify_queue = true;
+
+ if (s->server->notify_event_source) {
+ r = sd_event_source_set_enabled(s->server->notify_event_source, SD_EVENT_ON);
+ if (r < 0)
+ log_warning_errno(r, "Failed to enable notify event source: %m");
+ }
}
return 0;
@@ -723,3 +738,50 @@ int server_open_stdout_socket(Server *s) {
return 0;
}
+
+void stdout_stream_send_notify(StdoutStream *s) {
+ struct iovec iovec = {
+ .iov_base = (char*) "FDSTORE=1",
+ .iov_len = strlen("FDSTORE=1"),
+ };
+ struct msghdr msghdr = {
+ .msg_iov = &iovec,
+ .msg_iovlen = 1,
+ };
+ struct cmsghdr *cmsg;
+ ssize_t l;
+
+ assert(s);
+ assert(!s->fdstore);
+ assert(s->in_notify_queue);
+ assert(s->server);
+ assert(s->server->notify_fd >= 0);
+
+ /* Store the connection fd in PID 1, so that we get it passed
+ * in again on next start */
+
+ msghdr.msg_controllen = CMSG_SPACE(sizeof(int));
+ msghdr.msg_control = alloca0(msghdr.msg_controllen);
+
+ cmsg = CMSG_FIRSTHDR(&msghdr);
+ cmsg->cmsg_level = SOL_SOCKET;
+ cmsg->cmsg_type = SCM_RIGHTS;
+ cmsg->cmsg_len = CMSG_LEN(sizeof(int));
+
+ memcpy(CMSG_DATA(cmsg), &s->fd, sizeof(int));
+
+ l = sendmsg(s->server->notify_fd, &msghdr, MSG_DONTWAIT|MSG_NOSIGNAL);
+ if (l < 0) {
+ if (errno == EAGAIN)
+ return;
+
+ log_error_errno(errno, "Failed to send stream file descriptor to service manager: %m");
+ } else {
+ log_debug("Successfully sent stream file descriptor to service manager.");
+ s->fdstore = 1;
+ }
+
+ LIST_REMOVE(stdout_stream_notify_queue, s->server->stdout_streams_notify_queue, s);
+ s->in_notify_queue = false;
+
+}
diff --git a/src/journal/journald-stream.h b/src/journal/journald-stream.h
index 257dce45df..e3497f0ded 100644
--- a/src/journal/journald-stream.h
+++ b/src/journal/journald-stream.h
@@ -21,9 +21,13 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
+typedef struct StdoutStream StdoutStream;
+
#include "fdset.h"
#include "journald-server.h"
int server_open_stdout_socket(Server *s);
int server_restore_streams(Server *s, FDSet *fds);
+
void stdout_stream_free(StdoutStream *s);
+void stdout_stream_send_notify(StdoutStream *s);
diff --git a/src/journal/journald-syslog.c b/src/journal/journald-syslog.c
index 7e9ba12560..f3ac1a7ae0 100644
--- a/src/journal/journald-syslog.c
+++ b/src/journal/journald-syslog.c
@@ -25,8 +25,10 @@
#include "sd-messages.h"
+#include "alloc-util.h"
#include "fd-util.h"
#include "formats-util.h"
+#include "io-util.h"
#include "journald-console.h"
#include "journald-kmsg.h"
#include "journald-server.h"
@@ -35,7 +37,9 @@
#include "process-util.h"
#include "selinux-util.h"
#include "socket-util.h"
+#include "stdio-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)
diff --git a/src/journal/journald-wall.c b/src/journal/journald-wall.c
index 5284914941..69540f1141 100644
--- a/src/journal/journald-wall.c
+++ b/src/journal/journald-wall.c
@@ -19,6 +19,7 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
+#include "alloc-util.h"
#include "formats-util.h"
#include "journald-server.h"
#include "process-util.h"
diff --git a/src/journal/journald.c b/src/journal/journald.c
index 83236ceba9..b137e3c7be 100644
--- a/src/journal/journald.c
+++ b/src/journal/journald.c
@@ -61,10 +61,6 @@ int main(int argc, char *argv[]) {
log_debug("systemd-journald running as pid "PID_FMT, getpid());
server_driver_message(&server, SD_MESSAGE_JOURNAL_START, "Journal started");
- sd_notify(false,
- "READY=1\n"
- "STATUS=Processing requests...");
-
for (;;) {
usec_t t = USEC_INFINITY, n;
@@ -117,10 +113,6 @@ int main(int argc, char *argv[]) {
server_driver_message(&server, SD_MESSAGE_JOURNAL_STOP, "Journal stopped");
finish:
- sd_notify(false,
- "STOPPING=1\n"
- "STATUS=Shutting down...");
-
server_done(&server);
return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
diff --git a/src/journal/mmap-cache.c b/src/journal/mmap-cache.c
index 22f75540b8..3cb1dfa986 100644
--- a/src/journal/mmap-cache.c
+++ b/src/journal/mmap-cache.c
@@ -23,6 +23,7 @@
#include <stdlib.h>
#include <sys/mman.h>
+#include "alloc-util.h"
#include "hashmap.h"
#include "list.h"
#include "log.h"
diff --git a/src/journal/sd-journal.c b/src/journal/sd-journal.c
index 9dcfc726ea..218df8cebe 100644
--- a/src/journal/sd-journal.c
+++ b/src/journal/sd-journal.c
@@ -30,11 +30,14 @@
#include "sd-journal.h"
+#include "alloc-util.h"
#include "catalog.h"
#include "compress.h"
+#include "dirent-util.h"
#include "fd-util.h"
#include "fileio.h"
#include "formats-util.h"
+#include "fs-util.h"
#include "hashmap.h"
#include "hostname-util.h"
#include "io-util.h"
@@ -46,6 +49,8 @@
#include "missing.h"
#include "path-util.h"
#include "replace-var.h"
+#include "stat-util.h"
+#include "stdio-util.h"
#include "string-util.h"
#include "strv.h"
@@ -1020,8 +1025,6 @@ _public_ int sd_journal_seek_cursor(sd_journal *j, const char *cursor) {
_public_ int sd_journal_test_cursor(sd_journal *j, const char *cursor) {
int r;
- const char *word, *state;
- size_t l;
Object *o;
assert_return(j, -EINVAL);
@@ -1035,20 +1038,23 @@ _public_ int sd_journal_test_cursor(sd_journal *j, const char *cursor) {
if (r < 0)
return r;
- FOREACH_WORD_SEPARATOR(word, l, cursor, ";", state) {
+ for(;;) {
_cleanup_free_ char *item = NULL;
- sd_id128_t id;
unsigned long long ll;
+ sd_id128_t id;
int k = 0;
- if (l < 2 || word[1] != '=')
- return -EINVAL;
+ r = extract_first_word(&cursor, &item, ";", EXTRACT_DONT_COALESCE_SEPARATORS);
+ if (r < 0)
+ return r;
- item = strndup(word, l);
- if (!item)
- return -ENOMEM;
+ if (r == 0)
+ break;
- switch (word[0]) {
+ if (strlen(item) < 2 || item[1] != '=')
+ return -EINVAL;
+
+ switch (item[0]) {
case 's':
k = sd_id128_from_string(item+2, &id);
diff --git a/src/journal/stacktrace.c b/src/journal/stacktrace.c
index e32550d644..4305462f80 100644
--- a/src/journal/stacktrace.c
+++ b/src/journal/stacktrace.c
@@ -22,6 +22,7 @@
#include <dwarf.h>
#include <elfutils/libdwfl.h>
+#include "alloc-util.h"
#include "fd-util.h"
#include "formats-util.h"
#include "macro.h"
diff --git a/src/journal/test-catalog.c b/src/journal/test-catalog.c
index 72c1f60f02..aea8fd15e6 100644
--- a/src/journal/test-catalog.c
+++ b/src/journal/test-catalog.c
@@ -27,8 +27,10 @@
#include "sd-messages.h"
+#include "alloc-util.h"
#include "catalog.h"
#include "fd-util.h"
+#include "fileio.h"
#include "log.h"
#include "macro.h"
#include "string-util.h"
diff --git a/src/journal/test-compress-benchmark.c b/src/journal/test-compress-benchmark.c
index 0a9ab7f52c..93ea9c6318 100644
--- a/src/journal/test-compress-benchmark.c
+++ b/src/journal/test-compress-benchmark.c
@@ -19,8 +19,10 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
+#include "alloc-util.h"
#include "compress.h"
#include "macro.h"
+#include "parse-util.h"
#include "random-util.h"
#include "string-util.h"
#include "util.h"
diff --git a/src/journal/test-compress.c b/src/journal/test-compress.c
index e562fa1948..b9d90a8988 100644
--- a/src/journal/test-compress.c
+++ b/src/journal/test-compress.c
@@ -17,8 +17,10 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
+#include "alloc-util.h"
#include "compress.h"
#include "fd-util.h"
+#include "fileio.h"
#include "macro.h"
#include "random-util.h"
#include "util.h"
diff --git a/src/journal/test-journal-flush.c b/src/journal/test-journal-flush.c
index 6061623ae7..03d1522e23 100644
--- a/src/journal/test-journal-flush.c
+++ b/src/journal/test-journal-flush.c
@@ -23,6 +23,7 @@
#include "sd-journal.h"
+#include "alloc-util.h"
#include "journal-file.h"
#include "journal-internal.h"
#include "macro.h"
diff --git a/src/journal/test-journal-init.c b/src/journal/test-journal-init.c
index 717b703d19..142da85041 100644
--- a/src/journal/test-journal-init.c
+++ b/src/journal/test-journal-init.c
@@ -22,6 +22,7 @@
#include "sd-journal.h"
#include "log.h"
+#include "parse-util.h"
#include "rm-rf.h"
#include "util.h"
diff --git a/src/journal/test-journal-interleaving.c b/src/journal/test-journal-interleaving.c
index 8069339c1f..4ad89fe4b6 100644
--- a/src/journal/test-journal-interleaving.c
+++ b/src/journal/test-journal-interleaving.c
@@ -24,11 +24,14 @@
#include <fcntl.h>
#include "sd-journal.h"
+
+#include "alloc-util.h"
#include "journal-file.h"
#include "journal-vacuum.h"
-#include "util.h"
#include "log.h"
+#include "parse-util.h"
#include "rm-rf.h"
+#include "util.h"
/* This program tests skipping around in a multi-file journal.
*/
diff --git a/src/journal/test-journal-match.c b/src/journal/test-journal-match.c
index 476477055a..abefedb992 100644
--- a/src/journal/test-journal-match.c
+++ b/src/journal/test-journal-match.c
@@ -23,6 +23,7 @@
#include "sd-journal.h"
+#include "alloc-util.h"
#include "journal-internal.h"
#include "log.h"
#include "string-util.h"
diff --git a/src/journal/test-journal-stream.c b/src/journal/test-journal-stream.c
index b5ecf2f375..0cbef4b8c5 100644
--- a/src/journal/test-journal-stream.c
+++ b/src/journal/test-journal-stream.c
@@ -19,16 +19,19 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
-#include <unistd.h>
#include <fcntl.h>
+#include <unistd.h>
#include "sd-journal.h"
-#include "util.h"
+
+#include "alloc-util.h"
+#include "journal-file.h"
+#include "journal-internal.h"
#include "log.h"
#include "macro.h"
+#include "parse-util.h"
#include "rm-rf.h"
-#include "journal-file.h"
-#include "journal-internal.h"
+#include "util.h"
#define N_ENTRIES 200
diff --git a/src/journal/test-journal-syslog.c b/src/journal/test-journal-syslog.c
index de942c50cc..1784187fe9 100644
--- a/src/journal/test-journal-syslog.c
+++ b/src/journal/test-journal-syslog.c
@@ -19,6 +19,7 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
+#include "alloc-util.h"
#include "journald-syslog.h"
#include "macro.h"
#include "string-util.h"
diff --git a/src/journal/test-mmap-cache.c b/src/journal/test-mmap-cache.c
index ac1239acc4..fdd48e531c 100644
--- a/src/journal/test-mmap-cache.c
+++ b/src/journal/test-mmap-cache.c
@@ -19,12 +19,13 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
+#include <fcntl.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <unistd.h>
-#include <fcntl.h>
#include "fd-util.h"
+#include "fileio.h"
#include "macro.h"
#include "mmap-cache.h"
#include "util.h"