]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
chrt: do not try to interpret the --pid option itself as a PID
authorBenno Schulenberg <bensberg@telfort.nl>
Thu, 3 Jul 2025 14:47:50 +0000 (16:47 +0200)
committerKarel Zak <kzak@redhat.com>
Mon, 7 Jul 2025 11:33:11 +0000 (13:33 +0200)
When not specifying a PID with --pid, `chrt` would report:

  chrt: invalid PID argument: '--pid'

That was silly.  After this change, `chrt --pid` will report:

  chrt: too few arguments

Signed-off-by: Benno Schulenberg <bensberg@telfort.nl>
schedutils/chrt.c

index 415a9aa77a7c72b5c2a20b4ab29d2e6112383d22..a72c0de269b301b26ffbc5b2fda35f6aff2ad253 100644 (file)
@@ -474,6 +474,8 @@ int main(int argc, char **argv)
                        policy_given = true;
                        break;
                case 'p':
+                       if (argc - optind == 0)
+                               errx(EXIT_FAILURE, _("too few arguments"));
                        errno = 0;
                        /* strtopid_or_err() is not suitable here; 0 can be passed.*/
                        ctl->pid = strtos32_or_err(argv[argc - 1], _("invalid PID argument"));