From: Benno Schulenberg Date: Thu, 3 Jul 2025 14:47:51 +0000 (+0200) Subject: chrt: simplify the other check for too few arguments X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7f47aa34942e4f2ba06cf142f2f9aa39ba2ba4c3;p=thirdparty%2Futil-linux.git chrt: simplify the other check for too few arguments Without option --pid, always at least two arguments are needed: the value and a . (The 'need_prio' variable is relevant only for the --pid case.) Also, make the error message more informative. CC: Madadi Vineeth Reddy Signed-off-by: Benno Schulenberg --- diff --git a/schedutils/chrt.c b/schedutils/chrt.c index a72c0de26..731f995bb 100644 --- a/schedutils/chrt.c +++ b/schedutils/chrt.c @@ -507,9 +507,8 @@ int main(int argc, char **argv) } } - if (((ctl->pid > -1) && argc - optind < (need_prio ? 1 : 0)) || - ((ctl->pid == -1) && argc - optind < (need_prio ? 2 : 1))) { - warnx(_("bad usage")); + if (argc - optind < (ctl->pid > -1 ? 1 : 2)) { + warnx(_("too few arguments")); errtryhelp(EXIT_FAILURE); } @@ -530,11 +529,10 @@ int main(int argc, char **argv) if (ctl->verbose) show_sched_info(ctl); - errno = 0; - - if (need_prio || argc - optind > 1) + if (argc - optind > 1) { + errno = 0; ctl->priority = strtos32_or_err(argv[optind], _("invalid priority argument")); - else + } else ctl->priority = 0; if (ctl->runtime && !supports_runtime_param(ctl->policy))