]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core/exec-invoke: call setpriority() after sched_setattr()
authorIvan Shapovalov <intelfx@intelfx.name>
Wed, 7 Aug 2024 08:02:45 +0000 (10:02 +0200)
committerLuca Boccassi <luca.boccassi@gmail.com>
Sat, 10 Aug 2024 17:09:14 +0000 (19:09 +0200)
The nice value is part of struct sched_attr, and consequently invoking
sched_setattr() after setpriority() would clobber the nice value with
the default (as we are not setting it in struct sched_attr).

It would be best to combine both calls, but for now simply invoke
setpriority() after sched_setattr() to make sure Nice= remains effective
when used together with CPUSchedulingPolicy=.

src/core/exec-invoke.c

index cf17824fe84ec12d16c267bd76a06cc2f842ea4f..6bef4e7675e2e05fcba38e000c3451ef4c618117 100644 (file)
@@ -4435,14 +4435,6 @@ int exec_invoke(
                 }
         }
 
-        if (context->nice_set) {
-                r = setpriority_closest(context->nice);
-                if (r < 0) {
-                        *exit_status = EXIT_NICE;
-                        return log_exec_error_errno(context, params, r, "Failed to set up process scheduling priority (nice level): %m");
-                }
-        }
-
         if (context->cpu_sched_set) {
                 struct sched_attr attr = {
                         .size = sizeof(attr),
@@ -4458,6 +4450,14 @@ int exec_invoke(
                 }
         }
 
+        if (context->nice_set) {
+                r = setpriority_closest(context->nice);
+                if (r < 0) {
+                        *exit_status = EXIT_NICE;
+                        return log_exec_error_errno(context, params, r, "Failed to set up process scheduling priority (nice level): %m");
+                }
+        }
+
         if (context->cpu_affinity_from_numa || context->cpu_set.set) {
                 _cleanup_(cpu_set_reset) CPUSet converted_cpu_set = {};
                 const CPUSet *cpu_set;