misc: never use usage(ERROR)
We are using better/shorter error messages and somtimes also errtryhelp(). Here we fix all cases where the usage function took an int argument for exit_code. Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
This commit is contained in:
parent
9325dbfd20
commit
5118d1be2a
|
@ -102,11 +102,9 @@ static char *outbuffer;
|
|||
|
||||
static size_t blksize = 0;
|
||||
|
||||
|
||||
/* Input status of 0 to print help and exit without an error. */
|
||||
static void __attribute__((__noreturn__)) usage(int status)
|
||||
static void __attribute__((__noreturn__)) usage(void)
|
||||
{
|
||||
FILE *out = status ? stderr : stdout;
|
||||
FILE *out = stdout;
|
||||
|
||||
fputs(USAGE_HEADER, out);
|
||||
fprintf(out,
|
||||
|
@ -126,7 +124,7 @@ static void __attribute__((__noreturn__)) usage(int status)
|
|||
fputs(USAGE_VERSION, out);
|
||||
fputs(USAGE_SEPARATOR, out);
|
||||
|
||||
exit(status);
|
||||
exit(FSCK_EX_OK);
|
||||
}
|
||||
|
||||
static int get_superblock_endianness(uint32_t magic)
|
||||
|
@ -669,7 +667,7 @@ int main(int argc, char **argv)
|
|||
case 'y':
|
||||
break;
|
||||
case 'h':
|
||||
usage(FSCK_EX_OK);
|
||||
usage();
|
||||
break;
|
||||
case 'V':
|
||||
printf(UTIL_LINUX_VERSION);
|
||||
|
@ -689,8 +687,10 @@ int main(int argc, char **argv)
|
|||
errtryhelp(FSCK_EX_USAGE);
|
||||
}
|
||||
|
||||
if ((argc - optind) != 1)
|
||||
usage(FSCK_EX_USAGE);
|
||||
if ((argc - optind) != 1){
|
||||
warnx(_("bad usage"));
|
||||
errtryhelp(FSCK_EX_USAGE);
|
||||
}
|
||||
filename = argv[optind];
|
||||
|
||||
test_super(&start, &length);
|
||||
|
|
|
@ -42,10 +42,9 @@ void open_raw_ctl(void);
|
|||
static int query(int minor_raw, const char *raw_name, int quiet);
|
||||
static int bind(int minor_raw, int block_major, int block_minor);
|
||||
|
||||
static void __attribute__ ((__noreturn__)) usage(int err)
|
||||
static void __attribute__((__noreturn__)) usage(void)
|
||||
{
|
||||
FILE *out = err == EXIT_SUCCESS ? stdout : stderr;
|
||||
|
||||
FILE *out = stdout;
|
||||
fputs(USAGE_HEADER, out);
|
||||
fprintf(out,
|
||||
_(" %1$s %2$srawN <major> <minor>\n"
|
||||
|
@ -63,7 +62,7 @@ static void __attribute__ ((__noreturn__)) usage(int err)
|
|||
fputs(USAGE_HELP, out);
|
||||
fputs(USAGE_VERSION, out);
|
||||
fprintf(out, USAGE_MAN_TAIL("raw(8)"));
|
||||
exit(err);
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
static long strtol_octal_or_err(const char *str, const char *errmesg)
|
||||
|
@ -124,7 +123,7 @@ int main(int argc, char *argv[])
|
|||
printf(UTIL_LINUX_VERSION);
|
||||
return EXIT_SUCCESS;
|
||||
case 'h':
|
||||
usage(EXIT_SUCCESS);
|
||||
usage();
|
||||
default:
|
||||
errtryhelp(EXIT_FAILURE);
|
||||
}
|
||||
|
@ -135,8 +134,10 @@ int main(int argc, char *argv[])
|
|||
open_raw_ctl();
|
||||
|
||||
if (do_query_all) {
|
||||
if (optind < argc)
|
||||
usage(EXIT_FAILURE);
|
||||
if (optind < argc) {
|
||||
warnx(_("bad usage"));
|
||||
errtryhelp(EXIT_FAILURE);
|
||||
}
|
||||
for (i = 1; i < RAW_NR_MINORS; i++)
|
||||
query(i, NULL, 1);
|
||||
exit(EXIT_SUCCESS);
|
||||
|
@ -146,8 +147,10 @@ int main(int argc, char *argv[])
|
|||
* It's a bind or a single query. Either way we need a raw device.
|
||||
*/
|
||||
|
||||
if (optind >= argc)
|
||||
usage(EXIT_FAILURE);
|
||||
if (optind >= argc) {
|
||||
warnx(_("bad usage"));
|
||||
errtryhelp(EXIT_FAILURE);
|
||||
}
|
||||
raw_name = argv[optind++];
|
||||
|
||||
/*
|
||||
|
@ -156,9 +159,10 @@ int main(int argc, char *argv[])
|
|||
* causes udev to *remove* /dev/rawctl
|
||||
*/
|
||||
rc = sscanf(raw_name, _PATH_RAWDEVDIR "raw%d", &raw_minor);
|
||||
if (rc != 1)
|
||||
usage(EXIT_FAILURE);
|
||||
|
||||
if (rc != 1) {
|
||||
warnx(_("bad usage"));
|
||||
errtryhelp(EXIT_FAILURE);
|
||||
}
|
||||
if (raw_minor == 0)
|
||||
errx(EXIT_RAW_ACCESS,
|
||||
_("Device '%s' is the control raw device "
|
||||
|
@ -197,7 +201,8 @@ int main(int argc, char *argv[])
|
|||
break;
|
||||
|
||||
default:
|
||||
usage(EXIT_FAILURE);
|
||||
warnx(_("bad usage"));
|
||||
errtryhelp(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
return bind(raw_minor, block_major, block_minor);
|
||||
|
|
|
@ -672,7 +672,7 @@ restricted_shell (const char * const shell)
|
|||
}
|
||||
|
||||
static void __attribute__((__noreturn__))
|
||||
usage (const int status)
|
||||
usage(void)
|
||||
{
|
||||
if (su_mode == RUNUSER_MODE) {
|
||||
fputs(USAGE_HEADER, stdout);
|
||||
|
@ -712,7 +712,7 @@ usage (const int status)
|
|||
fputs(USAGE_HELP, stdout);
|
||||
fputs(USAGE_VERSION, stdout);
|
||||
printf(USAGE_MAN_TAIL(su_mode == SU_MODE ? "su(1)" : "runuser(1)"));
|
||||
exit (status);
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
static
|
||||
|
@ -851,13 +851,15 @@ su_main (int argc, char **argv, int mode)
|
|||
break;
|
||||
|
||||
case 'u':
|
||||
if (su_mode != RUNUSER_MODE)
|
||||
usage (EXIT_FAILURE);
|
||||
if (su_mode != RUNUSER_MODE) {
|
||||
warnx(_("invalid option -- 'u'"));
|
||||
errtryhelp(EXIT_FAILURE);
|
||||
}
|
||||
runuser_user = optarg;
|
||||
break;
|
||||
|
||||
case 'h':
|
||||
usage(0);
|
||||
usage();
|
||||
|
||||
case 'V':
|
||||
printf(UTIL_LINUX_VERSION);
|
||||
|
|
|
@ -22,9 +22,9 @@
|
|||
#define FINDFS_NOT_FOUND 1 /* label or uuid cannot be found */
|
||||
#define FINDFS_USAGE_ERROR 2 /* user did something unexpected */
|
||||
|
||||
static void __attribute__((__noreturn__)) usage(int rc)
|
||||
static void __attribute__((__noreturn__)) usage(void)
|
||||
{
|
||||
FILE *out = rc ? stderr : stdout;
|
||||
FILE *out = stdout;
|
||||
fputs(USAGE_HEADER, out);
|
||||
fprintf(out, _(" %s [options] {LABEL,UUID,PARTUUID,PARTLABEL}=<value>\n"),
|
||||
program_invocation_short_name);
|
||||
|
@ -36,7 +36,7 @@ static void __attribute__((__noreturn__)) usage(int rc)
|
|||
fputs(USAGE_HELP, out);
|
||||
fputs(USAGE_VERSION, out);
|
||||
fprintf(out, USAGE_MAN_TAIL("findfs(8)"));
|
||||
exit(rc);
|
||||
exit(FINDFS_SUCCESS);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
|
@ -54,10 +54,12 @@ int main(int argc, char **argv)
|
|||
textdomain(PACKAGE);
|
||||
atexit(close_stdout);
|
||||
|
||||
if (argc != 2)
|
||||
if (argc != 2) {
|
||||
/* we return '2' for backward compatibility
|
||||
* with version from e2fsprogs */
|
||||
usage(FINDFS_USAGE_ERROR);
|
||||
warnx(_("bad usage"));
|
||||
errtryhelp(FINDFS_USAGE_ERROR);
|
||||
}
|
||||
|
||||
while ((c = getopt_long(argc, argv, "Vh", longopts, NULL)) != -1)
|
||||
switch (c) {
|
||||
|
@ -65,7 +67,7 @@ int main(int argc, char **argv)
|
|||
printf(UTIL_LINUX_VERSION);
|
||||
return FINDFS_SUCCESS;
|
||||
case 'h':
|
||||
usage(FINDFS_SUCCESS);
|
||||
usage();
|
||||
default:
|
||||
errtryhelp(FINDFS_USAGE_ERROR);
|
||||
}
|
||||
|
|
|
@ -320,10 +320,10 @@ print_namei(struct namei *nm, char *path)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static void usage(int rc)
|
||||
static void __attribute__((__noreturn__)) usage(void)
|
||||
{
|
||||
const char *p = program_invocation_short_name;
|
||||
FILE *out = rc == EXIT_FAILURE ? stderr : stdout;
|
||||
FILE *out = stdout;
|
||||
|
||||
if (!*p)
|
||||
p = "namei";
|
||||
|
@ -346,7 +346,7 @@ static void usage(int rc)
|
|||
" -v, --vertical vertical align of modes and owners\n"), out);
|
||||
|
||||
fprintf(out, USAGE_MAN_TAIL("namei(1)"));
|
||||
exit(rc);
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
static const struct option longopts[] =
|
||||
|
@ -376,7 +376,7 @@ main(int argc, char **argv)
|
|||
while ((c = getopt_long(argc, argv, "hVlmnovx", longopts, NULL)) != -1) {
|
||||
switch(c) {
|
||||
case 'h':
|
||||
usage(EXIT_SUCCESS);
|
||||
usage();
|
||||
break;
|
||||
case 'V':
|
||||
printf(UTIL_LINUX_VERSION);
|
||||
|
@ -406,7 +406,7 @@ main(int argc, char **argv)
|
|||
|
||||
if (optind == argc) {
|
||||
warnx(_("pathname argument is missing"));
|
||||
usage(EXIT_FAILURE);
|
||||
errtryhelp(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
ucache = new_idcache();
|
||||
|
|
|
@ -128,9 +128,9 @@ struct chrt_ctl {
|
|||
verbose : 1; /* verbose output */
|
||||
};
|
||||
|
||||
static void __attribute__((__noreturn__)) show_usage(int rc)
|
||||
static void __attribute__((__noreturn__)) usage(void)
|
||||
{
|
||||
FILE *out = rc == EXIT_SUCCESS ? stdout : stderr;
|
||||
FILE *out = stdout;
|
||||
|
||||
fputs(_("Show or change the real-time scheduling attributes of a process.\n"), out);
|
||||
fputs(USAGE_SEPARATOR, out);
|
||||
|
@ -169,7 +169,7 @@ static void __attribute__((__noreturn__)) show_usage(int rc)
|
|||
fputs(USAGE_VERSION, out);
|
||||
|
||||
fprintf(out, USAGE_MAN_TAIL("chrt(1)"));
|
||||
exit(rc);
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
static const char *get_policy_name(int policy)
|
||||
|
@ -494,15 +494,17 @@ int main(int argc, char **argv)
|
|||
printf(UTIL_LINUX_VERSION);
|
||||
return EXIT_SUCCESS;
|
||||
case 'h':
|
||||
show_usage(EXIT_SUCCESS);
|
||||
usage();
|
||||
default:
|
||||
errtryhelp(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
if (((ctl->pid > -1) && argc - optind < 1) ||
|
||||
((ctl->pid == -1) && argc - optind < 2))
|
||||
show_usage(EXIT_FAILURE);
|
||||
((ctl->pid == -1) && argc - optind < 2)) {
|
||||
warnx(_("bad usage"));
|
||||
errtryhelp(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if ((ctl->pid > -1) && (ctl->verbose || argc - optind == 1)) {
|
||||
show_sched_info(ctl);
|
||||
|
|
|
@ -188,9 +188,9 @@ static int parse_iflag(char *str, int *set_iflag, int *clr_iflag)
|
|||
}
|
||||
|
||||
|
||||
static void __attribute__ ((__noreturn__)) usage(int exitcode)
|
||||
static void __attribute__((__noreturn__)) usage(void)
|
||||
{
|
||||
FILE *out = exitcode == EXIT_SUCCESS ? stdout : stderr;
|
||||
FILE *out = stdout;
|
||||
|
||||
fputs(USAGE_HEADER, out);
|
||||
fprintf(out, _(" %s [options] <ldisc> <device>\n"), program_invocation_short_name);
|
||||
|
@ -224,7 +224,7 @@ static void __attribute__ ((__noreturn__)) usage(int exitcode)
|
|||
print_table(out, ld_iflags);
|
||||
|
||||
fprintf(out, USAGE_MAN_TAIL("ldattach(8)"));
|
||||
exit(exitcode);
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
static int my_cfsetspeed(struct termios *ts, int speed)
|
||||
|
@ -315,7 +315,8 @@ int main(int argc, char **argv)
|
|||
|
||||
/* parse options */
|
||||
if (argc == 0)
|
||||
usage(EXIT_SUCCESS);
|
||||
errx(EXIT_FAILURE, _("bad usage"));
|
||||
|
||||
while ((optc =
|
||||
getopt_long(argc, argv, "dhV78neo12s:i:c:p:", opttbl,
|
||||
NULL)) >= 0) {
|
||||
|
@ -354,15 +355,16 @@ int main(int argc, char **argv)
|
|||
printf(UTIL_LINUX_VERSION);
|
||||
return EXIT_SUCCESS;
|
||||
case 'h':
|
||||
usage(EXIT_SUCCESS);
|
||||
usage();
|
||||
default:
|
||||
errtryhelp(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
if (argc - optind != 2)
|
||||
usage(EXIT_FAILURE);
|
||||
|
||||
if (argc - optind != 2) {
|
||||
warnx(_("not enough arguments"));
|
||||
errtryhelp(EXIT_FAILURE);
|
||||
}
|
||||
/* parse line discipline specification */
|
||||
ldisc = lookup_table(ld_discs, argv[optind]);
|
||||
if (ldisc < 0)
|
||||
|
|
Loading…
Reference in New Issue