core: implement /run/systemd/units/-based path for passing unit info from PID 1 to journald

And let's make use of it to implement two new unit settings with it:

1. LogLevelMax= is a new per-unit setting that may be used to configure
   log priority filtering: set it to LogLevelMax=notice and only
   messages of level "notice" and lower (i.e. more important) will be
   processed, all others are dropped.

2. LogExtraFields= is a new per-unit setting for configuring per-unit
   journal fields, that are implicitly included in every log record
   generated by the unit's processes. It takes field/value pairs in the
   form of FOO=BAR.

Also, related to this, one exisiting unit setting is ported to this new
facility:

3. The invocation ID is now pulled from /run/systemd/units/ instead of
   cgroupfs xattrs. This substantially relaxes requirements of systemd
   on the kernel version and the privileges it runs with (specifically,
   cgroupfs xattrs are not available in containers, since they are
   stored in kernel memory, and hence are unsafe to permit to lesser
   privileged code).

/run/systemd/units/ is a new directory, which contains a number of files
and symlinks encoding the above information. PID 1 creates and manages
these files, and journald reads them from there.

Note that this is supposed to be a direct path between PID 1 and the
journal only, due to the special runtime environment the journal runs
in. Normally, today we shouldn't introduce new interfaces that (mis-)use
a file system as IPC framework, and instead just an IPC system, but this
is very hard to do between the journal and PID 1, as long as the IPC
system is a subject PID 1 manages, and itself a client to the journal.

This patch cleans up a couple of types used in journal code:
specifically we switch to size_t for a couple of memory-sizing values,
as size_t is the right choice for everything that is memory.

Fixes: #4089
Fixes: #3041
Fixes: #4441
This commit is contained in:
Lennart Poettering
2017-11-16 12:40:17 +01:00
parent 4d14b2bd35
commit d3070fbdf6
27 changed files with 767 additions and 88 deletions
+128 -1
View File
@@ -26,15 +26,17 @@
#include "af-list.h"
#include "alloc-util.h"
#include "bus-util.h"
#include "capability-util.h"
#include "cap-list.h"
#include "capability-util.h"
#include "dbus-execute.h"
#include "env-util.h"
#include "errno-list.h"
#include "execute.h"
#include "fd-util.h"
#include "fileio.h"
#include "io-util.h"
#include "ioprio.h"
#include "journal-util.h"
#include "missing.h"
#include "mount-util.h"
#include "namespace.h"
@@ -771,6 +773,37 @@ static int property_get_bind_paths(
return sd_bus_message_close_container(reply);
}
static int property_get_log_extra_fields(
sd_bus *bus,
const char *path,
const char *interface,
const char *property,
sd_bus_message *reply,
void *userdata,
sd_bus_error *error) {
ExecContext *c = userdata;
size_t i;
int r;
assert(bus);
assert(c);
assert(property);
assert(reply);
r = sd_bus_message_open_container(reply, 'a', "ay");
if (r < 0)
return r;
for (i = 0; i < c->n_log_extra_fields; i++) {
r = sd_bus_message_append_array(reply, 'y', c->log_extra_fields[i].iov_base, c->log_extra_fields[i].iov_len);
if (r < 0)
return r;
}
return sd_bus_message_close_container(reply);
}
const sd_bus_vtable bus_exec_vtable[] = {
SD_BUS_VTABLE_START(0),
SD_BUS_PROPERTY("Environment", "as", NULL, offsetof(ExecContext, environment), SD_BUS_VTABLE_PROPERTY_CONST),
@@ -838,6 +871,8 @@ const sd_bus_vtable bus_exec_vtable[] = {
SD_BUS_PROPERTY("SyslogLevelPrefix", "b", bus_property_get_bool, offsetof(ExecContext, syslog_level_prefix), SD_BUS_VTABLE_PROPERTY_CONST),
SD_BUS_PROPERTY("SyslogLevel", "i", property_get_syslog_level, 0, SD_BUS_VTABLE_PROPERTY_CONST),
SD_BUS_PROPERTY("SyslogFacility", "i", property_get_syslog_facility, 0, SD_BUS_VTABLE_PROPERTY_CONST),
SD_BUS_PROPERTY("LogLevelMax", "i", bus_property_get_int, offsetof(ExecContext, log_level_max), SD_BUS_VTABLE_PROPERTY_CONST),
SD_BUS_PROPERTY("LogExtraFields", "aay", property_get_log_extra_fields, 0, SD_BUS_VTABLE_PROPERTY_CONST),
SD_BUS_PROPERTY("SecureBits", "i", bus_property_get_int, offsetof(ExecContext, secure_bits), SD_BUS_VTABLE_PROPERTY_CONST),
SD_BUS_PROPERTY("CapabilityBoundingSet", "t", property_get_capability_bounding_set, 0, SD_BUS_VTABLE_PROPERTY_CONST),
SD_BUS_PROPERTY("AmbientCapabilities", "t", property_get_ambient_capabilities, 0, SD_BUS_VTABLE_PROPERTY_CONST),
@@ -1137,6 +1172,98 @@ int bus_exec_context_set_transient_property(
}
return 1;
} else if (streq(name, "LogLevelMax")) {
int32_t level;
r = sd_bus_message_read(message, "i", &level);
if (r < 0)
return r;
if (!log_level_is_valid(level))
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Maximum log level value out of range");
if (mode != UNIT_CHECK) {
c->log_level_max = level;
unit_write_drop_in_private_format(u, mode, name, "LogLevelMax=%i", level);
}
return 1;
} else if (streq(name, "LogExtraFields")) {
size_t n = 0;
r = sd_bus_message_enter_container(message, 'a', "ay");
if (r < 0)
return r;
for (;;) {
_cleanup_free_ void *copy = NULL;
struct iovec *t;
const char *eq;
const void *p;
size_t sz;
/* Note that we expect a byte array for each field, instead of a string. That's because on the
* lower-level journal fields can actually contain binary data and are not restricted to text,
* and we should not "lose precision" in our types on the way. That said, I am pretty sure
* actually encoding binary data as unit metadata is not a good idea. Hence we actually refuse
* any actual binary data, and only accept UTF-8. This allows us to eventually lift this
* limitation, should a good, valid usecase arise. */
r = sd_bus_message_read_array(message, 'y', &p, &sz);
if (r < 0)
return r;
if (r == 0)
break;
if (memchr(p, 0, sz))
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Journal field contains zero byte");
eq = memchr(p, '=', sz);
if (!eq)
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Journal field contains no '=' character");
if (!journal_field_valid(p, eq - (const char*) p, false))
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Journal field invalid");
if (mode != UNIT_CHECK) {
t = realloc_multiply(c->log_extra_fields, sizeof(struct iovec), c->n_log_extra_fields+1);
if (!t)
return -ENOMEM;
c->log_extra_fields = t;
}
copy = malloc(sz + 1);
if (!copy)
return -ENOMEM;
memcpy(copy, p, sz);
((uint8_t*) copy)[sz] = 0;
if (!utf8_is_valid(copy))
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Journal field is not valid UTF-8");
if (mode != UNIT_CHECK) {
c->log_extra_fields[c->n_log_extra_fields++] = IOVEC_MAKE(copy, sz);
unit_write_drop_in_private_format(u, mode, name, "LogExtraFields=%s", (char*) copy);
copy = NULL;
}
n++;
}
r = sd_bus_message_exit_container(message);
if (r < 0)
return r;
if (mode != UNIT_CHECK && n == 0) {
exec_context_free_log_extra_fields(c);
unit_write_drop_in_private(u, mode, name, "LogExtraFields=");
}
return 1;
} else if (streq(name, "SecureBits")) {
int n;
+38 -2
View File
@@ -3483,11 +3483,12 @@ void exec_context_init(ExecContext *c) {
c->directories[i].mode = 0755;
c->capability_bounding_set = CAP_ALL;
c->restrict_namespaces = NAMESPACE_FLAGS_ALL;
c->log_level_max = -1;
}
void exec_context_done(ExecContext *c) {
unsigned l;
ExecDirectoryType i;
size_t l;
assert(c);
@@ -3534,6 +3535,10 @@ void exec_context_done(ExecContext *c) {
for (i = 0; i < _EXEC_DIRECTORY_TYPE_MAX; i++)
c->directories[i].paths = strv_free(c->directories[i].paths);
c->log_level_max = -1;
exec_context_free_log_extra_fields(c);
}
int exec_context_destroy_runtime_directory(ExecContext *c, const char *runtime_prefix) {
@@ -3796,9 +3801,9 @@ static void strv_fprintf(FILE *f, char **l) {
}
void exec_context_dump(ExecContext *c, FILE* f, const char *prefix) {
ExecDirectoryType dt;
char **e, **d;
unsigned i;
ExecDirectoryType dt;
int r;
assert(c);
@@ -3966,6 +3971,26 @@ void exec_context_dump(ExecContext *c, FILE* f, const char *prefix) {
fprintf(f, "%sSyslogLevel: %s\n", prefix, lvl_str);
}
if (c->log_level_max >= 0) {
_cleanup_free_ char *t = NULL;
(void) log_level_to_string_alloc(c->log_level_max, &t);
fprintf(f, "%sLogLevelMax: %s\n", prefix, strna(t));
}
if (c->n_log_extra_fields > 0) {
size_t j;
for (j = 0; j < c->n_log_extra_fields; j++) {
fprintf(f, "%sLogExtraFields: ", prefix);
fwrite(c->log_extra_fields[j].iov_base,
1, c->log_extra_fields[j].iov_len,
f);
fputc('\n', f);
}
}
if (c->secure_bits) {
_cleanup_free_ char *str = NULL;
@@ -4177,6 +4202,17 @@ int exec_context_get_effective_ioprio(ExecContext *c) {
return p;
}
void exec_context_free_log_extra_fields(ExecContext *c) {
size_t l;
assert(c);
for (l = 0; l < c->n_log_extra_fields; l++)
free(c->log_extra_fields[l].iov_base);
c->log_extra_fields = mfree(c->log_extra_fields);
c->n_log_extra_fields = 0;
}
void exec_status_start(ExecStatus *s, pid_t pid) {
assert(s);
+7
View File
@@ -212,6 +212,11 @@ struct ExecContext {
char *syslog_identifier;
bool syslog_level_prefix;
int log_level_max;
struct iovec* log_extra_fields;
size_t n_log_extra_fields;
bool cpu_sched_reset_on_fork;
bool non_blocking;
bool private_tmp;
@@ -353,6 +358,8 @@ bool exec_context_maintains_privileges(ExecContext *c);
int exec_context_get_effective_ioprio(ExecContext *c);
void exec_context_free_log_extra_fields(ExecContext *c);
void exec_status_start(ExecStatus *s, pid_t pid);
void exec_status_exit(ExecStatus *s, ExecContext *context, pid_t pid, int code, int status);
void exec_status_dump(ExecStatus *s, FILE *f, const char *prefix);
+2
View File
@@ -49,6 +49,8 @@ $1.SyslogIdentifier, config_parse_unit_string_printf, 0,
$1.SyslogFacility, config_parse_log_facility, 0, offsetof($1, exec_context.syslog_priority)
$1.SyslogLevel, config_parse_log_level, 0, offsetof($1, exec_context.syslog_priority)
$1.SyslogLevelPrefix, config_parse_bool, 0, offsetof($1, exec_context.syslog_level_prefix)
$1.LogLevelMax, config_parse_log_level, 0, offsetof($1, exec_context.log_level_max)
$1.LogExtraFields, config_parse_log_extra_fields, 0, offsetof($1, exec_context)
$1.Capabilities, config_parse_warn_compat, DISABLED_LEGACY, offsetof($1, exec_context)
$1.SecureBits, config_parse_exec_secure_bits, 0, offsetof($1, exec_context)
$1.CapabilityBoundingSet, config_parse_capability_set, 0, offsetof($1, exec_context.capability_bounding_set)
+74
View File
@@ -45,7 +45,9 @@
#include "escape.h"
#include "fd-util.h"
#include "fs-util.h"
#include "io-util.h"
#include "ioprio.h"
#include "journal-util.h"
#include "load-fragment.h"
#include "log.h"
#include "missing.h"
@@ -2331,6 +2333,78 @@ int config_parse_unset_environ(
return 0;
}
int config_parse_log_extra_fields(
const char *unit,
const char *filename,
unsigned line,
const char *section,
unsigned section_line,
const char *lvalue,
int ltype,
const char *rvalue,
void *data,
void *userdata) {
ExecContext *c = data;
Unit *u = userdata;
const char *p;
int r;
assert(filename);
assert(lvalue);
assert(rvalue);
assert(c);
if (isempty(rvalue)) {
exec_context_free_log_extra_fields(c);
return 0;
}
for (p = rvalue;; ) {
_cleanup_free_ char *word = NULL, *k = NULL;
struct iovec *t;
const char *eq;
r = extract_first_word(&p, &word, NULL, EXTRACT_CUNESCAPE|EXTRACT_QUOTES);
if (r == 0)
break;
if (r == -ENOMEM)
return log_oom();
if (r < 0) {
log_syntax(unit, LOG_WARNING, filename, line, r, "Invalid syntax, ignoring: %s", rvalue);
return 0;
}
r = unit_full_printf(u, word, &k);
if (r < 0) {
log_syntax(unit, LOG_ERR, filename, line, r, "Failed to resolve unit specifiers on %s, ignoring field: %m", word);
continue;
}
eq = strchr(k, '=');
if (!eq) {
log_syntax(unit, LOG_ERR, filename, line, 0, "Log field lacks '=' character, ignoring field: %s", k);
continue;
}
if (!journal_field_valid(k, eq-k, false)) {
log_syntax(unit, LOG_ERR, filename, line, 0, "Log field name is invalid, ignoring field: %s", k);
continue;
}
t = realloc_multiply(c->log_extra_fields, sizeof(struct iovec), c->n_log_extra_fields+1);
if (!t)
return log_oom();
c->log_extra_fields = t;
c->log_extra_fields[c->n_log_extra_fields++] = IOVEC_MAKE_STRING(k);
k = NULL;
}
return 0;
}
int config_parse_ip_tos(const char *unit,
const char *filename,
unsigned line,
+1
View File
@@ -121,6 +121,7 @@ int config_parse_bind_paths(const char *unit, const char *filename, unsigned lin
int config_parse_exec_keyring_mode(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
int config_parse_job_timeout_sec(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
int config_parse_job_running_timeout_sec(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
int config_parse_log_extra_fields(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
/* gperf prototypes */
const struct ConfigPerfItem* load_fragment_gperf_lookup(const char *key, GPERF_LEN_TYPE length);
+8 -1
View File
@@ -53,14 +53,15 @@
#include "dirent-util.h"
#include "env-util.h"
#include "escape.h"
#include "execute.h"
#include "exec-util.h"
#include "execute.h"
#include "exit-status.h"
#include "fd-util.h"
#include "fileio.h"
#include "fs-util.h"
#include "hashmap.h"
#include "io-util.h"
#include "label.h"
#include "locale-setup.h"
#include "log.h"
#include "macro.h"
@@ -714,6 +715,12 @@ int manager_new(UnitFileScope scope, unsigned test_run_flags, Manager **_m) {
goto fail;
}
if (MANAGER_IS_SYSTEM(m)) {
r = mkdir_label("/run/systemd/units", 0755);
if (r < 0 && r != -EEXIST)
goto fail;
}
/* Note that we do not set up the notify fd here. We do that after deserialization,
* since they might have gotten serialized across the reexec. */
+2
View File
@@ -769,6 +769,8 @@ static int mount_spawn(Mount *m, ExecCommand *c, pid_t *_pid) {
m->reset_accounting = false;
}
unit_export_state_files(UNIT(m));
r = unit_setup_exec_runtime(UNIT(m));
if (r < 0)
return r;
+2
View File
@@ -339,6 +339,8 @@ static int scope_start(Unit *u) {
(void) unit_reset_cpu_accounting(u);
(void) unit_reset_ip_accounting(u);
unit_export_state_files(UNIT(s));
r = unit_attach_pids_to_cgroup(u);
if (r < 0) {
log_unit_warning_errno(UNIT(s), r, "Failed to add PIDs to scope's control group: %m");
+2
View File
@@ -1251,6 +1251,8 @@ static int service_spawn(
s->reset_accounting = false;
}
unit_export_state_files(UNIT(s));
r = unit_setup_exec_runtime(UNIT(s));
if (r < 0)
return r;
+2
View File
@@ -1884,6 +1884,8 @@ static int socket_spawn(Socket *s, ExecCommand *c, pid_t *_pid) {
s->reset_accounting = false;
}
unit_export_state_files(UNIT(s));
r = unit_setup_exec_runtime(UNIT(s));
if (r < 0)
return r;
+2
View File
@@ -619,6 +619,8 @@ static int swap_spawn(Swap *s, ExecCommand *c, pid_t *_pid) {
s->reset_accounting = false;
}
unit_export_state_files(UNIT(s));
r = unit_setup_exec_runtime(UNIT(s));
if (r < 0)
goto fail;
+214 -2
View File
@@ -38,6 +38,7 @@
#include "fd-util.h"
#include "fileio-label.h"
#include "format-util.h"
#include "fs-util.h"
#include "id128-util.h"
#include "io-util.h"
#include "load-dropin.h"
@@ -51,6 +52,7 @@
#include "process-util.h"
#include "set.h"
#include "signal-util.h"
#include "sparse-endian.h"
#include "special.h"
#include "stat-util.h"
#include "stdio-util.h"
@@ -597,6 +599,9 @@ void unit_free(Unit *u) {
unit_release_cgroup(u);
if (!MANAGER_IS_RELOADING(u->manager))
unit_unlink_state_files(u);
unit_unref_uid_gid(u, false);
(void) manager_update_failed_units(u->manager, u, false);
@@ -2296,9 +2301,11 @@ void unit_notify(Unit *u, UnitActiveState os, UnitActiveState ns, bool reload_su
/* Keep track of failed units */
(void) manager_update_failed_units(u->manager, u, ns == UNIT_FAILED);
/* Make sure the cgroup is always removed when we become inactive */
if (UNIT_IS_INACTIVE_OR_FAILED(ns))
/* Make sure the cgroup and state files are always removed when we become inactive */
if (UNIT_IS_INACTIVE_OR_FAILED(ns)) {
unit_prune_cgroup(u);
unit_unlink_state_files(u);
}
/* Note that this doesn't apply to RemainAfterExit services exiting
* successfully, since there's no change of state in that case. Which is
@@ -3102,6 +3109,10 @@ int unit_serialize(Unit *u, FILE *f, FDSet *fds, bool serialize_jobs) {
unit_serialize_item(u, f, "transient", yes_no(u->transient));
unit_serialize_item(u, f, "exported-invocation-id", yes_no(u->exported_invocation_id));
unit_serialize_item(u, f, "exported-log-level-max", yes_no(u->exported_log_level_max));
unit_serialize_item(u, f, "exported-log-extra-fields", yes_no(u->exported_log_extra_fields));
unit_serialize_item_format(u, f, "cpu-usage-base", "%" PRIu64, u->cpu_usage_base);
if (u->cpu_usage_last != NSEC_INFINITY)
unit_serialize_item_format(u, f, "cpu-usage-last", "%" PRIu64, u->cpu_usage_last);
@@ -3342,6 +3353,36 @@ int unit_deserialize(Unit *u, FILE *f, FDSet *fds) {
continue;
} else if (streq(l, "exported-invocation-id")) {
r = parse_boolean(v);
if (r < 0)
log_unit_debug(u, "Failed to parse exported invocation ID bool %s, ignoring.", v);
else
u->exported_invocation_id = r;
continue;
} else if (streq(l, "exported-log-level-max")) {
r = parse_boolean(v);
if (r < 0)
log_unit_debug(u, "Failed to parse exported log level max bool %s, ignoring.", v);
else
u->exported_log_level_max = r;
continue;
} else if (streq(l, "exported-log-extra-fields")) {
r = parse_boolean(v);
if (r < 0)
log_unit_debug(u, "Failed to parse exported log extra fields bool %s, ignoring.", v);
else
u->exported_log_extra_fields = r;
continue;
} else if (STR_IN_SET(l, "cpu-usage-base", "cpuacct-usage-base")) {
r = safe_atou64(v, &u->cpu_usage_base);
@@ -4913,3 +4954,174 @@ void unit_remove_dependencies(Unit *u, UnitDependencyMask mask) {
} while (!done);
}
}
static int unit_export_invocation_id(Unit *u) {
const char *p;
int r;
assert(u);
if (u->exported_invocation_id)
return 0;
if (sd_id128_is_null(u->invocation_id))
return 0;
p = strjoina("/run/systemd/units/invocation:", u->id);
r = symlink_atomic(u->invocation_id_string, p);
if (r < 0)
return log_unit_debug_errno(u, r, "Failed to create invocation ID symlink %s: %m", p);
u->exported_invocation_id = true;
return 0;
}
static int unit_export_log_level_max(Unit *u, const ExecContext *c) {
const char *p;
char buf[2];
int r;
assert(u);
assert(c);
if (u->exported_log_level_max)
return 0;
if (c->log_level_max < 0)
return 0;
assert(c->log_level_max <= 7);
buf[0] = '0' + c->log_level_max;
buf[1] = 0;
p = strjoina("/run/systemd/units/log-level-max:", u->id);
r = symlink_atomic(buf, p);
if (r < 0)
return log_unit_debug_errno(u, r, "Failed to create maximum log level symlink %s: %m", p);
u->exported_log_level_max = true;
return 0;
}
static int unit_export_log_extra_fields(Unit *u, const ExecContext *c) {
_cleanup_close_ int fd = -1;
struct iovec *iovec;
const char *p;
char *pattern;
le64_t *sizes;
ssize_t n;
size_t i;
int r;
if (u->exported_log_extra_fields)
return 0;
if (c->n_log_extra_fields <= 0)
return 0;
sizes = newa(le64_t, c->n_log_extra_fields);
iovec = newa(struct iovec, c->n_log_extra_fields * 2);
for (i = 0; i < c->n_log_extra_fields; i++) {
sizes[i] = htole64(c->log_extra_fields[i].iov_len);
iovec[i*2] = IOVEC_MAKE(sizes + i, sizeof(le64_t));
iovec[i*2+1] = c->log_extra_fields[i];
}
p = strjoina("/run/systemd/units/log-extra-fields:", u->id);
pattern = strjoina(p, ".XXXXXX");
fd = mkostemp_safe(pattern);
if (fd < 0)
return log_unit_debug_errno(u, fd, "Failed to create extra fields file %s: %m", p);
n = writev(fd, iovec, c->n_log_extra_fields*2);
if (n < 0) {
r = log_unit_debug_errno(u, errno, "Failed to write extra fields: %m");
goto fail;
}
(void) fchmod(fd, 0644);
if (rename(pattern, p) < 0) {
r = log_unit_debug_errno(u, errno, "Failed to rename extra fields file: %m");
goto fail;
}
u->exported_log_extra_fields = true;
return 0;
fail:
(void) unlink(pattern);
return r;
}
void unit_export_state_files(Unit *u) {
const ExecContext *c;
assert(u);
if (!u->id)
return;
if (!MANAGER_IS_SYSTEM(u->manager))
return;
/* Exports a couple of unit properties to /run/systemd/units/, so that journald can quickly query this data
* from there. Ideally, journald would use IPC to query this, like everybody else, but that's hard, as long as
* the IPC system itself and PID 1 also log to the journal.
*
* Note that these files really shouldn't be considered API for anyone else, as use a runtime file system as
* IPC replacement is not compatible with today's world of file system namespaces. However, this doesn't really
* apply to communication between the journal and systemd, as we assume that these two daemons live in the same
* namespace at least.
*
* Note that some of the "files" exported here are actually symlinks and not regular files. Symlinks work
* better for storing small bits of data, in particular as we can write them with two system calls, and read
* them with one. */
(void) unit_export_invocation_id(u);
c = unit_get_exec_context(u);
if (c) {
(void) unit_export_log_level_max(u, c);
(void) unit_export_log_extra_fields(u, c);
}
}
void unit_unlink_state_files(Unit *u) {
const char *p;
assert(u);
if (!u->id)
return;
if (!MANAGER_IS_SYSTEM(u->manager))
return;
/* Undoes the effect of unit_export_state() */
if (u->exported_invocation_id) {
p = strjoina("/run/systemd/units/invocation:", u->id);
(void) unlink(p);
u->exported_invocation_id = false;
}
if (u->exported_log_level_max) {
p = strjoina("/run/systemd/units/log-level-max:", u->id);
(void) unlink(p);
u->exported_log_level_max = false;
}
if (u->exported_log_extra_fields) {
p = strjoina("/run/systemd/units/extra-fields:", u->id);
(void) unlink(p);
u->exported_log_extra_fields = false;
}
}
+8
View File
@@ -338,6 +338,11 @@ struct Unit {
/* For transient units: whether to add a bus track reference after creating the unit */
bool bus_track_add:1;
/* Remember which unit state files we created */
bool exported_invocation_id:1;
bool exported_log_level_max:1;
bool exported_log_extra_fields:1;
};
struct UnitStatusMessageFormats {
@@ -742,6 +747,9 @@ int unit_fork_helper_process(Unit *u, pid_t *ret);
void unit_remove_dependencies(Unit *u, UnitDependencyMask mask);
void unit_export_state_files(Unit *u);
void unit_unlink_state_files(Unit *u);
/* Macros which append UNIT= or USER_UNIT= to the message */
#define log_unit_full(unit, level, error, ...) \