chiark / gitweb /
clients: unify how we invoke getopt_long()
[elogind.git] / src / journal / coredumpctl.c
index 0bbfff2ecdc30aec0afac4c0eb7590822b7ac048..bcfee46da1d989b273f77ec14a911d50c40758de 100644 (file)
@@ -68,10 +68,9 @@ static Set *new_matches(void) {
                 return NULL;
         }
 
-        r = set_put(set, tmp);
+        r = set_consume(set, tmp);
         if (r < 0) {
                 log_error("failed to add to set: %s", strerror(-r));
-                free(tmp);
                 set_free(set);
                 return NULL;
         }
@@ -85,6 +84,7 @@ static int help(void) {
                "Flags:\n"
                "  -o --output=FILE  Write output to FILE\n"
                "     --no-pager     Do not pipe output into a pager\n"
+               "     --no-legend    Do not print the column headers.\n\n"
 
                "Commands:\n"
                "  -h --help         Show this help\n"
@@ -125,18 +125,17 @@ static int add_match(Set *set, const char *match) {
         if (!pattern)
                 goto fail;
 
-        r = set_put(set, pattern);
+        log_debug("Adding pattern: %s", pattern);
+        r = set_consume(set, pattern);
         if (r < 0) {
-                log_error("failed to add pattern '%s': %s",
+                log_error("Failed to add pattern '%s': %s",
                           pattern, strerror(-r));
                 goto fail;
         }
-        log_debug("Added pattern: %s", pattern);
 
         return 0;
 fail:
-        free(pattern);
-        log_error("failed to add match: %s", strerror(-r));
+        log_error("Failed to add match: %s", strerror(-r));
         return r;
 }
 
@@ -156,7 +155,7 @@ static int parse_argv(int argc, char *argv[], Set *matches) {
                 { "no-legend",    no_argument,       NULL, ARG_NO_LEGEND },
                 { "output",       required_argument, NULL, 'o'           },
                 { "field",        required_argument, NULL, 'F'           },
-                { NULL,           0,                 NULL, 0             }
+                {}
         };
 
         assert(argc >= 0);
@@ -164,15 +163,15 @@ static int parse_argv(int argc, char *argv[], Set *matches) {
 
         while ((c = getopt_long(argc, argv, "ho:F:", options, NULL)) >= 0)
                 switch(c) {
+
                 case 'h':
-                        help();
                         arg_action = ACTION_NONE;
-                        return 0;
+                        return help();
 
                 case ARG_VERSION:
+                        arg_action = ACTION_NONE;
                         puts(PACKAGE_STRING);
                         puts(SYSTEMD_FEATURES);
-                        arg_action = ACTION_NONE;
                         return 0;
 
                 case ARG_NO_PAGER:
@@ -210,8 +209,7 @@ static int parse_argv(int argc, char *argv[], Set *matches) {
                         return -EINVAL;
 
                 default:
-                        log_error("Unknown option code %c", c);
-                        return -EINVAL;
+                        assert_not_reached("Unhandled option");
                 }
 
         if (optind < argc) {
@@ -343,7 +341,7 @@ static int dump_list(sd_journal *j) {
         assert(j);
 
         /* The coredumps are likely to compressed, and for just
-         * listing them we don#t need to decompress them, so let's
+         * listing them we don't need to decompress them, so let's
          * pick a fairly low data threshold here */
         sd_journal_set_data_threshold(j, 4096);
 
@@ -558,6 +556,13 @@ int main(int argc, char *argv[]) {
                 }
         }
 
+        if (_unlikely_(log_get_max_level() >= LOG_PRI(LOG_DEBUG))) {
+                _cleanup_free_ char *filter;
+
+                filter = journal_make_match_string(j);
+                log_debug("Journal filter: %s", filter);
+        }
+
         switch(arg_action) {
 
         case ACTION_LIST: