summaryrefslogtreecommitdiff
path: root/src/journal
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2014-08-02 11:12:21 -0400
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2014-08-03 21:46:07 -0400
commit601185b43da638b1c74153deae01dbd518680889 (patch)
treeb4f1bc609e57e542a03ca00553098eabbb3b196b /src/journal
parent75cd513ef830d8e00d0d2d6a64917fec533315db (diff)
Unify parse_argv style
getopt is usually good at printing out a nice error message when commandline options are invalid. It distinguishes between an unknown option and a known option with a missing arg. It is better to let it do its job and not use opterr=0 unless we actually want to suppress messages. So remove opterr=0 in the few places where it wasn't really useful. When an error in options is encountered, we should not print a lengthy help() and overwhelm the user, when we know precisely what is wrong with the commandline. In addition, since help() prints to stdout, it should not be used except when requested with -h or --help. Also, simplify things here and there.
Diffstat (limited to 'src/journal')
-rw-r--r--src/journal/cat.c15
-rw-r--r--src/journal/coredumpctl.c46
-rw-r--r--src/journal/journalctl.c10
3 files changed, 32 insertions, 39 deletions
diff --git a/src/journal/cat.c b/src/journal/cat.c
index a525bcf3e8..627c0624a5 100644
--- a/src/journal/cat.c
+++ b/src/journal/cat.c
@@ -36,18 +36,15 @@ static char *arg_identifier = NULL;
static int arg_priority = LOG_INFO;
static bool arg_level_prefix = true;
-static int help(void) {
-
+static void help(void) {
printf("%s [OPTIONS...] {COMMAND} ...\n\n"
"Execute process with stdout/stderr connected to the journal.\n\n"
" -h --help Show this help\n"
" --version Show package version\n"
" -t --identifier=STRING Set syslog identifier\n"
" -p --priority=PRIORITY Set priority value (0..7)\n"
- " --level-prefix=BOOL Control whether level prefix shall be parsed\n",
- program_invocation_short_name);
-
- return 0;
+ " --level-prefix=BOOL Control whether level prefix shall be parsed\n"
+ , program_invocation_short_name);
}
static int parse_argv(int argc, char *argv[]) {
@@ -71,12 +68,13 @@ static int parse_argv(int argc, char *argv[]) {
assert(argc >= 0);
assert(argv);
- while ((c = getopt_long(argc, argv, "+ht:p:", options, NULL)) >= 0) {
+ while ((c = getopt_long(argc, argv, "+ht:p:", options, NULL)) >= 0)
switch (c) {
case 'h':
- return help();
+ help();
+ return 0;
case ARG_VERSION:
puts(PACKAGE_STRING);
@@ -120,7 +118,6 @@ static int parse_argv(int argc, char *argv[]) {
default:
assert_not_reached("Unhandled option");
}
- }
return 1;
}
diff --git a/src/journal/coredumpctl.c b/src/journal/coredumpctl.c
index 2bc9021022..f5cf85a765 100644
--- a/src/journal/coredumpctl.c
+++ b/src/journal/coredumpctl.c
@@ -81,29 +81,6 @@ static Set *new_matches(void) {
return set;
}
-static int help(void) {
-
- printf("%s [OPTIONS...]\n\n"
- "List or retrieve coredumps from the journal.\n\n"
- "Flags:\n"
- " -h --help Show this help\n"
- " --version Print version string\n"
- " --no-pager Do not pipe output into a pager\n"
- " --no-legend Do not print the column headers.\n"
- " -1 Show information about most recent entry only\n"
- " -F --field=FIELD List all values a certain field takes\n"
- " -o --output=FILE Write output to FILE\n\n"
-
- "Commands:\n"
- " list [MATCHES...] List available coredumps (default)\n"
- " info [MATCHES...] Show detailed information about one or more coredumps\n"
- " dump [MATCHES...] Print first matching coredump to stdout\n"
- " gdb [MATCHES...] Start gdb for the first matching coredump\n"
- , program_invocation_short_name);
-
- return 0;
-}
-
static int add_match(Set *set, const char *match) {
int r = -ENOMEM;
unsigned pid;
@@ -144,6 +121,26 @@ fail:
return r;
}
+static void help(void) {
+ printf("%s [OPTIONS...]\n\n"
+ "List or retrieve coredumps from the journal.\n\n"
+ "Flags:\n"
+ " -h --help Show this help\n"
+ " --version Print version string\n"
+ " --no-pager Do not pipe output into a pager\n"
+ " --no-legend Do not print the column headers.\n"
+ " -1 Show information about most recent entry only\n"
+ " -F --field=FIELD List all values a certain field takes\n"
+ " -o --output=FILE Write output to FILE\n\n"
+
+ "Commands:\n"
+ " list [MATCHES...] List available coredumps (default)\n"
+ " info [MATCHES...] Show detailed information about one or more coredumps\n"
+ " dump [MATCHES...] Print first matching coredump to stdout\n"
+ " gdb [MATCHES...] Start gdb for the first matching coredump\n"
+ , program_invocation_short_name);
+}
+
static int parse_argv(int argc, char *argv[], Set *matches) {
enum {
ARG_VERSION = 0x100,
@@ -171,7 +168,8 @@ static int parse_argv(int argc, char *argv[], Set *matches) {
case 'h':
arg_action = ACTION_NONE;
- return help();
+ help();
+ return 0;
case ARG_VERSION:
arg_action = ACTION_NONE;
diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c
index 52fd8beb22..5c4a71d618 100644
--- a/src/journal/journalctl.c
+++ b/src/journal/journalctl.c
@@ -160,7 +160,7 @@ static int parse_boot_descriptor(const char *x, sd_id128_t *boot_id, int *offset
return 0;
}
-static int help(void) {
+static void help(void) {
pager_open_if_enabled();
@@ -218,8 +218,6 @@ static int help(void) {
" --verify Verify journal file consistency\n"
#endif
, program_invocation_short_name);
-
- return 0;
}
static int parse_argv(int argc, char *argv[]) {
@@ -306,12 +304,13 @@ static int parse_argv(int argc, char *argv[]) {
assert(argc >= 0);
assert(argv);
- while ((c = getopt_long(argc, argv, "hefo:aln::qmb::kD:p:c:u:F:xrM:", options, NULL)) >= 0) {
+ while ((c = getopt_long(argc, argv, "hefo:aln::qmb::kD:p:c:u:F:xrM:", options, NULL)) >= 0)
switch (c) {
case 'h':
- return help();
+ help();
+ return 0;
case ARG_VERSION:
puts(PACKAGE_STRING);
@@ -633,7 +632,6 @@ static int parse_argv(int argc, char *argv[]) {
default:
assert_not_reached("Unhandled option");
}
- }
if (arg_follow && !arg_no_tail && arg_lines < 0)
arg_lines = 10;