coredumpctl: rework presence reporting
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 26 Sep 2016 23:41:38 +0000 (01:41 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 28 Sep 2016 21:49:01 +0000 (23:49 +0200)
The column for "present" was easy to miss, especially if somebody had no
coredumps present at all, in which case the column of spaces of width one
wasn't visually distinguished from the neighbouring columns. Replace this
with an explicit text, one of: "missing", "journal", "present", "error".

$ coredumpctl
TIME                            PID   UID   GID SIG COREFILE EXE
Mon 2016-09-26 22:46:31 CEST   8623     0     0  11 missing  /usr/bin/bash
Mon 2016-09-26 22:46:35 CEST   8639  1001  1001  11 missing  /usr/bin/bash
Tue 2016-09-27 01:10:46 CEST  16110  1001  1001  11 journal  /usr/bin/bash
Tue 2016-09-27 01:13:20 CEST  16290  1001  1001  11 journal  /usr/bin/bash
Tue 2016-09-27 01:33:48 CEST  17867  1001  1001  11 present  /usr/bin/bash
Tue 2016-09-27 01:37:55 CEST  18549     0     0  11 error    /usr/bin/bash

Also, use access(…, R_OK), so that we can report a present but inaccessible
file different than a missing one.

src/coredump/coredumpctl.c

index 15ffd56..57d1800 100644 (file)
@@ -310,7 +310,7 @@ static int print_list(FILE* file, sd_journal *j, int had_legend) {
         usec_t t;
         char buf[FORMAT_TIMESTAMP_MAX];
         int r;
-        bool present;
+        const char *present;
 
         assert(file);
         assert(j);
@@ -337,7 +337,6 @@ static int print_list(FILE* file, sd_journal *j, int had_legend) {
                 return log_error_errno(r, "Failed to get realtime timestamp: %m");
 
         format_timestamp(buf, sizeof(buf), t);
-        present = (filename && access(filename, F_OK) == 0) || coredump;
 
         if (!had_legend && !arg_no_legend)
                 fprintf(file, "%-*s %*s %*s %*s %*s %*s %s\n",
@@ -346,16 +345,28 @@ static int print_list(FILE* file, sd_journal *j, int had_legend) {
                         5, "UID",
                         5, "GID",
                         3, "SIG",
-                        1, "PRESENT",
+                        8, "COREFILE",
                            "EXE");
 
-        fprintf(file, "%-*s %*s %*s %*s %*s %*s %s\n",
+        if (filename)
+                if (access(filename, R_OK) == 0)
+                        present = "present";
+                else if (errno == ENOENT)
+                        present = "missing";
+                else
+                        present = "error";
+        else if (coredump)
+                present = "journal";
+        else
+                present = "none";
+
+        fprintf(file, "%-*s %*s %*s %*s %*s %-*s %s\n",
                 FORMAT_TIMESTAMP_WIDTH, buf,
                 6, strna(pid),
                 5, strna(uid),
                 5, strna(gid),
                 3, strna(sgnl),
-                1, present ? "*" : "",
+                8, present,
                 strna(exe ?: (comm ?: cmdline)));
 
         return 0;
@@ -510,7 +521,7 @@ static int print_info(FILE *file, sd_journal *j, bool need_space) {
 
         if (filename)
                 fprintf(file, "       Storage: %s%s\n", filename,
-                        access(filename, F_OK) < 0 ? " (inaccessible)" : "");
+                        access(filename, R_OK) < 0 ? " (inaccessible)" : "");
         else if (coredump)
                 fprintf(file, "       Storage: journal\n");
         else