From: Madadi Vineeth Reddy <vineethr@linux.ibm.com>
To: Karel Zak <kzak@redhat.com>
Cc: util-linux@vger.kernel.org,
Benno Schulenberg <bensberg@telfort.nl>,
Madadi Vineeth Reddy <vineethr@linux.ibm.com>
Subject: Re: [PATCH] chrt: Allow optional priority for non‑prio policies without --pid
Date: Mon, 21 Jul 2025 21:13:49 +0530 [thread overview]
Message-ID: <dadc4295-fea1-4faf-ba0b-ad5ce7060c7f@linux.ibm.com> (raw)
In-Reply-To: <eu5csrk3f4jmwf7olhle3ukcxvdcofhgk7etss6dko3h364qhn@bxaakyetv7uk>
Hi Karel,
On 21/07/25 12:31, Karel Zak wrote:
> On Sat, Jul 19, 2025 at 12:34:39AM +0530, Madadi Vineeth Reddy wrote:
>> diff --git a/schedutils/chrt.c b/schedutils/chrt.c
>> index 10ba7fbf6..44b9b9e20 100644
>> --- a/schedutils/chrt.c
>> +++ b/schedutils/chrt.c
>> @@ -395,6 +395,18 @@ static void set_sched(struct chrt_ctl *ctl)
>> ctl->altered = 1;
>> }
>>
>> +static bool is_number(const char *s)
>> +{
>> + if (!s || *s == '\0')
>> + return false;
>> +
>> + for (const char *p = s; *p; p++) {
>> + if (!isdigit((unsigned char)*p))
>> + return false;
>> + }
>> + return true;
>> +}
>
> It seems you can replace this function with isdigit_string() from
> include/strutils.h.
>
Will replace it.
>> +
>> int main(int argc, char **argv)
>> {
>> struct chrt_ctl _ctl = { .pid = -1, .policy = SCHED_RR }, *ctl = &_ctl;
>> @@ -503,7 +515,7 @@ int main(int argc, char **argv)
>> }
>> }
>>
>> - if (argc - optind < (ctl->pid == 0 ? 1 : 2)) {
>> + if (argc - optind < 1) {
>> warnx(_("too few arguments"));
>> errtryhelp(EXIT_FAILURE);
>> }
>> @@ -527,7 +539,10 @@ int main(int argc, char **argv)
>> if (ctl->verbose)
>> show_sched_info(ctl);
>>
>> - if (argc - optind > 1) {
>> + bool have_prio = need_prio ||
>> + (ctl->pid == -1 ? (optind < argc && is_number(argv[optind])) : (argc - optind > 1));
>> +
>> + if (have_prio) {
>> errno = 0;
>> ctl->priority = strtos32_or_err(argv[optind], _("invalid priority argument"));
>> } else
>> @@ -568,9 +583,19 @@ int main(int argc, char **argv)
>> 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] && is_number(argv[0]))
>> + argv++;
>> +
>> + if (argv[0] && strcmp(argv[0], "--") == 0)
>> argv++;
>> +
>> + if (!argv[0])
>> + errx(EXIT_FAILURE, "Missing command to execute");
>
> You need to use _() for translation, ideally with string already used in
> other tools. For example, _("no command specified").
Sure. Will fix it in v2. Thanks for taking a look.
--
Madadi Vineeth Reddy
>
> Thanks!
> Karel
>
prev parent reply other threads:[~2025-07-21 15:44 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-18 19:04 [PATCH] chrt: Allow optional priority for non‑prio policies without --pid Madadi Vineeth Reddy
2025-07-21 7:01 ` Karel Zak
2025-07-21 15:43 ` Madadi Vineeth Reddy [this message]
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=dadc4295-fea1-4faf-ba0b-ad5ce7060c7f@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).