]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
execute: cleanup use of ERRNO_IS_PRIVILEGE()
authorDmitry V. Levin <ldv@strace.io>
Fri, 14 Jul 2023 08:00:00 +0000 (08:00 +0000)
committerDmitry V. Levin <ldv@strace.io>
Fri, 28 Jul 2023 12:28:35 +0000 (12:28 +0000)
Given that ERRNO_IS_PRIVILEGE() also matches positive values,
make sure this macro is not called with arguments that do not have
errno semantics.

In this case the arguments passed to ERRNO_IS_PRIVILEGE() are the values
returned by set_oom_score_adjust() and set_coredump_filter() which are
not expected to return any positive values, but let's be consistent
anyway and move the ERRNO_IS_PRIVILEGE() invocations to the branches
where the return values are known to be negative.

src/core/execute.c

index 9dafdffa08f407f41a1262713cb9a7ca49957e5c..07913e658b390c3182af917d11fe854342f478dd 100644 (file)
@@ -5098,20 +5098,24 @@ static int exec_child(
                 /* When we can't make this change due to EPERM, then let's silently skip over it. User namespaces
                  * prohibit write access to this file, and we shouldn't trip up over that. */
                 r = set_oom_score_adjust(context->oom_score_adjust);
-                if (ERRNO_IS_PRIVILEGE(r))
-                        log_unit_debug_errno(unit, r, "Failed to adjust OOM setting, assuming containerized execution, ignoring: %m");
-                else if (r < 0) {
-                        *exit_status = EXIT_OOM_ADJUST;
-                        return log_unit_error_errno(unit, r, "Failed to adjust OOM setting: %m");
+                if (r < 0) {
+                        if (ERRNO_IS_PRIVILEGE(r))
+                                log_unit_debug_errno(unit, r, "Failed to adjust OOM setting, assuming containerized execution, ignoring: %m");
+                        else {
+                                *exit_status = EXIT_OOM_ADJUST;
+                                return log_unit_error_errno(unit, r, "Failed to adjust OOM setting: %m");
+                        }
                 }
         }
 
         if (context->coredump_filter_set) {
                 r = set_coredump_filter(context->coredump_filter);
-                if (ERRNO_IS_PRIVILEGE(r))
-                        log_unit_debug_errno(unit, r, "Failed to adjust coredump_filter, ignoring: %m");
-                else if (r < 0)
-                        return log_unit_error_errno(unit, r, "Failed to adjust coredump_filter: %m");
+                if (r < 0) {
+                        if (ERRNO_IS_PRIVILEGE(r))
+                                log_unit_debug_errno(unit, r, "Failed to adjust coredump_filter, ignoring: %m");
+                        else
+                                return log_unit_error_errno(unit, r, "Failed to adjust coredump_filter: %m");
+                }
         }
 
         if (context->nice_set) {