summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRuediger Meier2017-06-19 09:24:10 +0200
committerRuediger Meier2017-06-26 14:38:24 +0200
commit9325dbfd2018b2a3b510617f4aa13777fbbe23c3 (patch)
tree07b7b9f9e99a77d9575284ae5b1b5ee9eb34101a
parentflock, getopt: write --help to stdout and return 0 (diff)
downloadkernel-qcow2-util-linux-9325dbfd2018b2a3b510617f4aa13777fbbe23c3.tar.gz
kernel-qcow2-util-linux-9325dbfd2018b2a3b510617f4aa13777fbbe23c3.tar.xz
kernel-qcow2-util-linux-9325dbfd2018b2a3b510617f4aa13777fbbe23c3.zip
misc: cleanup and fix --unknownopt issues
Fixed checkusage.sh warnings: rtcwake: --unknownopt, non-empty stdout rtcwake: --unknownopt, stderr too long: 21 blockdev: --unknownopt, stderr too long: 28 lsipc: --unknownopt, stderr too long: 77 pg: --unknownopt, stderr too long: 23 renice: --unknownopt, stderr too long: 18 sulogin: --unknownopt, stderr too long: 17 write: --unknownopt, stderr too long: 12 Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
-rw-r--r--disk-utils/blockdev.c27
-rw-r--r--login-utils/sulogin.c8
-rw-r--r--sys-utils/lsipc.c9
-rw-r--r--sys-utils/renice.c20
-rw-r--r--sys-utils/rtcwake.c17
-rw-r--r--term-utils/agetty.c16
-rw-r--r--term-utils/write.c10
-rw-r--r--text-utils/pg.c13
8 files changed, 67 insertions, 53 deletions
diff --git a/disk-utils/blockdev.c b/disk-utils/blockdev.c
index 2f6681ce2..4760e021b 100644
--- a/disk-utils/blockdev.c
+++ b/disk-utils/blockdev.c
@@ -178,9 +178,11 @@ static const struct bdc bdcms[] =
}
};
-static void __attribute__ ((__noreturn__)) usage(FILE * out)
+static void __attribute__((__noreturn__)) usage(void)
{
+ FILE * out = stdout;
size_t i;
+
fprintf(out, _("\nUsage:\n"
" %1$s -V\n"
" %1$s --report [devices]\n"
@@ -197,8 +199,9 @@ static void __attribute__ ((__noreturn__)) usage(FILE * out)
fprintf(out, " %-25s %s\n", bdcms[i].name,
_(bdcms[i].help));
}
- fputc('\n', out);
- exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
+
+ fprintf(out, USAGE_MAN_TAIL("blockdev(1)"));
+ exit(EXIT_SUCCESS);
}
static int find_cmd(char *s)
@@ -225,8 +228,10 @@ int main(int argc, char **argv)
textdomain(PACKAGE);
atexit(close_stdout);
- if (argc < 2)
- usage(stderr);
+ if (argc < 2) {
+ warnx(_("not enough arguments"));
+ errtryhelp(EXIT_FAILURE);
+ }
/* -V not together with commands */
if (!strcmp(argv[1], "-V") || !strcmp(argv[1], "--version")) {
@@ -234,7 +239,7 @@ int main(int argc, char **argv)
return EXIT_SUCCESS;
}
if (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help"))
- usage(stdout);
+ usage();
/* --report not together with other commands */
if (!strcmp(argv[1], "--report")) {
@@ -267,8 +272,10 @@ int main(int argc, char **argv)
break;
}
- if (d >= argc)
- usage(stderr);
+ if (d >= argc) {
+ warnx(_("no device specified"));
+ errtryhelp(EXIT_FAILURE);
+ }
for (k = d; k < argc; k++) {
fd = open(argv[k], O_RDONLY, 0);
@@ -315,7 +322,7 @@ static void do_commands(int fd, char **argv, int d)
j = find_cmd(argv[i]);
if (j == -1) {
warnx(_("Unknown command: %s"), argv[i]);
- usage(stderr);
+ errtryhelp(EXIT_FAILURE);
}
switch (bdcms[j].argtype) {
@@ -332,7 +339,7 @@ static void do_commands(int fd, char **argv, int d)
if (i == d - 1) {
warnx(_("%s requires an argument"),
bdcms[j].name);
- usage(stderr);
+ errtryhelp(EXIT_FAILURE);
}
iarg = atoi(argv[++i]);
} else
diff --git a/login-utils/sulogin.c b/login-utils/sulogin.c
index 72bba623a..ac6a15c38 100644
--- a/login-utils/sulogin.c
+++ b/login-utils/sulogin.c
@@ -795,8 +795,9 @@ static void sushell(struct passwd *pwd)
warn(_("failed to execute %s"), "/bin/sh");
}
-static void usage(FILE *out)
+static void usage(void)
{
+ FILE *out = stdout;
fputs(USAGE_HEADER, out);
fprintf(out, _(
" %s [options] [tty device]\n"), program_invocation_short_name);
@@ -872,11 +873,10 @@ int main(int argc, char **argv)
printf(UTIL_LINUX_VERSION);
return EXIT_SUCCESS;
case 'h':
- usage(stdout);
+ usage();
return EXIT_SUCCESS;
default:
- usage(stderr);
- /* Do not exit! */
+ /* Do not exit! getopt prints a warning. */
break;
}
}
diff --git a/sys-utils/lsipc.c b/sys-utils/lsipc.c
index 3e7586b32..8ac50d67a 100644
--- a/sys-utils/lsipc.c
+++ b/sys-utils/lsipc.c
@@ -269,8 +269,9 @@ static int parse_time_mode(const char *s)
errx(EXIT_FAILURE, _("unknown time format: %s"), s);
}
-static void __attribute__ ((__noreturn__)) usage(FILE * out)
+static void __attribute__((__noreturn__)) usage(void)
{
+ FILE *out = stdout;
size_t i;
fputs(USAGE_HEADER, out);
@@ -327,7 +328,7 @@ static void __attribute__ ((__noreturn__)) usage(FILE * out)
fprintf(out, " %14s %s\n", coldescs[i].name, _(coldescs[i].help));
fprintf(out, USAGE_MAN_TAIL("lsipc(1)"));
- exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
+ exit(EXIT_SUCCESS);
}
static struct libscols_table *new_table(struct lsipc_control *ctl)
@@ -1223,12 +1224,12 @@ int main(int argc, char *argv[])
show_creat = 1;
break;
case 'h':
- usage(stdout);
+ usage();
case 'V':
printf(UTIL_LINUX_VERSION);
return EXIT_SUCCESS;
default:
- usage(stderr);
+ errtryhelp(EXIT_FAILURE);
}
}
diff --git a/sys-utils/renice.c b/sys-utils/renice.c
index bc6e3c849..a88f590fb 100644
--- a/sys-utils/renice.c
+++ b/sys-utils/renice.c
@@ -54,8 +54,9 @@ static const char *idtype[] = {
[PRIO_USER] = N_("user ID"),
};
-static void __attribute__((__noreturn__)) usage(FILE *out)
+static void __attribute__((__noreturn__)) usage(void)
{
+ FILE *out = stdout;
fputs(USAGE_HEADER, out);
fprintf(out,
_(" %1$s [-n] <priority> [-p|--pid] <pid>...\n"
@@ -75,7 +76,7 @@ static void __attribute__((__noreturn__)) usage(FILE *out)
fputs(USAGE_HELP, out);
fputs(USAGE_VERSION, out);
fprintf(out, USAGE_MAN_TAIL("renice(1)"));
- exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
+ exit(EXIT_SUCCESS);
}
static int getprio(const int which, const int who, int *prio)
@@ -127,7 +128,7 @@ int main(int argc, char **argv)
if (argc == 1) {
if (strcmp(*argv, "-h") == 0 ||
strcmp(*argv, "--help") == 0)
- usage(stdout);
+ usage();
if (strcmp(*argv, "-v") == 0 ||
strcmp(*argv, "-V") == 0 ||
@@ -142,13 +143,16 @@ int main(int argc, char **argv)
argv++;
}
- if (argc < 2)
- usage(stderr);
+ if (argc < 2) {
+ warnx(_("not enough arguments"));
+ errtryhelp(EXIT_FAILURE);
+ }
prio = strtol(*argv, &endptr, 10);
- if (*endptr)
- usage(stderr);
-
+ if (*endptr) {
+ warnx(_("invalid priorty '%s'"), *argv);
+ errtryhelp(EXIT_FAILURE);
+ }
argc--;
argv++;
diff --git a/sys-utils/rtcwake.c b/sys-utils/rtcwake.c
index de0ac4d85..86c009536 100644
--- a/sys-utils/rtcwake.c
+++ b/sys-utils/rtcwake.c
@@ -88,8 +88,9 @@ struct rtcwake_control {
dryrun:1; /* do not set alarm, suspend system, etc */
};
-static void __attribute__((__noreturn__)) usage(FILE *out)
+static void __attribute__((__noreturn__)) usage(void)
{
+ FILE *out = stdout;
fputs(USAGE_HEADER, out);
fprintf(out,
_(" %s [options]\n"), program_invocation_short_name);
@@ -113,13 +114,11 @@ static void __attribute__((__noreturn__)) usage(FILE *out)
fputs(_(" -u, --utc RTC uses UTC\n"), out);
fputs(_(" -v, --verbose verbose messages\n"), out);
- printf(USAGE_SEPARATOR);
- printf(USAGE_HELP);
- printf(USAGE_VERSION);
-
+ fputs(USAGE_SEPARATOR, out);
+ fputs(USAGE_HELP, out);
+ fputs(USAGE_VERSION, out);
printf(USAGE_MAN_TAIL("rtcwake(8)"));
-
- exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
+ exit(EXIT_SUCCESS);
}
static int is_wakeup_enabled(const char *devname)
@@ -496,9 +495,9 @@ int main(int argc, char **argv)
printf(UTIL_LINUX_VERSION);
exit(EXIT_SUCCESS);
case 'h':
- usage(stdout);
+ usage();
default:
- usage(stderr);
+ errtryhelp(EXIT_FAILURE);
}
}
diff --git a/term-utils/agetty.c b/term-utils/agetty.c
index 5b910011c..869513b22 100644
--- a/term-utils/agetty.c
+++ b/term-utils/agetty.c
@@ -308,7 +308,7 @@ static void termio_final(struct options *op,
struct termios *tp, struct chardata *cp);
static int caps_lock(char *s);
static speed_t bcode(char *s);
-static void usage(FILE * out) __attribute__((__noreturn__));
+static void usage(void) __attribute__((__noreturn__));
static void log_err(const char *, ...) __attribute__((__noreturn__))
__attribute__((__format__(printf, 1, 2)));
static void log_warn (const char *, ...)
@@ -785,9 +785,9 @@ static void parse_args(int argc, char **argv, struct options *op)
printf(UTIL_LINUX_VERSION);
exit(EXIT_SUCCESS);
case HELP_OPTION:
- usage(stdout);
+ usage();
default:
- usage(stderr);
+ errtryhelp(EXIT_FAILURE);
}
}
@@ -795,7 +795,7 @@ static void parse_args(int argc, char **argv, struct options *op)
if (argc < optind + 1) {
log_warn(_("not enough arguments"));
- usage(stderr);
+ warn(_("not enough arguments"));
}
/* Accept "tty", "baudrate tty", and "tty baudrate". */
@@ -803,8 +803,8 @@ static void parse_args(int argc, char **argv, struct options *op)
/* Assume BSD style speed. */
parse_speeds(op, argv[optind++]);
if (argc < optind + 1) {
+ log_warn(_("not enough arguments"));
warn(_("not enough arguments"));
- usage(stderr);
}
op->tty = argv[optind++];
} else {
@@ -2066,8 +2066,10 @@ static speed_t bcode(char *s)
return 0;
}
-static void __attribute__ ((__noreturn__)) usage(FILE *out)
+static void __attribute__((__noreturn__)) usage(void)
{
+ FILE *out = stdout;
+
fputs(USAGE_HEADER, out);
fprintf(out, _(" %1$s [options] <line> [<baud_rate>,...] [<termtype>]\n"
" %1$s [options] <baud_rate>,... <line> [<termtype>]\n"), program_invocation_short_name);
@@ -2112,7 +2114,7 @@ static void __attribute__ ((__noreturn__)) usage(FILE *out)
fputs(_(" --version output version information and exit\n"), out);
fprintf(out, USAGE_MAN_TAIL("agetty(8)"));
- exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
+ exit(EXIT_SUCCESS);
}
/*
diff --git a/term-utils/write.c b/term-utils/write.c
index 13d4745f9..a7b51809f 100644
--- a/term-utils/write.c
+++ b/term-utils/write.c
@@ -79,8 +79,9 @@ struct write_control {
const char *dst_tty_name;
};
-static void __attribute__((__noreturn__)) usage(FILE *out)
+static void __attribute__((__noreturn__)) usage(void)
{
+ FILE *out = stdout;
fputs(USAGE_HEADER, out);
fprintf(out,
_(" %s [options] <user> [<ttyname>]\n"),
@@ -92,9 +93,8 @@ static void __attribute__((__noreturn__)) usage(FILE *out)
fputs(USAGE_OPTIONS, out);
fputs(USAGE_HELP, out);
fputs(USAGE_VERSION, out);
-
fprintf(out, USAGE_MAN_TAIL("write(1)"));
- exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
+ exit(EXIT_SUCCESS);
}
/*
@@ -317,9 +317,9 @@ int main(int argc, char **argv)
printf(UTIL_LINUX_VERSION);
return EXIT_SUCCESS;
case 'h':
- usage(stdout);
+ usage();
default:
- usage(stderr);
+ errtryhelp(EXIT_FAILURE);
}
if (get_terminal_name(&ctl.src_tty_path, &ctl.src_tty_name, NULL) == 0) {
diff --git a/text-utils/pg.c b/text-utils/pg.c
index 50fd3c379..ce5898dc3 100644
--- a/text-utils/pg.c
+++ b/text-utils/pg.c
@@ -223,8 +223,9 @@ static void __attribute__((__noreturn__)) quit(int status)
}
/* Usage message and similar routines. */
-static void __attribute__((__noreturn__)) usage(FILE *out)
+static void __attribute__((__noreturn__)) usage(void)
{
+ FILE *out = stdout;
fputs(USAGE_HEADER, out);
fprintf(out,
_(" %s [options] [+line] [+/pattern/] [files]\n"),
@@ -250,19 +251,19 @@ static void __attribute__((__noreturn__)) usage(FILE *out)
fputs(USAGE_VERSION, out);
fprintf(out, USAGE_MAN_TAIL("pg(1)"));
- quit(out == stderr ? 2 : 0);
+ exit(0);
}
static void __attribute__((__noreturn__)) needarg(const char *s)
{
warnx(_("option requires an argument -- %s"), s);
- usage(stderr);
+ errtryhelp(2);
}
static void __attribute__((__noreturn__)) invopt(const char *s)
{
warnx(_("illegal option -- %s"), s);
- usage(stderr);
+ errtryhelp(2);
}
#ifdef HAVE_WIDECHAR
@@ -1567,7 +1568,7 @@ int main(int argc, char **argv)
argc--;
if (!strcmp(argv[arg], "--help")) {
- usage(stdout);
+ usage();
}
if (!strcmp(argv[arg], "--version")) {
@@ -1623,7 +1624,7 @@ int main(int argc, char **argv)
sflag = 1;
break;
case 'h':
- usage(stdout);
+ usage();
case 'V':
printf(UTIL_LINUX_VERSION);
return EXIT_SUCCESS;