diff options
author | Karol Lewandowski <k.lewandowsk@samsung.com> | 2021-03-24 21:16:40 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@review> | 2021-03-24 21:16:40 +0000 |
commit | 2f75e3c6bc10d67b9c69533d608029d6717b68d1 (patch) | |
tree | cbc0809426e91021e720bf02939f0b37652002c5 | |
parent | 492e8d38fed26e683762f6750bc6205324fecb2c (diff) | |
parent | 6a1f41c36bd6fe1057109428570e11140bbbeab3 (diff) | |
download | systemd-2f75e3c6bc10d67b9c69533d608029d6717b68d1.tar.gz systemd-2f75e3c6bc10d67b9c69533d608029d6717b68d1.tar.bz2 systemd-2f75e3c6bc10d67b9c69533d608029d6717b68d1.zip |
Merge "Basic PoC for DLog stdout redirector" into tizensubmit/tizen/20210326.090524submit/tizen/20210324.095642accepted/tizen/unified/20210328.230635
-rw-r--r-- | meson.build | 2 | ||||
-rw-r--r-- | packaging/systemd.spec | 1 | ||||
-rw-r--r-- | src/core/execute.c | 57 | ||||
-rw-r--r-- | src/core/execute.h | 3 | ||||
-rw-r--r-- | src/core/meson.build | 1 |
5 files changed, 62 insertions, 2 deletions
diff --git a/meson.build b/meson.build index 06002d656c..98d333b684 100644 --- a/meson.build +++ b/meson.build @@ -859,6 +859,8 @@ if not libcap.found() libcap = cc.find_library('cap') endif +libdlog_redirect_stdout = dependency('dlog-redirect-stdout', required : true) + libmount = dependency('mount', version : fuzzer_build ? '>= 0' : '>= 2.30') diff --git a/packaging/systemd.spec b/packaging/systemd.spec index a1aa48b993..03feb750eb 100644 --- a/packaging/systemd.spec +++ b/packaging/systemd.spec @@ -84,6 +84,7 @@ BuildRequires: pkgconfig(liblzma) BuildRequires: pkgconfig(libkmod) BuildRequires: pkgconfig(mount) BuildRequires: pkgconfig(libdbuspolicy1) +BuildRequires: pkgconfig(dlog-redirect-stdout) BuildRequires: meson BuildRequires: acl BuildRequires: python diff --git a/src/core/execute.c b/src/core/execute.c index 414c3854b8..14a7d1399b 100644 --- a/src/core/execute.c +++ b/src/core/execute.c @@ -14,6 +14,8 @@ #include <unistd.h> #include <utmpx.h> +#include <dlog/dlog-redirect-stdout.h> + #if HAVE_PAM #include <security/pam_appl.h> #endif @@ -253,18 +255,26 @@ static bool exec_context_needs_term(const ExecContext *c) { return !!c->tty_path; } -static int open_null_as(int flags, int nfd) { +static int open_device_as(const char *devname, int flags, int nfd) { int fd; assert(nfd >= 0); - fd = open("/dev/null", flags|O_NOCTTY); + fd = open(devname, flags|O_NOCTTY); if (fd < 0) return -errno; return move_fd(fd, nfd, false); } +static int open_null_as(int flags, int nfd) { + return open_device_as("/dev/null", flags, nfd); +} + +static int open_kmsg_as(int flags, int nfd) { + return open_device_as("/dev/kmsg", flags, nfd); +} + static int connect_journal_socket(int fd, uid_t uid, gid_t gid) { static const union sockaddr_union sa = { .un.sun_family = AF_UNIX, @@ -560,6 +570,28 @@ static bool can_inherit_stderr_from_stdout( return true; } +static int wire_up_dlog(int fileno, const char *ident) +{ + /* NB: dlogutil has FOO* tag filtering wildcards but not *FOO + * therefore the STDFOO part of the final tag goes in front. + * + * The tag can nominally be longer than 128 but dlogutil will + * not print a longer one anyway and it's good to limit overhead */ + char tag[128]; + int priority; + + if (fileno == STDERR_FILENO) { + priority = 6; // ERROR + snprintf(tag, sizeof tag, "STDERR_%s", ident); + } else { + priority = 4; // INFO + snprintf(tag, sizeof tag, "STDOUT_%s", ident); + } + + return connect_dlog(2, // SYSTEM dlog buffer (consider also 0 for generic MAIN buffer) + fileno, tag, priority); +} + static int setup_output( const Unit *unit, const ExecContext *context, @@ -680,6 +712,24 @@ static int setup_output( } return r; + case EXEC_OUTPUT_DLOG: + r = wire_up_dlog(fileno, ident); + return r < 0 ? r : fileno; + + case EXEC_OUTPUT_DLOG_OR_NULL: + r = wire_up_dlog(fileno, ident); + if (r >= 0) + return fileno; + else + return open_null_as(O_WRONLY, fileno); + + case EXEC_OUTPUT_DLOG_OR_KMSG: + r = wire_up_dlog(fileno, ident); + if (r >= 0) + return fileno; + else + return open_kmsg_as(O_WRONLY, fileno); + case EXEC_OUTPUT_SOCKET: assert(socket_fd >= 0); @@ -5627,6 +5677,9 @@ static const char* const exec_output_table[_EXEC_OUTPUT_MAX] = { [EXEC_OUTPUT_NAMED_FD] = "fd", [EXEC_OUTPUT_FILE] = "file", [EXEC_OUTPUT_FILE_APPEND] = "append", + [EXEC_OUTPUT_DLOG] = "dlog", + [EXEC_OUTPUT_DLOG_OR_NULL] = "dlog|null", + [EXEC_OUTPUT_DLOG_OR_KMSG] = "dlog|kmsg", }; DEFINE_STRING_TABLE_LOOKUP(exec_output, ExecOutput); diff --git a/src/core/execute.h b/src/core/execute.h index 43ec07c143..11a4054712 100644 --- a/src/core/execute.h +++ b/src/core/execute.h @@ -60,6 +60,9 @@ typedef enum ExecOutput { EXEC_OUTPUT_NAMED_FD, EXEC_OUTPUT_FILE, EXEC_OUTPUT_FILE_APPEND, + EXEC_OUTPUT_DLOG, + EXEC_OUTPUT_DLOG_OR_NULL, + EXEC_OUTPUT_DLOG_OR_KMSG, _EXEC_OUTPUT_MAX, _EXEC_OUTPUT_INVALID = -1 } ExecOutput; diff --git a/src/core/meson.build b/src/core/meson.build index 9cd72f5ea0..a7afe19507 100644 --- a/src/core/meson.build +++ b/src/core/meson.build @@ -181,6 +181,7 @@ libcore = static_library( libkmod, libapparmor, libselinux, + libdlog_redirect_stdout, libmount]) systemd_sources = files('main.c') |