Skip to content

Commit

Permalink
core/execute: switch mount_apivfs to tristate
Browse files Browse the repository at this point in the history
No functional change, just refactoring.
  • Loading branch information
YHNdnzj committed Apr 25, 2024
1 parent 4dffcad commit c920712
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 69 deletions.
17 changes: 3 additions & 14 deletions src/core/dbus-execute.c
Original file line number Diff line number Diff line change
Expand Up @@ -1746,6 +1746,9 @@ int bus_exec_context_set_transient_property(
if (streq(name, "PrivateMounts"))
return bus_set_transient_tristate(u, name, &c->private_mounts, message, flags, error);

if (streq(name, "MountAPIVFS"))
return bus_set_transient_tristate(u, name, &c->mount_apivfs, message, flags, error);

if (streq(name, "BindJournalSockets"))
return bus_set_transient_tristate(u, name, &c->bind_journal_sockets, message, flags, error);

Expand Down Expand Up @@ -2716,20 +2719,6 @@ int bus_exec_context_set_transient_property(

return 1;

} else if (streq(name, "MountAPIVFS")) {
bool b;

r = bus_set_transient_bool(u, name, &b, message, flags, error);
if (r < 0)
return r;

if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
c->mount_apivfs = b;
c->mount_apivfs_set = true;
}

return 1;

} else if (streq(name, "WorkingDirectory")) {
_cleanup_free_ char *simplified = NULL;
bool missing_ok, is_home;
Expand Down
2 changes: 1 addition & 1 deletion src/core/exec-invoke.c
Original file line number Diff line number Diff line change
Expand Up @@ -3862,7 +3862,7 @@ static bool exec_context_need_unprivileged_private_users(
context->private_ipc ||
context->ipc_namespace_path ||
context->private_mounts > 0 ||
context->mount_apivfs ||
context->mount_apivfs > 0 ||
context->bind_journal_sockets > 0 ||
context->n_bind_mounts > 0 ||
context->n_temporary_filesystems > 0 ||
Expand Down
20 changes: 8 additions & 12 deletions src/core/execute-serialize.c
Original file line number Diff line number Diff line change
Expand Up @@ -1832,6 +1832,10 @@ static int exec_context_serialize(const ExecContext *c, FILE *f) {
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-journal-sockets", c->bind_journal_sockets);
if (r < 0)
return r;
Expand Down Expand Up @@ -1892,12 +1896,6 @@ static int exec_context_serialize(const ExecContext *c, FILE *f) {
if (r < 0)
return r;

if (c->mount_apivfs_set) {
r = serialize_bool(f, "exec-context-mount-api-vfs", c->mount_apivfs);
if (r < 0)
return r;
}

r = serialize_bool_elide(f, "exec-context-same-pgrp", c->same_pgrp);
if (r < 0)
return r;
Expand Down Expand Up @@ -2717,6 +2715,10 @@ static int exec_context_deserialize(ExecContext *c, FILE *f) {
r = safe_atoi(val, &c->private_mounts);
if (r < 0)
return r;
} else if ((val = startswith(l, "exec-context-mount-api-vfs="))) {
r = safe_atoi(val, &c->mount_apivfs);
if (r < 0)
return r;
} else if ((val = startswith(l, "exec-context-bind-journal-sockets="))) {
r = safe_atoi(val, &c->bind_journal_sockets);
if (r < 0)
Expand Down Expand Up @@ -2788,12 +2790,6 @@ static int exec_context_deserialize(ExecContext *c, FILE *f) {
c->protect_system = protect_system_from_string(val);
if (c->protect_system < 0)
return -EINVAL;
} else if ((val = startswith(l, "exec-context-mount-api-vfs="))) {
r = parse_boolean(val);
if (r < 0)
return r;
c->mount_apivfs = r;
c->mount_apivfs_set = true;
} else if ((val = startswith(l, "exec-context-same-pgrp="))) {
r = parse_boolean(val);
if (r < 0)
Expand Down
5 changes: 3 additions & 2 deletions src/core/execute.c
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,7 @@ void exec_context_init(ExecContext *c) {
.tty_rows = UINT_MAX,
.tty_cols = UINT_MAX,
.private_mounts = -1,
.mount_apivfs = -1,
.bind_journal_sockets = -1,
.memory_ksm = -1,
.set_login_environment = -1,
Expand Down Expand Up @@ -1443,8 +1444,8 @@ bool exec_context_get_effective_mount_apivfs(const ExecContext *c) {
assert(c);

/* Explicit setting wins */
if (c->mount_apivfs_set)
return c->mount_apivfs;
if (c->mount_apivfs >= 0)
return c->mount_apivfs > 0;

/* Default to "yes" if root directory or image are specified */
if (exec_context_with_rootfs(c))
Expand Down
3 changes: 1 addition & 2 deletions src/core/execute.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,6 @@ struct ExecContext {
bool nice_set:1;
bool ioprio_set:1;
bool cpu_sched_set:1;
bool mount_apivfs_set:1;

/* This is not exposed to the user but available internally. We need it to make sure that whenever we
* spawn /usr/bin/mount it is run in the same process group as us so that the autofs logic detects
Expand Down Expand Up @@ -313,6 +312,7 @@ struct ExecContext {
ProcSubset proc_subset; /* subset= */

int private_mounts;
int mount_apivfs;
int bind_journal_sockets;
int memory_ksm;
bool private_tmp;
Expand All @@ -328,7 +328,6 @@ struct ExecContext {
ProtectSystem protect_system;
ProtectHome protect_home;
bool protect_hostname;
bool mount_apivfs;

bool dynamic_user;
bool remove_ipc;
Expand Down
2 changes: 1 addition & 1 deletion src/core/load-fragment-gperf.gperf.in
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@
{{type}}.ProtectSystem, config_parse_protect_system, 0, offsetof({{type}}, exec_context.protect_system)
{{type}}.ProtectHome, config_parse_protect_home, 0, offsetof({{type}}, exec_context.protect_home)
{{type}}.MountFlags, config_parse_exec_mount_propagation_flag, 0, offsetof({{type}}, exec_context.mount_propagation_flag)
{{type}}.MountAPIVFS, config_parse_exec_mount_apivfs, 0, offsetof({{type}}, exec_context)
{{type}}.MountAPIVFS, config_parse_tristate, 0, offsetof({{type}}, exec_context.mount_apivfs)
{{type}}.BindJournalSockets, config_parse_tristate, 0, offsetof({{type}}, exec_context.bind_journal_sockets)
{{type}}.Personality, config_parse_personality, 0, offsetof({{type}}, exec_context.personality)
{{type}}.RuntimeDirectoryPreserve, config_parse_exec_preserve_mode, 0, offsetof({{type}}, exec_context.runtime_directory_preserve_mode)
Expand Down
37 changes: 0 additions & 37 deletions src/core/load-fragment.c
Original file line number Diff line number Diff line change
Expand Up @@ -1496,43 +1496,6 @@ int config_parse_exec_cpu_sched_policy(const char *unit,
return 0;
}

int config_parse_exec_mount_apivfs(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 = ASSERT_PTR(data);
int k;

assert(filename);
assert(lvalue);
assert(rvalue);

if (isempty(rvalue)) {
c->mount_apivfs_set = false;
c->mount_apivfs = false;
return 0;
}

k = parse_boolean(rvalue);
if (k < 0) {
log_syntax(unit, LOG_WARNING, filename, line, k,
"Failed to parse boolean value, ignoring: %s",
rvalue);
return 0;
}

c->mount_apivfs_set = true;
c->mount_apivfs = k;
return 0;
}

int config_parse_numa_mask(const char *unit,
const char *filename,
unsigned line,
Expand Down

0 comments on commit c920712

Please sign in to comment.