]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
chrt: Only show current scheduling policy when pid is given
authorRong Zhang <i@rong.moe>
Sat, 25 Apr 2026 20:19:39 +0000 (04:19 +0800)
committerRong Zhang <i@rong.moe>
Mon, 4 May 2026 12:13:34 +0000 (20:13 +0800)
The `--verbose' option is completely broken when `--pid' is not
specified, as it tries to show the current scheduling policy for
nothing:

  $ chrt --verbose --other 0 true
  chrt: failed to get pid -1's policy: Invalid argument

Fix it by only showing the current scheduling policy if `--pid' and
`--verbose' are both given.

  $ chrt --verbose --other 0 true
  pid 1549197's new scheduling policy: SCHED_OTHER
  pid 1549197's new scheduling priority: 0
  pid 1549197's new runtime parameter: 2800000

Fixes: 13346d4d28cd ("chrt: Only display current settings when no policy is specified")
Signed-off-by: Rong Zhang <i@rong.moe>
schedutils/chrt.c

index 273905e5d86dc0c148dc4b5cb5e648eb90f684df..ab6e53ac6732246977e91048311cc5cc5024cbf1 100644 (file)
@@ -527,7 +527,7 @@ int main(int argc, char **argv)
        if (ctl->policy == SCHED_RR)
                need_prio = true;
 
-       if (ctl->verbose)
+       if (ctl->pid > -1 && ctl->verbose)
                show_sched_info(ctl);
 
        bool have_prio = need_prio ||