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