[PATCH 3/4] chrt: fix incorrect maximum priority on SCHED_{OTHER, BATCH, IDLE}

walter harms wharms at bfs.de
Sun Jan 14 15:58:25 UTC 2018



Am 13.01.2018 22:29, schrieb Povilas Kanapickas:
> ---
>  util-linux/chrt.c | 14 ++++++++++++--
>  1 file changed, 12 insertions(+), 2 deletions(-)
> 
> diff --git a/util-linux/chrt.c b/util-linux/chrt.c
> index bbd6e2deb..5c5513aeb 100644
> --- a/util-linux/chrt.c
> +++ b/util-linux/chrt.c
> @@ -78,6 +78,8 @@ int chrt_main(int argc UNUSED_PARAM, char **argv)
>  	char *priority = priority; /* for compiler */
>  	const char *current_new;
>  	int policy = SCHED_RR;
> +	int priority_min;
> +	int priority_max;
>  
>  	/* only one policy accepted */
>  	opt = getopt32(argv, "^+" "mprfobi" "\0" "r--fobi:f--robi:o--rfbi:b--rfoi:i--rfob");
> @@ -146,8 +148,16 @@ int chrt_main(int argc UNUSED_PARAM, char **argv)
>  		  priority 0.
>  	[...] SCHED_FIFO or SCHED_RR can have static priority in 1..99 range.
>  	*/
> -	sp.sched_priority = xstrtou_range(priority, 0,
> -			(policy != SCHED_OTHER && policy != SCHED_BATCH && policy != SCHED_IDLE) ? 1 : 0, 99);
> +	if (policy == SCHED_OTHER || policy == SCHED_BATCH
> +	 || policy == SCHED_IDLE
> +	) {
> +		priority_min = 0;
> +		priority_max = 0;
> +	} else {
> +		priority_min = 1;
> +		priority_max = 99;
> +	}
> +	sp.sched_priority = xstrtou_range(priority, 0, priority_min, priority_max);
>  

Perhaps it is better to init direktly:
int priority_min=1;
int priority_max=99;
and forget about the else ?

(a real question i did not check the rest of the code or the resulting size changes)

re,
 wh

>  	if (sched_setscheduler(pid, policy, &sp) < 0)
>  		bb_perror_msg_and_die("can't %cet pid %d's policy", 's', (int)pid);


More information about the busybox mailing list