1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2025-01-12 09:17:44 +03:00

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.
This commit is contained in:
Lennart Poettering 2017-08-01 10:16:42 +02:00
parent 2935311ca4
commit 3ed0cd26ea
8 changed files with 20 additions and 15 deletions

View File

@ -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,

View File

@ -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);
}

View File

@ -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),

View File

@ -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 {

View File

@ -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);

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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) {