Re: [PATCH 3/4 V2] chrt: simplify the other check for too few arguments

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxx>
> Signed-off-by: Benno Schulenberg <bensberg@xxxxxxxxxx>
> ---
> 
> 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))





[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux