All of lore.kernel.org
 help / color / mirror / Atom feed
From: Cyril Hrubis <chrubis@suse.cz>
To: Petr Vorel <pvorel@suse.cz>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [PATCH 1/3 v2] tst_supported_fs: Unify messaging
Date: Fri, 23 Sep 2022 17:23:01 +0200	[thread overview]
Message-ID: <Yy3PVQCjVuVJjqwt@yuki> (raw)
In-Reply-To: <20220922210931.23982-2-pvorel@suse.cz>

Hi!
> +#define err(...) ({ \
> +	fprintf(stderr, __VA_ARGS__); \
> +	fprintf(stderr, "\n"); \
> +	usage(); \
> +	return 2; })
           ^
This should rather be exit(2);

It's only matter of time until someone uses that in a function outside
of main.

> +#define fail(...) ({ \
> +	fprintf(stderr, __VA_ARGS__); \
> +	fprintf(stderr, "\n"); \
> +	return 1; })

Here as well.

> +#define info(...) ({ \
> +	fprintf(stderr, __VA_ARGS__); \
> +	fprintf(stderr, "\n"); \
> +	return 0; })

The naming here is a bit of strange, I wouldn't expect that function
called info() would exit the process.

Maybe these three should include exit in the function name such as
info_exit(), err_exit() and fail_exit().

>  static void usage(void)
>  {
>  	fprintf(stderr, "Usage:\n");
> @@ -90,67 +106,50 @@ int main(int argc, char *argv[])
>  			break;
>  
>  		case 'd':
> -			if (fsname) {
> -				fprintf(stderr,
> -					"Can't specify multiple paths\n");
> -				usage();
> -				return 2;
> -			}
> +			if (fsname)
> +				err("Can't specify multiple paths");
>  
>  			fsname = tst_fs_type_name(tst_fs_type(optarg));
>  			break;
>  		}
>  	}
>  
> -	if (fsname && !skiplist) {
> -		fprintf(stderr, "Parameter -d requires skiplist\n");
> -		usage();
> -		return 2;
> -	}
> +	if (fsname && !skiplist)
> +		err("Parameter -d requires skiplist");
>  
> -	if (argc - optind > 1) {
> -		fprintf(stderr, "Can't specify multiple fs_type\n");
> -		usage();
> -		return 2;
> -	}
> +	if (argc - optind > 1)
> +		err("Can't specify multiple fs_type");
>  
>  	/* fs_type */
>  	if (optind < argc) {
> -		if (fsname) {
> -			fprintf(stderr, "Can't specify fs_type and -d together\n");
> -			usage();
> -			return 2;
> -		}
> +		if (fsname)
> +			err("Can't specify fs_type and -d together");
>  
>  		fsname = argv[optind];
>  	}
>  
>  	if (fsname) {
>  		if (fsname[0] == '\0')
> -			tst_brk(TCONF, "fs_type is empty");
> +			err("fs_type is empty");
>  
>  		if (skiplist) {
>  			if (tst_fs_in_skiplist(fsname, (const char * const*)skiplist))
> -				tst_brk(TCONF, "%s is skipped", fsname);
> -			else
> -				tst_res(TINFO, "%s is not skipped", fsname);
> +				fail("%s is skipped", fsname);
>  
> -			return 0;
> +			info("%s is not skipped", fsname);
>  		}
>  
>  		if (tst_fs_is_supported(fsname) == TST_FS_UNSUPPORTED)
> -			tst_brk(TCONF, "%s is not supported", fsname);
> -		else
> -			tst_res(TINFO, "%s is supported", fsname);
> +			fail("%s is not supported", fsname);
>  
> -		return 0;
> +		info("%s is supported", fsname);
>  	}
>  
>  	/* all filesystems */
>  	filesystems = tst_get_supported_fs_types((const char * const*)skiplist);
>  
>  	if (!filesystems[0])
> -		tst_brk(TCONF, "There are no supported filesystems or all skipped");
> +		fail("There are no supported filesystems or all skipped");
>  
>  	for (i = 0; filesystems[i]; i++)
>  		printf("%s\n", filesystems[i]);
> -- 
> 2.37.3
> 

-- 
Cyril Hrubis
chrubis@suse.cz

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

  parent reply	other threads:[~2022-09-23 15:21 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-22 21:09 [LTP] [PATCH 0/3 v2] tst_test.sh: Fix filesystem support detection Petr Vorel
2022-09-22 21:09 ` [LTP] [PATCH 1/3 v2] tst_supported_fs: Unify messaging Petr Vorel
2022-09-23  2:43   ` Li Wang
2022-09-23  6:05     ` Petr Vorel
2022-09-23 15:23   ` Cyril Hrubis [this message]
2022-09-23 16:31     ` Petr Vorel
2022-09-22 21:09 ` [LTP] [PATCH 2/3 v2] tst_supported_fs: Fix return codes Petr Vorel
2022-09-22 21:09 ` [LTP] [PATCH 3/3 v2] tst_test.sh: Fix filesystem support detection Petr Vorel
2022-09-23 15:29   ` Cyril Hrubis
2022-09-23 16:36     ` Petr Vorel
2022-09-26  9:13       ` Cyril Hrubis
2022-09-26  9:34         ` Petr Vorel
2022-09-26  9:45         ` Petr Vorel

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=Yy3PVQCjVuVJjqwt@yuki \
    --to=chrubis@suse.cz \
    --cc=ltp@lists.linux.it \
    --cc=pvorel@suse.cz \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.