util-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/4 V2] chrt: with more than one argument, interpret first argument as priority
@ 2025-07-03 14:47 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
                   ` (2 more replies)
  0 siblings, 3 replies; 17+ messages in thread
From: Benno Schulenberg @ 2025-07-03 14:47 UTC (permalink / raw)
  To: util-linux; +Cc: Madadi Vineeth Reddy

The first argument is a priority not only for `chrt --pid <prio> <pid>`
but also for `chrt <prio> <command> [<argument>...]`.

This fixes an oversight in recent commit e7a2d62434.

Reviewed-by: Madadi Vineeth Reddy <vineethr@linux.ibm.com>
Tested-by: Madadi Vineeth Reddy <vineethr@linux.ibm.com>
Signed-off-by: Benno Schulenberg <bensberg@telfort.nl>
---
 schedutils/chrt.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/schedutils/chrt.c b/schedutils/chrt.c
index 550cefe4d..415a9aa77 100644
--- a/schedutils/chrt.c
+++ b/schedutils/chrt.c
@@ -530,7 +530,7 @@ int main(int argc, char **argv)
 
 	errno = 0;
 
-	if (need_prio || argc - optind == 2)
+	if (need_prio || argc - optind > 1)
 		ctl->priority = strtos32_or_err(argv[optind], _("invalid priority argument"));
 	else
 		ctl->priority = 0;
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 2/4 V2] chrt: do not try to interpret the --pid option itself as a PID
  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 ` Benno Schulenberg
  2025-07-03 14:47 ` [PATCH 3/4 V2] chrt: simplify the other check for too few arguments Benno Schulenberg
  2025-07-03 14:47 ` [PATCH 4/4 V2] chrt: do not try to interpret any other option as a PID either Benno Schulenberg
  2 siblings, 0 replies; 17+ messages in thread
From: Benno Schulenberg @ 2025-07-03 14:47 UTC (permalink / raw)
  To: util-linux

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 | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/schedutils/chrt.c b/schedutils/chrt.c
index 415a9aa77..a72c0de26 100644
--- a/schedutils/chrt.c
+++ b/schedutils/chrt.c
@@ -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"));
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 3/4 V2] chrt: simplify the other check for too few arguments
  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 ` Benno Schulenberg
  2025-07-06  5:58   ` Madadi Vineeth Reddy
  2025-07-03 14:47 ` [PATCH 4/4 V2] chrt: do not try to interpret any other option as a PID either Benno Schulenberg
  2 siblings, 1 reply; 17+ messages in thread
From: Benno Schulenberg @ 2025-07-03 14:47 UTC (permalink / raw)
  To: util-linux; +Cc: Madadi Vineeth Reddy

Without option --pid, always at least two arguments are needed:
the <priority> value and a <command>.  (The 'need_prio' variable
is relevant only for the --pid case.)

Also, make the error message more informative.

CC: Madadi Vineeth Reddy <vineethr@linux.ibm.com>
Signed-off-by: Benno Schulenberg <bensberg@telfort.nl>
---

V2: left in the call errtryhelp()

 schedutils/chrt.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

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))
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 4/4 V2] chrt: do not try to interpret any other option as a PID either
  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-03 14:47 ` Benno Schulenberg
  2025-07-06  6:09   ` Madadi Vineeth Reddy
  2 siblings, 1 reply; 17+ messages in thread
From: Benno Schulenberg @ 2025-07-03 14:47 UTC (permalink / raw)
  To: util-linux; +Cc: Madadi Vineeth Reddy

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`:

  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;
 		}
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* Re: [PATCH 3/4 V2] chrt: simplify the other check for too few arguments
  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
  0 siblings, 1 reply; 17+ messages in thread
From: Madadi Vineeth Reddy @ 2025-07-06  5:58 UTC (permalink / raw)
  To: Benno Schulenberg, util-linux; +Cc: Karel Zak, Madadi Vineeth Reddy

On 03/07/25 20:17, Benno Schulenberg wrote:
> Without option --pid, always at least two arguments are needed:
> the <priority> value and a <command>.  (The 'need_prio' variable
> is relevant only for the --pid case.)

Yes, need_prio is only relevant for the --pid case as of now.

But priority should also be optional when --pid is not used, for
policies that don’t require it.

With your patch, this fails:
chrt --other ls
chrt: too few arguments
Try 'chrt --help' for more information.

while this works:
chrt --other 0 ls

The first case should work too, to match the behavior introduced in
commit e7a2d62434c2 ("chrt: Make priority optional for policies that don't use it").

Thanks,
Madadi Vineeth Reddy.

> 
> Also, make the error message more informative.
> 
> CC: Madadi Vineeth Reddy <vineethr@linux.ibm.com>
> Signed-off-by: Benno Schulenberg <bensberg@telfort.nl>
> ---
> 
> V2: left in the call errtryhelp()
> 
>  schedutils/chrt.c | 12 +++++-------
>  1 file changed, 5 insertions(+), 7 deletions(-)
> 
> 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))


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 4/4 V2] chrt: do not try to interpret any other option as a PID either
  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
  2025-07-14 11:28     ` Karel Zak
  0 siblings, 1 reply; 17+ messages in thread
From: Madadi Vineeth Reddy @ 2025-07-06  6:09 UTC (permalink / raw)
  To: Benno Schulenberg, util-linux; +Cc: Karel Zak, Madadi Vineeth Reddy

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;
>  		}


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 3/4 V2] chrt: simplify the other check for too few arguments
  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
  0 siblings, 1 reply; 17+ messages in thread
From: Benno Schulenberg @ 2025-07-06  9:10 UTC (permalink / raw)
  To: Madadi Vineeth Reddy, util-linux; +Cc: Karel Zak


[-- Attachment #1.1: Type: text/plain, Size: 1017 bytes --]


Op 06-07-2025 om 07:58 schreef Madadi Vineeth Reddy:
> But priority should also be optional when --pid is not used, for
> policies that don’t require it.

Oh...  Then the synopses need adjusting, because currently they
indicate the priority value as mandatory when a command is given:

   chrt [options] priority command [argument...]


> With your patch, this fails:
> chrt --other ls
> chrt: too few arguments
> Try 'chrt --help' for more information.
> 
> while this works:
> chrt --other 0 ls
> 
> The first case should work too, to match the behavior introduced in
> commit e7a2d62434c2 ("chrt: Make priority optional for policies that don't use it").

With current git (or after checking out that commit), and then running
`./chrt --other ls`, it says here:

   Segmentatiefout (geheugendump gemaakt)

Running valgrind on it gives:

   ==38370== Invalid read of size 1
   ==38370==    by 0x10C6EB: main (chrt.c:574)

Pointing to: if (strcmp(argv[0], "--") == 0)


Benno


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 840 bytes --]

^ permalink raw reply	[flat|nested] 17+ messages in thread

* chrt from git segfaults
  2025-07-06  9:10     ` Benno Schulenberg
@ 2025-07-09  7:12       ` Benno Schulenberg
  2025-07-09 18:45         ` Madadi Vineeth Reddy
  0 siblings, 1 reply; 17+ messages in thread
From: Benno Schulenberg @ 2025-07-09  7:12 UTC (permalink / raw)
  To: Madadi Vineeth Reddy, util-linux; +Cc: Karel Zak


[-- Attachment #1.1: Type: text/plain, Size: 510 bytes --]


Hello Vineeth,

Just in case you missed the bug report buried in the previous message:

> With current git, running `./chrt --other ls` says here:
> 
>    Segmentatiefout (geheugendump gemaakt)
> 
> Running valgrind on it gives:
> 
>    ==38370== Invalid read of size 1
>    ==38370==    by 0x10C6EB: main (chrt.c:574)
> 
> Pointing to: if (strcmp(argv[0], "--") == 0)

My patch will prevent that case from occurring.  But if instead it
should work, something needs fixing.


Benno

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 840 bytes --]

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: chrt from git segfaults
  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
  0 siblings, 1 reply; 17+ messages in thread
From: Madadi Vineeth Reddy @ 2025-07-09 18:45 UTC (permalink / raw)
  To: Benno Schulenberg, util-linux; +Cc: Karel Zak, Madadi Vineeth Reddy

On 09/07/25 12:42, Benno Schulenberg wrote:
> 
> Hello Vineeth,
> 
> Just in case you missed the bug report buried in the previous message:
> 
>> With current git, running `./chrt --other ls` says here:
>>
>>    Segmentatiefout (geheugendump gemaakt)
>>
>> Running valgrind on it gives:
>>
>>    ==38370== Invalid read of size 1
>>    ==38370==    by 0x10C6EB: main (chrt.c:574)
>>
>> Pointing to: if (strcmp(argv[0], "--") == 0)
> 
> My patch will prevent that case from occurring.  But if instead it
> should work, something needs fixing.

Could you spin off a patch to make sure the priority argument is
optional for policies that don’t need it, even when --pid is not used?

Thanks,
Madadi Vineeth Reddy

> 
> 
> Benno


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: chrt from git segfaults
  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
  0 siblings, 2 replies; 17+ messages in thread
From: Benno Schulenberg @ 2025-07-10  8:11 UTC (permalink / raw)
  To: Madadi Vineeth Reddy, util-linux; +Cc: Karel Zak


[-- Attachment #1.1: Type: text/plain, Size: 247 bytes --]


Op 09-07-2025 om 20:45 schreef Madadi Vineeth Reddy:
> Could you spin off a patch to make sure the priority argument is
> optional for policies that don’t need it, even when --pid is not used?

No.  You broke it, you fix it.


Benno


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 840 bytes --]

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: chrt from git segfaults
  2025-07-10  8:11           ` Benno Schulenberg
@ 2025-07-12 16:29             ` Madadi Vineeth Reddy
  2025-07-14 11:32             ` Karel Zak
  1 sibling, 0 replies; 17+ messages in thread
From: Madadi Vineeth Reddy @ 2025-07-12 16:29 UTC (permalink / raw)
  To: Benno Schulenberg, util-linux; +Cc: Karel Zak, Madadi Vineeth Reddy

On 10/07/25 13:41, Benno Schulenberg wrote:
> 
> Op 09-07-2025 om 20:45 schreef Madadi Vineeth Reddy:
>> Could you spin off a patch to make sure the priority argument is
>> optional for policies that don’t need it, even when --pid is not used?
> 
> No.  You broke it, you fix it.
> 

Sure, I’ll send a patch. Thanks.

Thanks,
Madadi Vineeth Reddy

> 
> Benno
> 


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 4/4 V2] chrt: do not try to interpret any other option as a PID either
  2025-07-06  6:09   ` Madadi Vineeth Reddy
@ 2025-07-14 11:28     ` Karel Zak
  2025-07-15  5:33       ` Madadi Vineeth Reddy
  0 siblings, 1 reply; 17+ messages in thread
From: Karel Zak @ 2025-07-14 11:28 UTC (permalink / raw)
  To: Madadi Vineeth Reddy; +Cc: Benno Schulenberg, util-linux

On Sun, Jul 06, 2025 at 11:39:44AM +0530, Madadi Vineeth Reddy wrote:
> 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.

My point of view (may be wrong, sched-utils CLI is odd). The core of  
the chrt command line can be described as:

   chrt <options> [<prio>] <process>

where <process> is

    1) new process by exec()
    2) already running process

The default is 1), --pid enables the 2) and in this case  
<process> is PID.

The --pid is just an option to switch between the cases. There is no  
argument for the option; it informs how to interpret the <process>.

The ideal would be to use "--" before <process>.

It means that arbitrary options could be after --pid, including --max.

Does it make sense?

    Karel

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: chrt from git segfaults
  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
  1 sibling, 2 replies; 17+ messages in thread
From: Karel Zak @ 2025-07-14 11:32 UTC (permalink / raw)
  To: Benno Schulenberg; +Cc: Madadi Vineeth Reddy, util-linux

On Thu, Jul 10, 2025 at 10:11:58AM +0200, Benno Schulenberg wrote:
> 
> Op 09-07-2025 om 20:45 schreef Madadi Vineeth Reddy:
> > Could you spin off a patch to make sure the priority argument is
> > optional for policies that don’t need it, even when --pid is not used?
> 
> No.  You broke it, you fix it.

Please, please, don't forget to finalize it to avoid releasing it
incomplete ;-)

I have merged Benno's V2 set of patches, so nothing else is in the
queue for now.

Thanks guys!

    Karel

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: chrt from git segfaults
  2025-07-14 11:32             ` Karel Zak
@ 2025-07-15  5:29               ` Madadi Vineeth Reddy
  2025-07-15  9:19               ` Benno Schulenberg
  1 sibling, 0 replies; 17+ messages in thread
From: Madadi Vineeth Reddy @ 2025-07-15  5:29 UTC (permalink / raw)
  To: Karel Zak; +Cc: util-linux, Benno Schulenberg, Madadi Vineeth Reddy

Hi Karel,

On 14/07/25 17:02, Karel Zak wrote:
> On Thu, Jul 10, 2025 at 10:11:58AM +0200, Benno Schulenberg wrote:
>>
>> Op 09-07-2025 om 20:45 schreef Madadi Vineeth Reddy:
>>> Could you spin off a patch to make sure the priority argument is
>>> optional for policies that don’t need it, even when --pid is not used?
>>
>> No.  You broke it, you fix it.
> 
> Please, please, don't forget to finalize it to avoid releasing it
> incomplete ;-)
> 
> I have merged Benno's V2 set of patches, so nothing else is in the
> queue for now.

I will send the patch to make the priority argument optional when
--pid is not used in the next couple of days. That should complete
the series.

Thanks,
Madadi Vineeth Reddy

> 
> Thanks guys!
> 
>     Karel
> 


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 4/4 V2] chrt: do not try to interpret any other option as a PID either
  2025-07-14 11:28     ` Karel Zak
@ 2025-07-15  5:33       ` Madadi Vineeth Reddy
  0 siblings, 0 replies; 17+ messages in thread
From: Madadi Vineeth Reddy @ 2025-07-15  5:33 UTC (permalink / raw)
  To: Karel Zak; +Cc: Benno Schulenberg, util-linux, Madadi Vineeth Reddy

On 14/07/25 16:58, Karel Zak wrote:
> On Sun, Jul 06, 2025 at 11:39:44AM +0530, Madadi Vineeth Reddy wrote:
>> 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.
> 
> My point of view (may be wrong, sched-utils CLI is odd). The core of  
> the chrt command line can be described as:
> 
>    chrt <options> [<prio>] <process>
> 
> where <process> is
> 
>     1) new process by exec()
>     2) already running process
> 
> The default is 1), --pid enables the 2) and in this case  
> <process> is PID.
> 
> The --pid is just an option to switch between the cases. There is no  
> argument for the option; it informs how to interpret the <process>.
> 
> The ideal would be to use "--" before <process>.
> 
> It means that arbitrary options could be after --pid, including --max.
> 
> Does it make sense?
> 

Yes. That makes sense.

Thanks,
Madadi Vineeth Reddy

>     Karel
> 


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: chrt from git segfaults
  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
  1 sibling, 1 reply; 17+ messages in thread
From: Benno Schulenberg @ 2025-07-15  9:19 UTC (permalink / raw)
  To: Karel Zak; +Cc: Madadi Vineeth Reddy, util-linux


[-- Attachment #1.1: Type: text/plain, Size: 221 bytes --]


Op 14-07-2025 om 13:32 schreef Karel Zak:
> I have merged Benno's V2 set of patches, so nothing else is in the
> queue for now.

I'm not seeing those in git yet.  Did you forget to push to kernel.org?


Benno


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 840 bytes --]

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: chrt from git segfaults
  2025-07-15  9:19               ` Benno Schulenberg
@ 2025-07-16  8:16                 ` Karel Zak
  0 siblings, 0 replies; 17+ messages in thread
From: Karel Zak @ 2025-07-16  8:16 UTC (permalink / raw)
  To: Benno Schulenberg; +Cc: Madadi Vineeth Reddy, util-linux

On Tue, Jul 15, 2025 at 11:19:46AM +0200, Benno Schulenberg wrote:
> 
> Op 14-07-2025 om 13:32 schreef Karel Zak:
> > I have merged Benno's V2 set of patches, so nothing else is in the
> > queue for now.
> 
> I'm not seeing those in git yet.  Did you forget to push to kernel.org?

All should be on kernel.org and github.com now.

    Karel

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com


^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2025-07-16  8:16 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2025-07-14 11:28     ` Karel Zak
2025-07-15  5:33       ` Madadi Vineeth Reddy

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).