Re: [rt-tests v2 08/18] pip_stress: Add command line parser

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

 




On Wed, 7 Oct 2020, Daniel Wagner wrote:

> Add a default command line parser to print at least the current
> version.
> 
> Signed-off-by: Daniel Wagner <dwagner@xxxxxxx>
> ---
>  src/pi_tests/pip_stress.c | 34 +++++++++++++++++++++++++++++-----
>  1 file changed, 29 insertions(+), 5 deletions(-)
> 
> diff --git a/src/pi_tests/pip_stress.c b/src/pi_tests/pip_stress.c
> index c9dbd992e15d..74cf53dcfa7a 100644
> --- a/src/pi_tests/pip_stress.c
> +++ b/src/pi_tests/pip_stress.c
> @@ -67,12 +67,17 @@ struct State *statep;
>  const int policy = SCHED_FIFO;
>  const int prio_min;	/* Initialized for the minimum priority of policy */
>  
> -struct option long_options[] = {
> -    { "usleep", required_argument, 0, 0 },
> -    { 0,        0,                 0, 0 },
> -};
> +static void usage(int error)
> +{
> +	printf("pip_stress V %1.2f\n", VERSION);
> +	printf("Usage:\n"
> +	       "pip_stress <options>\n"\
> +	       "-h	--help                  Show this help menu.\n"
> +	       );
> +	exit(error);
> +}
>  
> -int main(void)
> +int main(int argc, char *argv[])
>  {
>  	void *mptr;	/* memory pointer */
>  	pid_t pid1, pid2;
> @@ -80,6 +85,25 @@ int main(void)
>  	int res;
>  	int *minimum_priority = (int*)&prio_min;
>  
> +	for (;;) {
> +		struct option long_options[] = {
> +			{ "help",	no_argument,		NULL,	'h' },
> +			{ NULL,		0,			NULL,	0 },
> +		};
> +
> +		int c = getopt_long(argc, argv, "s:h", long_options, NULL);
> +		if (c == -1)
> +			break;
> +		switch (c) {
> +		case 'h':
> +			usage(0);
> +			break;
> +		default:
> +			usage(1);
> +			break;
> +		};
> +	}
> +
>  	*minimum_priority = sched_get_priority_min(policy);
>  
>  	if (check_privs())
> -- 
> 2.28.0
> 
> 

Uglifying my beautiful program in the name conformity?

Ugh, ok fine

Signed-off-by: John Kacur <jkacur@xxxxxxxxxx>



[Index of Archives]     [RT Stable]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]

  Powered by Linux