HALF ECHO LEARN / REFERENCE COLLECTION
v262.2src/core/execute-serialize.c
Git blob: 60cd7a54ab47c2bb6013ca53cb70e53271d9a705
Lines 1001–2000 of 3,790
r = deserialize_read_line(f, &l);
if (r < 0)
return r;
if (r == 0) /* eof or end marker */
break;
if ((val = startswith(l, "exec-runtime-id="))) {
r = free_and_strdup(&rt->shared->id, val);
if (r < 0)
return r;
} else if ((val = startswith(l, "exec-runtime-tmp-dir="))) {
r = free_and_strdup(&rt->shared->tmp_dir, val);
if (r < 0)
return r;
} else if ((val = startswith(l, "exec-runtime-var-tmp-dir="))) {
r = free_and_strdup(&rt->shared->var_tmp_dir, val);
if (r < 0)
return r;
} else if ((val = startswith(l, "exec-runtime-userns-storage-socket="))) {
r = deserialize_fd_many(fds, val, 2, rt->shared->userns_storage_socket);
if (r < 0)
continue;
} else if ((val = startswith(l, "exec-runtime-netns-storage-socket="))) {
r = deserialize_fd_many(fds, val, 2, rt->shared->netns_storage_socket);
if (r < 0)
continue;
} else if ((val = startswith(l, "exec-runtime-ipcns-storage-socket="))) {
r = deserialize_fd_many(fds, val, 2, rt->shared->ipcns_storage_socket);
if (r < 0)
continue;
} else if ((val = startswith(l, "exec-runtime-dynamic-creds-user=")))
dynamic_user_deserialize_one(/* m= */ NULL, val, fds, &rt->dynamic_creds->user);
else if ((val = startswith(l, "exec-runtime-dynamic-creds-group=")))
dynamic_user_deserialize_one(/* m= */ NULL, val, fds, &rt->dynamic_creds->group);
else if ((val = startswith(l, "exec-runtime-dynamic-creds-group-copy="))) {
r = parse_boolean(val);
if (r < 0)
return r;
if (!r)
continue; /* Nothing to do */
if (!rt->dynamic_creds->user)
return -EINVAL;
rt->dynamic_creds->group = dynamic_user_ref(rt->dynamic_creds->user);
} else if ((val = startswith(l, "exec-runtime-ephemeral-copy="))) {
r = free_and_strdup(&rt->ephemeral_copy, val);
if (r < 0)
return r;
} else if ((val = startswith(l, "exec-runtime-ephemeral-storage-socket="))) {
r = deserialize_fd_many(fds, val, 2, rt->ephemeral_storage_socket);
if (r < 0)
continue;
} else
log_warning("Failed to parse serialized line, ignoring: %s", l);
}
return 0;
}
static bool exec_parameters_is_idle_pipe_set(const ExecParameters *p) {
assert(p);
return p->idle_pipe &&
p->idle_pipe[0] >= 0 &&
p->idle_pipe[1] >= 0 &&
p->idle_pipe[2] >= 0 &&
p->idle_pipe[3] >= 0;
}
static int exec_parameters_serialize(const ExecParameters *p, const ExecContext *c, FILE *f, FDSet *fds) {
int r;
assert(f);
assert(fds);
if (!p)
return 0;
r = serialize_item(f, "exec-parameters-runtime-scope", runtime_scope_to_string(p->runtime_scope));
if (r < 0)
return r;
r = serialize_strv(f, "exec-parameters-environment", p->environment);
if (r < 0)
return r;
if (p->fds) {
if (p->n_socket_fds > 0) {
r = serialize_item_format(f, "exec-parameters-n-socket-fds", "%zu", p->n_socket_fds);
if (r < 0)
return r;
}
if (p->n_stashed_fds > 0) {
r = serialize_item_format(f, "exec-parameters-n-stashed-fds", "%zu", p->n_stashed_fds);
if (r < 0)
return r;
}
r = serialize_fd_many(f, fds, "exec-parameters-fds", p->fds, p->n_socket_fds + p->n_stashed_fds);
if (r < 0)
return r;
r = serialize_strv(f, "exec-parameters-fd-names", p->fd_names);
if (r < 0)
return r;
}
if (p->flags != 0) {
r = serialize_item_format(f, "exec-parameters-flags", "%u", (unsigned) p->flags);
if (r < 0)
return r;
}
r = serialize_bool_elide(f, "exec-parameters-selinux-context-net", p->selinux_context_net);
if (r < 0)
return r;
r = serialize_item(f, "exec-parameters-cgroup-path", p->cgroup_path);
if (r < 0)
return r;
r = serialize_item_format(f, "exec-parameters-cgroup-id", "%" PRIu64, p->cgroup_id);
if (r < 0)
return r;
for (ExecDirectoryType dt = 0; dt < _EXEC_DIRECTORY_TYPE_MAX; dt++) {
_cleanup_free_ char *key = NULL;
key = strjoin("exec-parameters-prefix-directories-", exec_directory_type_to_string(dt));
if (!key)
return log_oom_debug();
/* Always serialize, even an empty prefix, as this is a fixed array and we always expect
* to have all elements (unless fuzzing is happening, hence the NULL check). */
r = serialize_item(f, key, strempty(p->prefix ? p->prefix[dt] : NULL));
if (r < 0)
return r;
}
r = serialize_item(f, "exec-parameters-received-credentials-directory", p->received_credentials_directory);
if (r < 0)
return r;
r = serialize_item(f, "exec-parameters-received-encrypted-credentials-directory", p->received_encrypted_credentials_directory);
if (r < 0)
return r;
r = serialize_item(f, "exec-parameters-confirm-spawn", p->confirm_spawn);
if (r < 0)
return r;
r = serialize_bool_elide(f, "exec-parameters-shall-confirm-spawn", p->shall_confirm_spawn);
if (r < 0)
return r;
if (p->watchdog_usec > 0) {
r = serialize_usec(f, "exec-parameters-watchdog-usec", p->watchdog_usec);
if (r < 0)
return r;
}
if (exec_parameters_is_idle_pipe_set(p)) {
r = serialize_fd_many(f, fds, "exec-parameters-idle-pipe", p->idle_pipe, 4);
if (r < 0)
return r;
}
r = serialize_fd(f, fds, "exec-parameters-stdin-fd", p->stdin_fd);
if (r < 0)
return r;
r = serialize_fd(f, fds, "exec-parameters-stdout-fd", p->stdout_fd);
if (r < 0)
return r;
r = serialize_fd(f, fds, "exec-parameters-stderr-fd", p->stderr_fd);
if (r < 0)
return r;
r = serialize_fd(f, fds, "exec-parameters-root-directory-fd", p->root_directory_fd);
if (r < 0)
return r;
r = serialize_fd(f, fds, "exec-parameters-exec-fd", p->exec_fd);
if (r < 0)
return r;
r = serialize_fd(f, fds, "exec-parameters-handoff-timestamp-fd", p->handoff_timestamp_fd);
if (r < 0)
return r;
r = serialize_fd(f, fds, "exec-parameters-pidref-transport-fd", p->pidref_transport_fd);
if (r < 0)
return r;
if (c && exec_context_restrict_filesystems_set(c)) {
r = serialize_fd(f, fds, "exec-parameters-bpf-outer-map-fd", p->bpf_restrict_fs_map_fd);
if (r < 0)
return r;
}
r = serialize_item(f, "exec-parameters-notify-socket", p->notify_socket);
if (r < 0)
return r;
LIST_FOREACH(open_files, file, p->open_files) {
_cleanup_free_ char *ofs = NULL;
r = open_file_to_string(file, &ofs);
if (r < 0)
return r;
r = serialize_item(f, "exec-parameters-open-file", ofs);
if (r < 0)
return r;
}
r = serialize_item(f, "exec-parameters-fallback-smack-process-label", p->fallback_smack_process_label);
if (r < 0)
return r;
r = serialize_fd(f, fds, "exec-parameters-user-lookup-fd", p->user_lookup_fd);
if (r < 0)
return r;
r = serialize_strv(f, "exec-parameters-files-env", p->files_env);
if (r < 0)
return r;
r = serialize_item(f, "exec-parameters-unit-id", p->unit_id);
if (r < 0)
return r;
r = serialize_item(f, "exec-parameters-invocation-id-string", p->invocation_id_string);
if (r < 0)
return r;
r = serialize_bool_elide(f, "exec-parameters-debug-invocation", p->debug_invocation);
if (r < 0)
return r;
fputc('\n', f); /* End marker */
return 0;
}
static int exec_parameters_deserialize(ExecParameters *p, FILE *f, FDSet *fds) {
int r;
assert(p);
assert(f);
assert(fds);
unsigned nr_open = MAX(read_nr_open(), NR_OPEN_MINIMUM);
for (;;) {
_cleanup_free_ char *l = NULL;
const char *val;
r = deserialize_read_line(f, &l);
if (r < 0)
return r;
if (r == 0) /* eof or end marker */
break;
if ((val = startswith(l, "exec-parameters-runtime-scope="))) {
p->runtime_scope = runtime_scope_from_string(val);
if (p->runtime_scope < 0)
return p->runtime_scope;
} else if ((val = startswith(l, "exec-parameters-environment="))) {
r = deserialize_strv(val, &p->environment);
if (r < 0)
return r;
} else if ((val = startswith(l, "exec-parameters-n-socket-fds="))) {
if (p->fds)
return -EINVAL; /* Already received */
r = safe_atozu(val, &p->n_socket_fds);
if (r < 0)
return r;
if (p->n_socket_fds > nr_open)
return -EINVAL; /* too many, someone is playing games with us */
} else if ((val = startswith(l, "exec-parameters-n-stashed-fds="))) {
if (p->fds)
return -EINVAL; /* Already received */
r = safe_atozu(val, &p->n_stashed_fds);
if (r < 0)
return r;
if (p->n_stashed_fds > nr_open)
return -EINVAL; /* too many, someone is playing games with us */
} else if ((val = startswith(l, "exec-parameters-fds="))) {
if (p->n_socket_fds + p->n_stashed_fds == 0)
return log_warning_errno(
SYNTHETIC_ERRNO(EINVAL),
"Got exec-parameters-fds= without "
"prior exec-parameters-n-socket-fds= or exec-parameters-n-stashed-fds=");
if (p->n_socket_fds + p->n_stashed_fds > nr_open)
return -EINVAL; /* too many, someone is playing games with us */
if (p->fds)
return -EINVAL; /* duplicated */
p->fds = new(int, p->n_socket_fds + p->n_stashed_fds);
if (!p->fds)
return log_oom_debug();
/* Ensure we don't leave any FD uninitialized on error, it makes the fuzzer sad */
FOREACH_ARRAY(i, p->fds, p->n_socket_fds + p->n_stashed_fds)
*i = -EBADF;
r = deserialize_fd_many(fds, val, p->n_socket_fds + p->n_stashed_fds, p->fds);
if (r < 0)
continue;
} else if ((val = startswith(l, "exec-parameters-fd-names="))) {
r = deserialize_strv(val, &p->fd_names);
if (r < 0)
return r;
} else if ((val = startswith(l, "exec-parameters-flags="))) {
unsigned flags;
r = safe_atou(val, &flags);
if (r < 0)
return r;
p->flags = flags;
} else if ((val = startswith(l, "exec-parameters-selinux-context-net="))) {
r = parse_boolean(val);
if (r < 0)
return r;
p->selinux_context_net = r;
} else if ((val = startswith(l, "exec-parameters-cgroup-path="))) {
r = free_and_strdup(&p->cgroup_path, val);
if (r < 0)
return r;
} else if ((val = startswith(l, "exec-parameters-cgroup-id="))) {
r = safe_atou64(val, &p->cgroup_id);
if (r < 0)
return r;
} else if ((val = startswith(l, "exec-parameters-prefix-directories-"))) {
_cleanup_free_ char *type = NULL, *prefix = NULL;
ExecDirectoryType dt;
r = extract_many_words(&val, "= ", 0, &type, &prefix);
if (r < 0)
return r;
if (r == 0)
return -EINVAL;
dt = exec_directory_type_from_string(type);
if (dt < 0)
return -EINVAL;
if (!p->prefix) {
p->prefix = new0(char*, _EXEC_DIRECTORY_TYPE_MAX+1);
if (!p->prefix)
return log_oom_debug();
}
if (isempty(prefix))
p->prefix[dt] = mfree(p->prefix[dt]);
else
free_and_replace(p->prefix[dt], prefix);
} else if ((val = startswith(l, "exec-parameters-received-credentials-directory="))) {
r = free_and_strdup(&p->received_credentials_directory, val);
if (r < 0)
return r;
} else if ((val = startswith(l, "exec-parameters-received-encrypted-credentials-directory="))) {
r = free_and_strdup(&p->received_encrypted_credentials_directory, val);
if (r < 0)
return r;
} else if ((val = startswith(l, "exec-parameters-confirm-spawn="))) {
r = free_and_strdup(&p->confirm_spawn, val);
if (r < 0)
return r;
} else if ((val = startswith(l, "exec-parameters-shall-confirm-spawn="))) {
r = parse_boolean(val);
if (r < 0)
return r;
p->shall_confirm_spawn = r;
} else if ((val = startswith(l, "exec-parameters-watchdog-usec="))) {
r = deserialize_usec(val, &p->watchdog_usec);
if (r < 0)
return r;
} else if ((val = startswith(l, "exec-parameters-idle-pipe="))) {
if (p->idle_pipe)
return -EINVAL; /* duplicated */
p->idle_pipe = new(int, 4);
if (!p->idle_pipe)
return log_oom_debug();
p->idle_pipe[0] = p->idle_pipe[1] = p->idle_pipe[2] = p->idle_pipe[3] = -EBADF;
r = deserialize_fd_many(fds, val, 4, p->idle_pipe);
if (r < 0)
continue;
} else if ((val = startswith(l, "exec-parameters-stdin-fd="))) {
int fd;
fd = deserialize_fd(fds, val);
if (fd < 0)
continue;
close_and_replace(p->stdin_fd, fd);
} else if ((val = startswith(l, "exec-parameters-stdout-fd="))) {
int fd;
fd = deserialize_fd(fds, val);
if (fd < 0)
continue;
close_and_replace(p->stdout_fd, fd);
} else if ((val = startswith(l, "exec-parameters-stderr-fd="))) {
int fd;
fd = deserialize_fd(fds, val);
if (fd < 0)
continue;
close_and_replace(p->stderr_fd, fd);
} else if ((val = startswith(l, "exec-parameters-root-directory-fd="))) {
int fd;
fd = deserialize_fd(fds, val);
if (fd < 0)
continue;
close_and_replace(p->root_directory_fd, fd);
} else if ((val = startswith(l, "exec-parameters-exec-fd="))) {
int fd;
fd = deserialize_fd(fds, val);
if (fd < 0)
continue;
close_and_replace(p->exec_fd, fd);
} else if ((val = startswith(l, "exec-parameters-handoff-timestamp-fd="))) {
int fd;
fd = deserialize_fd(fds, val);
if (fd < 0)
continue;
close_and_replace(p->handoff_timestamp_fd, fd);
} else if ((val = startswith(l, "exec-parameters-pidref-transport-fd="))) {
int fd;
fd = deserialize_fd(fds, val);
if (fd < 0)
continue;
close_and_replace(p->pidref_transport_fd, fd);
} else if ((val = startswith(l, "exec-parameters-bpf-outer-map-fd="))) {
int fd;
fd = deserialize_fd(fds, val);
if (fd < 0)
continue;
close_and_replace(p->bpf_restrict_fs_map_fd, fd);
} else if ((val = startswith(l, "exec-parameters-notify-socket="))) {
r = free_and_strdup(&p->notify_socket, val);
if (r < 0)
return r;
} else if ((val = startswith(l, "exec-parameters-open-file="))) {
OpenFile *of;
r = open_file_parse(val, &of);
if (r < 0)
return r;
LIST_APPEND(open_files, p->open_files, of);
} else if ((val = startswith(l, "exec-parameters-fallback-smack-process-label="))) {
r = free_and_strdup(&p->fallback_smack_process_label, val);
if (r < 0)
return r;
} else if ((val = startswith(l, "exec-parameters-user-lookup-fd="))) {
int fd;
fd = deserialize_fd(fds, val);
if (fd < 0)
continue;
close_and_replace(p->user_lookup_fd, fd);
} else if ((val = startswith(l, "exec-parameters-files-env="))) {
r = deserialize_strv(val, &p->files_env);
if (r < 0)
return r;
} else if ((val = startswith(l, "exec-parameters-unit-id="))) {
r = free_and_strdup(&p->unit_id, val);
if (r < 0)
return r;
} else if ((val = startswith(l, "exec-parameters-invocation-id-string="))) {
if (strlen(val) > SD_ID128_STRING_MAX - 1)
return -EINVAL;
r = sd_id128_from_string(val, &p->invocation_id);
if (r < 0)
return r;
sd_id128_to_string(p->invocation_id, p->invocation_id_string);
} else if ((val = startswith(l, "exec-parameters-debug-invocation="))) {
r = parse_boolean(val);
if (r < 0)
return r;
p->debug_invocation = r;
} else
log_warning("Failed to parse serialized line, ignoring: %s", l);
}
/* Bail out if we got exec-parameters-n-{socket/stashed}-fds= but no corresponding
* exec-parameters-fds= */
if (p->n_socket_fds + p->n_stashed_fds > 0 && !p->fds)
return -EINVAL;
return 0;
}
static int serialize_mount_options(const MountOptions *mount_options, char **s) {
assert(s);
if (!mount_options)
return 0;
for (PartitionDesignator i = 0; i < _PARTITION_DESIGNATOR_MAX; i++) {
_cleanup_free_ char *escaped = NULL;
if (isempty(mount_options->options[i]))
continue;
escaped = shell_escape(mount_options->options[i], ":");
if (!escaped)
return log_oom_debug();
if (!strextend(s,
" ",
partition_designator_to_string(i),
":",
escaped))
return log_oom_debug();
}
return 0;
}
static int deserialize_mount_options(const char *s, MountOptions **ret_mount_options) {
_cleanup_(mount_options_free_allp) MountOptions *options = NULL;
int r;
assert(ret_mount_options);
for (;;) {
_cleanup_free_ char *word = NULL, *mount_options = NULL, *partition = NULL;
PartitionDesignator partition_designator;
const char *p;
r = extract_first_word(&s, &word, NULL, 0);
if (r < 0)
return r;
if (r == 0)
break;
p = word;
r = extract_many_words(&p, ":", EXTRACT_CUNESCAPE|EXTRACT_UNESCAPE_SEPARATORS, &partition, &mount_options);
if (r < 0)
return r;
if (r == 0)
continue;
if (r != 2) {
log_warning("Failed to parse mount options entry '%s', ignoring.", word);
continue;
}
partition_designator = partition_designator_from_string(partition);
if (partition_designator < 0) {
log_warning_errno(partition_designator, "Unknown partition designator '%s' in exec-context-root-image-options= entry, ignoring.", partition);
continue;
}
r = mount_options_set_and_consume(&options, partition_designator, TAKE_PTR(mount_options));
if (r < 0)
return r;
}
*ret_mount_options = TAKE_PTR(options);
return 0;
}
static int exec_context_serialize(const ExecContext *c, FILE *f) {
int r;
assert(f);
if (!c)
return 0;
r = serialize_strv(f, "exec-context-environment", c->environment);
if (r < 0)
return r;
r = serialize_strv(f, "exec-context-environment-files", c->environment_files);
if (r < 0)
return r;
r = serialize_strv(f, "exec-context-pass-environment", c->pass_environment);
if (r < 0)
return r;
r = serialize_strv(f, "exec-context-unset-environment", c->unset_environment);
if (r < 0)
return r;
r = serialize_item_escaped(f, "exec-context-working-directory", c->working_directory);
if (r < 0)
return r;
r = serialize_bool_elide(f, "exec-context-working-directory-missing-ok", c->working_directory_missing_ok);
if (r < 0)
return r;
r = serialize_bool_elide(f, "exec-context-working-directory-home", c->working_directory_home);
if (r < 0)
return r;
r = serialize_item_escaped(f, "exec-context-root-directory", c->root_directory);
if (r < 0)
return r;
r = serialize_item_escaped(f, "exec-context-root-image", c->root_image);
if (r < 0)
return r;
if (c->root_image_options) {
_cleanup_free_ char *options = NULL;
r = serialize_mount_options(c->root_image_options, &options);
if (r < 0)
return r;
r = serialize_item(f, "exec-context-root-image-options", options);
if (r < 0)
return r;
}
r = serialize_item(f, "exec-context-root-verity", c->root_verity);
if (r < 0)
return r;
r = serialize_item(f, "exec-context-root-hash-path", c->root_hash_path);
if (r < 0)
return r;
r = serialize_item(f, "exec-context-root-hash-sig-path", c->root_hash_sig_path);
if (r < 0)
return r;
r = serialize_item_hexmem(f, "exec-context-root-hash", c->root_hash.iov_base, c->root_hash.iov_len);
if (r < 0)
return r;
r = serialize_item_base64mem(f, "exec-context-root-hash-sig", c->root_hash_sig.iov_base, c->root_hash_sig.iov_len);
if (r < 0)
return r;
r = serialize_bool_elide(f, "exec-context-root-ephemeral", c->root_ephemeral);
if (r < 0)
return r;
r = serialize_item_escaped(f, "exec-context-root-mstack", c->root_mstack);
if (r < 0)
return r;
r = serialize_item_format(f, "exec-context-umask", "%04o", c->umask);
if (r < 0)
return r;
r = serialize_bool_elide(f, "exec-context-non-blocking", c->non_blocking);
if (r < 0)
return r;
r = serialize_item_tristate(f, "exec-context-private-mounts", c->private_mounts);
if (r < 0)
return r;
r = serialize_item_tristate(f, "exec-context-mount-api-vfs", c->mount_apivfs);
if (r < 0)
return r;
r = serialize_item_tristate(f, "exec-context-bind-log-sockets", c->bind_log_sockets);
if (r < 0)
return r;
r = serialize_item_tristate(f, "exec-context-memory-ksm", c->memory_ksm);
if (r < 0)
return r;
r = serialize_item(f, "exec-context-memory-thp", exec_memory_thp_to_string(c->memory_thp));
if (r < 0)
return r;
r = serialize_item(f, "exec-context-private-tmp", private_tmp_to_string(c->private_tmp));
if (r < 0)
return r;
/* This must be set in unit_patch_contexts() before executing a command. A unit whose load failed
* never goes through that, yet can still be stopped, hence this is reachable. Refuse instead of
* asserting, this runs in PID 1. */
if (c->private_var_tmp < 0 || c->private_var_tmp >= _PRIVATE_TMP_MAX)
return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
"PrivateVarTmp= is not set up, unit was not fully loaded, refusing.");
r = serialize_item(f, "exec-context-private-var-tmp", private_tmp_to_string(c->private_var_tmp));
if (r < 0)
return r;
r = serialize_bool_elide(f, "exec-context-private-devices", c->private_devices);
if (r < 0)
return r;
r = serialize_bool_elide(f, "exec-context-protect-kernel-tunables", c->protect_kernel_tunables);
if (r < 0)
return r;
r = serialize_bool_elide(f, "exec-context-protect-kernel-modules", c->protect_kernel_modules);
if (r < 0)
return r;
r = serialize_bool_elide(f, "exec-context-protect-kernel-logs", c->protect_kernel_logs);
if (r < 0)
return r;
r = serialize_bool_elide(f, "exec-context-protect-clock", c->protect_clock);
if (r < 0)
return r;
r = serialize_item(f, "exec-context-protect-control-groups", protect_control_groups_to_string(c->protect_control_groups));
if (r < 0)
return r;
r = serialize_bool_elide(f, "exec-context-private-network", c->private_network);
if (r < 0)
return r;
r = serialize_item(f, "exec-context-private-users", private_users_to_string(c->private_users));
if (r < 0)
return r;
r = serialize_bool_elide(f, "exec-context-private-ipc", c->private_ipc);
if (r < 0)
return r;
r = serialize_item(f, "exec-context-private-pids", private_pids_to_string(c->private_pids));
if (r < 0)
return r;
r = serialize_bool_elide(f, "exec-context-remove-ipc", c->remove_ipc);
if (r < 0)
return r;
r = serialize_item(f, "exec-context-protect-home", protect_home_to_string(c->protect_home));
if (r < 0)
return r;
r = serialize_item(f, "exec-context-protect-system", protect_system_to_string(c->protect_system));
if (r < 0)
return r;
r = serialize_bool_elide(f, "exec-context-same-pgrp", c->same_pgrp);
if (r < 0)
return r;
r = serialize_bool(f, "exec-context-ignore-sigpipe", c->ignore_sigpipe);
if (r < 0)
return r;
r = serialize_bool_elide(f, "exec-context-memory-deny-write-execute", c->memory_deny_write_execute);
if (r < 0)
return r;
r = serialize_bool_elide(f, "exec-context-restrict-realtime", c->restrict_realtime);
if (r < 0)
return r;
r = serialize_bool_elide(f, "exec-context-restrict-suid-sgid", c->restrict_suid_sgid);
if (r < 0)
return r;
r = serialize_item(f, "exec-context-keyring-mode", exec_keyring_mode_to_string(c->keyring_mode));
if (r < 0)
return r;
r = serialize_item(f, "exec-context-protect-hostname", protect_hostname_to_string(c->protect_hostname));
if (r < 0)
return r;
r = serialize_item(f, "exec-context-private-hostname", c->private_hostname);
if (r < 0)
return r;
r = serialize_item(f, "exec-context-protect-proc", protect_proc_to_string(c->protect_proc));
if (r < 0)
return r;
r = serialize_item(f, "exec-context-proc-subset", proc_subset_to_string(c->proc_subset));
if (r < 0)
return r;
r = serialize_item(f, "exec-context-private-bpf", private_bpf_to_string(c->private_bpf));
if (r < 0)
return r;
if (c->bpf_delegate_commands != 0) {
r = serialize_item_format(f, "exec-context-bpf-delegate-commands", "0x%"PRIx64, c->bpf_delegate_commands);
if (r < 0)
return r;
}
if (c->bpf_delegate_maps != 0) {
r = serialize_item_format(f, "exec-context-bpf-delegate-maps", "0x%"PRIx64, c->bpf_delegate_maps);
if (r < 0)
return r;
}
if (c->bpf_delegate_programs != 0) {
r = serialize_item_format(f, "exec-context-bpf-delegate-programs", "0x%"PRIx64, c->bpf_delegate_programs);
if (r < 0)
return r;
}
if (c->bpf_delegate_attachments != 0) {
r = serialize_item_format(f, "exec-context-bpf-delegate-attachments", "0x%"PRIx64, c->bpf_delegate_attachments);
if (r < 0)
return r;
}
r = serialize_item(f, "exec-context-runtime-directory-preserve-mode", exec_preserve_mode_to_string(c->runtime_directory_preserve_mode));
if (r < 0)
return r;
for (ExecDirectoryType dt = 0; dt < _EXEC_DIRECTORY_TYPE_MAX; dt++) {
_cleanup_free_ char *key = NULL, *value = NULL;
key = strjoin("exec-context-directories-", exec_directory_type_to_string(dt));
if (!key)
return log_oom_debug();
if (asprintf(&value, "%04o", c->directories[dt].mode) < 0)
return log_oom_debug();
FOREACH_ARRAY(i, c->directories[dt].items, c->directories[dt].n_items) {
_cleanup_free_ char *path_escaped = NULL;
path_escaped = xescape(i->path, ":\"");
if (!path_escaped)
return log_oom_debug();
if (!strextend(&value, " \"", path_escaped))
return log_oom_debug();
if (!strextend(&value, ":", yes_no(FLAGS_SET(i->flags, EXEC_DIRECTORY_ONLY_CREATE))))
return log_oom_debug();
if (!strextend(&value, ":", yes_no(FLAGS_SET(i->flags, EXEC_DIRECTORY_READ_ONLY))))
return log_oom_debug();
STRV_FOREACH(d, i->symlinks) {
_cleanup_free_ char *link_escaped = NULL;
link_escaped = xescape(*d, ":\"");
if (!link_escaped)
return log_oom_debug();
if (!strextend(&value, ":", link_escaped))
return log_oom_debug();
}
if (!strextend(&value, "\""))
return log_oom_debug();
}
r = serialize_item(f, key, value);
if (r < 0)
return r;
if (c->directories[dt].exec_quota.quota_enforce) {
_cleanup_free_ char *key_quota = NULL;
key_quota = strjoin("exec-context-quota-directories-", exec_directory_type_to_string(dt));
if (!key_quota)
return log_oom_debug();
r = serialize_item_format(f, key_quota, "%" PRIu64 " %" PRIu32, c->directories[dt].exec_quota.quota_absolute,
c->directories[dt].exec_quota.quota_scale);
if (r < 0)
return r;
} else if (c->directories[dt].exec_quota.quota_accounting) {
_cleanup_free_ char *key_quota = NULL;
key_quota = strjoin("exec-context-quota-accounting-directories-", exec_directory_type_to_string(dt));
if (!key_quota)
return log_oom_debug();
r = serialize_bool(f, key_quota, c->directories[dt].exec_quota.quota_accounting);
if (r < 0)
return r;
}
}
r = serialize_usec(f, "exec-context-timeout-clean-usec", c->timeout_clean_usec);
if (r < 0)
return r;
if (c->nice_set) {
r = serialize_item_format(f, "exec-context-nice", "%i", c->nice);
if (r < 0)
return r;
}
if (c->oom_score_adjust_set) {
r = serialize_item_format(f, "exec-context-oom-score-adjust", "%i", c->oom_score_adjust);
if (r < 0)
return r;
}
if (c->coredump_filter_set) {
r = serialize_item_format(f, "exec-context-coredump-filter", "%"PRIx64, c->coredump_filter);
if (r < 0)
return r;
}
for (unsigned i = 0; i < RLIM_NLIMITS; i++) {
_cleanup_free_ char *key = NULL, *limit = NULL;
if (!c->rlimit[i])
continue;
key = strjoin("exec-context-limit-", rlimit_to_string(i));
if (!key)
return log_oom_debug();
r = rlimit_format(c->rlimit[i], &limit);
if (r < 0)
return r;
r = serialize_item(f, key, limit);
if (r < 0)
return r;
}
if (c->ioprio_is_set) {
r = serialize_item_format(f, "exec-context-ioprio", "%d", c->ioprio);
if (r < 0)
return r;
}
if (c->cpu_sched_set) {
_cleanup_free_ char *policy_str = NULL;
r = sched_policy_to_string_alloc(c->cpu_sched_policy, &policy_str);
if (r < 0)
return r;
r = serialize_item(f, "exec-context-cpu-scheduling-policy", policy_str);
if (r < 0)
return r;
r = serialize_item_format(f, "exec-context-cpu-scheduling-priority", "%i", c->cpu_sched_priority);
if (r < 0)
return r;
r = serialize_bool_elide(f, "exec-context-cpu-scheduling-reset-on-fork", c->cpu_sched_reset_on_fork);
if (r < 0)
return r;
}
if (c->cpu_set.set) {
_cleanup_free_ char *affinity = NULL;
affinity = cpu_set_to_range_string(&c->cpu_set);