chiark / gitweb /
coredumpctl: add --no-legend option
[elogind.git] / src / journal / coredumpctl.c
index 311c18b6ab8d362e48868796d7ed29ab466ae3ef..e1b5a1997555c9a933bd7ab90b2f3f0a8242865f 100644 (file)
@@ -45,6 +45,7 @@ static Set *matches = NULL;
 static FILE* output = NULL;
 
 static int arg_no_pager = false;
+static int arg_no_legend = false;
 
 static Set *new_matches(void) {
         Set *set;
@@ -138,15 +139,18 @@ static int parse_argv(int argc, char *argv[]) {
         enum {
                 ARG_VERSION = 0x100,
                 ARG_NO_PAGER,
+                ARG_NO_LEGEND,
         };
 
         int r, c;
 
         static const struct option options[] = {
-                { "help",         no_argument,       NULL, 'h'              },
-                { "version" ,     no_argument,       NULL, ARG_VERSION      },
-                { "no-pager",     no_argument,       NULL, ARG_NO_PAGER     },
-                { "output",       required_argument, NULL, 'o'              },
+                { "help",         no_argument,       NULL, 'h'           },
+                { "version" ,     no_argument,       NULL, ARG_VERSION   },
+                { "no-pager",     no_argument,       NULL, ARG_NO_PAGER  },
+                { "no-legend",    no_argument,       NULL, ARG_NO_LEGEND },
+                { "output",       required_argument, NULL, 'o'           },
+                { NULL,           0,                 NULL, 0             }
         };
 
         assert(argc >= 0);
@@ -170,6 +174,10 @@ static int parse_argv(int argc, char *argv[]) {
                         arg_no_pager = true;
                         break;
 
+                case ARG_NO_LEGEND:
+                        arg_no_legend = true;
+                        break;
+
                 case 'o':
                         if (output) {
                                 log_error("cannot set output more than once");
@@ -183,6 +191,10 @@ static int parse_argv(int argc, char *argv[]) {
                         }
 
                         break;
+
+                case '?':
+                        return -EINVAL;
+
                 default:
                         log_error("Unknown option code %c", c);
                         return -EINVAL;
@@ -237,7 +249,7 @@ static int retrieve(const void *data,
         return 0;
 }
 
-static int print_entry(FILE* file, sd_journal *j, int had_header) {
+static int print_entry(FILE* file, sd_journal *j, int had_legend) {
         const char _cleanup_free_
                 *pid = NULL, *uid = NULL, *gid = NULL,
                 *sgnl = NULL, *exe = NULL;
@@ -273,7 +285,7 @@ static int print_entry(FILE* file, sd_journal *j, int had_header) {
 
         format_timestamp(buf, sizeof(buf), t);
 
-        if (!had_header)
+        if (!had_legend && !arg_no_legend)
                 fprintf(file, "%-*s %*s %*s %*s %*s %s\n",
                         FORMAT_TIMESTAMP_MAX-1, "TIME",
                         6, "PID",
@@ -471,10 +483,13 @@ int main(int argc, char *argv[]) {
         log_open();
 
         matches = new_matches();
-        if (!matches)
+        if (!matches) {
+                r = -ENOMEM;
                 goto end;
+        }
 
-        if (parse_argv(argc, argv))
+        r = parse_argv(argc, argv);
+        if (r < 0)
                 goto end;
 
         if (arg_action == ACTION_NONE)