From 3ed0cd26ea96e4bcc09846fb76851095c4ec85a8 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 1 Aug 2017 10:16:42 +0200 Subject: [PATCH] execute: replace command flag bools by a flags field This way, we can extend it later on in an easier way, and can pass it along nicely. --- src/core/dbus-execute.c | 2 +- src/core/dbus-service.c | 4 ++-- src/core/execute.c | 6 +++--- src/core/execute.h | 8 ++++++-- src/core/load-fragment.c | 5 +++-- src/core/service.c | 6 +++--- src/core/socket.c | 2 +- src/test/test-unit-file.c | 2 +- 8 files changed, 20 insertions(+), 15 deletions(-) diff --git a/src/core/dbus-execute.c b/src/core/dbus-execute.c index bd4e113..45497ca 100644 --- a/src/core/dbus-execute.c +++ b/src/core/dbus-execute.c @@ -904,7 +904,7 @@ static int append_exec_command(sd_bus_message *reply, ExecCommand *c) { return r; r = sd_bus_message_append(reply, "bttttuii", - c->ignore, + !!(c->flags & EXEC_COMMAND_IGNORE_FAILURE), c->exec_status.start_timestamp.realtime, c->exec_status.start_timestamp.monotonic, c->exec_status.exit_timestamp.realtime, diff --git a/src/core/dbus-service.c b/src/core/dbus-service.c index 0b81d08..05bdc0a 100644 --- a/src/core/dbus-service.c +++ b/src/core/dbus-service.c @@ -280,7 +280,7 @@ static int bus_service_set_transient_property( c->argv = argv; argv = NULL; - c->ignore = b; + c->flags = b ? EXEC_COMMAND_IGNORE_FAILURE : 0; path_kill_slashes(c->path); exec_command_append_list(&s->exec_command[SERVICE_EXEC_START], c); @@ -319,7 +319,7 @@ static int bus_service_set_transient_property( return -ENOMEM; fprintf(f, "ExecStart=%s@%s %s\n", - c->ignore ? "-" : "", + c->flags & EXEC_COMMAND_IGNORE_FAILURE ? "-" : "", c->path, a); } diff --git a/src/core/execute.c b/src/core/execute.c index 55f9aab..b485509 100644 --- a/src/core/execute.c +++ b/src/core/execute.c @@ -2033,7 +2033,7 @@ static int apply_mount_namespace( if (!context->dynamic_user && root_dir) ns_info.ignore_protect_paths = true; - apply_restrictions = (params->flags & EXEC_APPLY_PERMISSIONS) && !command->privileged; + apply_restrictions = (params->flags & EXEC_APPLY_PERMISSIONS) && !(command->flags & EXEC_COMMAND_FULLY_PRIVILEGED); r = setup_namespace(root_dir, root_image, &ns_info, rw, @@ -2647,7 +2647,7 @@ static int exec_child( return r; } - needs_exec_restrictions = (params->flags & EXEC_APPLY_PERMISSIONS) && !command->privileged; + needs_exec_restrictions = (params->flags & EXEC_APPLY_PERMISSIONS) && !(command->flags & EXEC_COMMAND_FULLY_PRIVILEGED); if (needs_exec_restrictions) { if (context->pam_name && username) { @@ -3068,7 +3068,7 @@ int exec_spawn(Unit *unit, error_message), "EXECUTABLE=%s", command->path, NULL); - else if (r == -ENOENT && command->ignore) + else if (r == -ENOENT && (command->flags & EXEC_COMMAND_IGNORE_FAILURE)) log_struct_errno(LOG_INFO, r, "MESSAGE_ID=" SD_MESSAGE_SPAWN_FAILED_STR, LOG_UNIT_ID(unit), diff --git a/src/core/execute.h b/src/core/execute.h index f7fa317..4742f4e 100644 --- a/src/core/execute.h +++ b/src/core/execute.h @@ -88,13 +88,17 @@ struct ExecStatus { int status; /* as in sigingo_t::si_status */ }; +typedef enum ExecCommandFlags { + EXEC_COMMAND_IGNORE_FAILURE = 1, + EXEC_COMMAND_FULLY_PRIVILEGED = 2, +} ExecCommandFlags; + struct ExecCommand { char *path; char **argv; ExecStatus exec_status; + ExecCommandFlags flags; LIST_FIELDS(ExecCommand, command); /* useful for chaining commands */ - bool ignore:1; - bool privileged:1; }; struct ExecRuntime { diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c index d9da1a4..07ad3c5 100644 --- a/src/core/load-fragment.c +++ b/src/core/load-fragment.c @@ -752,8 +752,9 @@ int config_parse_exec( nce->argv = n; nce->path = path; - nce->ignore = ignore; - nce->privileged = privileged; + nce->flags = + (ignore ? EXEC_COMMAND_IGNORE_FAILURE : 0) | + (privileged ? EXEC_COMMAND_FULLY_PRIVILEGED : 0); exec_command_append_list(e, nce); diff --git a/src/core/service.c b/src/core/service.c index e576f4b..4510ac2 100644 --- a/src/core/service.c +++ b/src/core/service.c @@ -2913,7 +2913,7 @@ static void service_sigchld_event(Unit *u, pid_t pid, int code, int status) { s->main_command->exec_status = s->main_exec_status; - if (s->main_command->ignore) + if (s->main_command->flags & EXEC_COMMAND_IGNORE_FAILURE) f = SERVICE_SUCCESS; } else if (s->exec_command[SERVICE_EXEC_START]) { @@ -2921,7 +2921,7 @@ static void service_sigchld_event(Unit *u, pid_t pid, int code, int status) { * ignore the return value if this was * configured for the starter process */ - if (s->exec_command[SERVICE_EXEC_START]->ignore) + if (s->exec_command[SERVICE_EXEC_START]->flags & EXEC_COMMAND_IGNORE_FAILURE) f = SERVICE_SUCCESS; } @@ -3026,7 +3026,7 @@ static void service_sigchld_event(Unit *u, pid_t pid, int code, int status) { if (s->control_command) { exec_status_exit(&s->control_command->exec_status, &s->exec_context, pid, code, status); - if (s->control_command->ignore) + if (s->control_command->flags & EXEC_COMMAND_IGNORE_FAILURE) f = SERVICE_SUCCESS; } diff --git a/src/core/socket.c b/src/core/socket.c index ca59a13..3ab92f7 100644 --- a/src/core/socket.c +++ b/src/core/socket.c @@ -2776,7 +2776,7 @@ static void socket_sigchld_event(Unit *u, pid_t pid, int code, int status) { if (s->control_command) { exec_status_exit(&s->control_command->exec_status, &s->exec_context, pid, code, status); - if (s->control_command->ignore) + if (s->control_command->flags & EXEC_COMMAND_IGNORE_FAILURE) f = SOCKET_SUCCESS; } diff --git a/src/test/test-unit-file.c b/src/test/test-unit-file.c index d0c844d..aa45727 100644 --- a/src/test/test-unit-file.c +++ b/src/test/test-unit-file.c @@ -93,7 +93,7 @@ static void check_execcommand(ExecCommand *c, assert_se(streq_ptr(c->argv[1], argv1)); if (n > 1) assert_se(streq_ptr(c->argv[2], argv2)); - assert_se(c->ignore == ignore); + assert_se(!!(c->flags & EXEC_COMMAND_IGNORE_FAILURE) == ignore); } static void test_config_parse_exec(void) { -- 2.7.4