]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
execute: replace command flag bools by a flags field
authorLennart Poettering <lennart@poettering.net>
Tue, 1 Aug 2017 08:16:42 +0000 (10:16 +0200)
committerLennart Poettering <lennart@poettering.net>
Thu, 10 Aug 2017 12:44:58 +0000 (14:44 +0200)
This way, we can extend it later on in an easier way, and can pass it
along nicely.

src/core/dbus-execute.c
src/core/dbus-service.c
src/core/execute.c
src/core/execute.h
src/core/load-fragment.c
src/core/service.c
src/core/socket.c
src/test/test-unit-file.c

index bd4e113bec3398ea11e91a5a19d6d63289af278c..45497ca024d65f22e0e421bd6023fb8a278b2343 100644 (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,
index 0b81d085fe5fe838730d416e1809952e39f9ca63..05bdc0a74855b43d44721f739ab915b62591fb90 100644 (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);
                         }
index 55f9aab4b289c18bf8d102bc1dde893eaa152090..b485509bdf50eadf76ce3c723bca59ac3788fced 100644 (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),
index f7fa3176b13b50019d2c8ec420d403237fdfa38d..4742f4e6c1ce57c72d0f0ec4dad5037dc5f83b62 100644 (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 {
index d9da1a422e1227a3a7ad3ddf01d0677d36b41632..07ad3c5def8287d1f1d759618d696563b42e5488 100644 (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);
 
index e576f4ba83c877da9f6d235ab128eedfe617032d..4510ac2423fdf54b60d1576c4c67c46a005a5690 100644 (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;
                 }
 
index ca59a13b66315fbdf65e30f126263b8a032d634c..3ab92f72c3faa29cfe445bcf9ce87dfd8bc33773 100644 (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;
         }
 
index d0c844dddb3997900b10bf7a24b5a9e96bfdfefc..aa457279863f2e3f64d20a2c19cd41db57822927 100644 (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) {