This extends commit
e7a2d62434c2
("chrt: Make priority optional for policies that don't use it")
so that priority arguments are optional even when --pid is not specified.
Before this patch:
$ chrt --other ls -lh
chrt: invalid priority argument: 'ls'
-> only "chrt --other 0 ls -lh" would work
After this patch:
$ chrt --other ls -lh
$ chrt --other 0 ls -lh
-> both now work
If an out‑of‑range priority is given, it reports an error:
$ chrt --other 1 ls -lh
unsupported priority value for the policy: 1 (see --max for valid range)
Changes in v2:
- Removed is_number() and used isdigit_string() (Karel Zak)
- used _() for translation (Karel Zak)
Fixes: e7a2d62434c2 ("chrt: Make priority optional for policies that don't use it")
Signed-off-by: Madadi Vineeth Reddy <vineethr@linux.ibm.com>
}
}
- if (argc - optind < (ctl->pid == 0 ? 1 : 2)) {
+ if (argc - optind < 1) {
warnx(_("too few arguments"));
errtryhelp(EXIT_FAILURE);
}
if (ctl->verbose)
show_sched_info(ctl);
- if (argc - optind > 1) {
+ bool have_prio = need_prio ||
+ (ctl->pid == -1 ? (optind < argc && isdigit_string(argv[optind])) : (argc - optind > 1));
+
+ if (have_prio) {
errno = 0;
ctl->priority = strtos32_or_err(argv[optind], _("invalid priority argument"));
} else
show_sched_info(ctl);
if (!ctl->pid) {
- argv += optind + 1;
- if (strcmp(argv[0], "--") == 0)
+ argv += optind;
+
+ if (need_prio)
argv++;
+ else if (argv[0] && isdigit_string(argv[0]))
+ argv++;
+
+ if (argv[0] && strcmp(argv[0], "--") == 0)
+ argv++;
+
+ if (!argv[0])
+ errx(EXIT_FAILURE, _("no command specified"));
+
execvp(argv[0], argv);
errexec(argv[0]);
}