From: Madadi Vineeth Reddy <vineethr@linux.ibm.com>
To: Benno Schulenberg <bensberg@telfort.nl>, util-linux@vger.kernel.org
Cc: Karel Zak <kzak@redhat.com>,
Madadi Vineeth Reddy <vineethr@linux.ibm.com>
Subject: Re: [PATCH 4/4 V2] chrt: do not try to interpret any other option as a PID either
Date: Sun, 6 Jul 2025 11:39:44 +0530 [thread overview]
Message-ID: <547205fc-ae34-4ac4-a7d9-d32e65b5c3cb@linux.ibm.com> (raw)
In-Reply-To: <20250703144752.29971-4-bensberg@telfort.nl>
On 03/07/25 20:17, Benno Schulenberg wrote:
> When doing, for example, `chrt --pid --max`, it would report:
>
> chrt: invalid PID argument: '--max'
>
> This mistakenly gave the impression that the PID argument has to follow
> directly after the --pid option.
>
> Avoid this by delaying the parsing of a PID until after all options have
> been parsed. Temporarily set 'ctl->pid' to zero to indicate that a PID
> needs to be read.
>
> After this change, `chrt --pid --max` will simply report the minimum and
> maximum valid priorities. And `chrt --pid -v`:
According to help text,
chrt [options] --pid <priority> <pid>
I’m still not sure about allowing the --max option after --pid.
I’ll leave it to Karel to decide what’s best here.
Thanks,
Madadi Vineeth Reddy
>
> chrt: too few arguments
>
> Also, add a missing call of gettext() for the other error message.
>
> CC: Madadi Vineeth Reddy <vineethr@linux.ibm.com>
> Signed-off-by: Benno Schulenberg <bensberg@telfort.nl>
> ---
> schedutils/chrt.c | 24 +++++++++++-------------
> 1 file changed, 11 insertions(+), 13 deletions(-)
>
> diff --git a/schedutils/chrt.c b/schedutils/chrt.c
> index 731f995bb..10ba7fbf6 100644
> --- a/schedutils/chrt.c
> +++ b/schedutils/chrt.c
> @@ -474,11 +474,7 @@ 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"));
> + ctl->pid = 0; /* indicate that a PID is expected */
> break;
> case 'r':
> ctl->policy = SCHED_RR;
> @@ -507,20 +503,22 @@ int main(int argc, char **argv)
> }
> }
>
> - if (argc - optind < (ctl->pid > -1 ? 1 : 2)) {
> + if (argc - optind < (ctl->pid == 0 ? 1 : 2)) {
> warnx(_("too few arguments"));
> errtryhelp(EXIT_FAILURE);
> }
>
> - /* pid exists but priority not given */
> - if (ctl->pid > -1 && argc - optind == 1) {
> - /* Error if priority is missing for a policy that requires it */
> - if (policy_given && need_prio)
> - errx(EXIT_FAILURE, ("policy %s requires a priority argument"),
> + /* If option --pid was given, parse the very last argument as a PID. */
> + if (ctl->pid == 0) {
> + if (need_prio && argc - optind < 2)
> + errx(EXIT_FAILURE, _("policy %s requires a priority argument"),
> get_policy_name(ctl->policy));
> + errno = 0;
> + /* strtopid_or_err() is not suitable here, as 0 can be passed. */
> + ctl->pid = strtos32_or_err(argv[argc - 1], _("invalid PID argument"));
>
> - /* If no policy specified, show current settings */
> - if (!policy_given) {
> + /* If no policy nor priority was given, show current settings. */
> + if (!policy_given && argc - optind == 1) {
> show_sched_info(ctl);
> return EXIT_SUCCESS;
> }
next prev parent reply other threads:[~2025-07-06 6:09 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-03 14:47 [PATCH 1/4 V2] chrt: with more than one argument, interpret first argument as priority Benno Schulenberg
2025-07-03 14:47 ` [PATCH 2/4 V2] chrt: do not try to interpret the --pid option itself as a PID Benno Schulenberg
2025-07-03 14:47 ` [PATCH 3/4 V2] chrt: simplify the other check for too few arguments Benno Schulenberg
2025-07-06 5:58 ` Madadi Vineeth Reddy
2025-07-06 9:10 ` Benno Schulenberg
2025-07-09 7:12 ` chrt from git segfaults Benno Schulenberg
2025-07-09 18:45 ` Madadi Vineeth Reddy
2025-07-10 8:11 ` Benno Schulenberg
2025-07-12 16:29 ` Madadi Vineeth Reddy
2025-07-14 11:32 ` Karel Zak
2025-07-15 5:29 ` Madadi Vineeth Reddy
2025-07-15 9:19 ` Benno Schulenberg
2025-07-16 8:16 ` Karel Zak
2025-07-03 14:47 ` [PATCH 4/4 V2] chrt: do not try to interpret any other option as a PID either Benno Schulenberg
2025-07-06 6:09 ` Madadi Vineeth Reddy [this message]
2025-07-14 11:28 ` Karel Zak
2025-07-15 5:33 ` Madadi Vineeth Reddy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=547205fc-ae34-4ac4-a7d9-d32e65b5c3cb@linux.ibm.com \
--to=vineethr@linux.ibm.com \
--cc=bensberg@telfort.nl \
--cc=kzak@redhat.com \
--cc=util-linux@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).