diff options
-rw-r--r-- | src/journal/coredumpctl.c | 31 | ||||
-rw-r--r-- | src/shared/util.h | 2 |
2 files changed, 24 insertions, 9 deletions
diff --git a/src/journal/coredumpctl.c b/src/journal/coredumpctl.c index 9dac169cc5..7cf6b4590b 100644 --- a/src/journal/coredumpctl.c +++ b/src/journal/coredumpctl.c @@ -232,12 +232,15 @@ static int retrieve(const void *data, return 0; } -static void print_entry(FILE* file, sd_journal *j, int had_header) { +static int print_entry(FILE* file, sd_journal *j, int had_header) { const char _cleanup_free_ *pid = NULL, *uid = NULL, *gid = NULL, *sgnl = NULL, *exe = NULL; const void *d; size_t l; + usec_t t; + char buf[FORMAT_TIMESTAMP_MAX]; + int r; SD_JOURNAL_FOREACH_DATA(j, d, l) { retrieve(d, l, "COREDUMP_PID", &pid); @@ -253,24 +256,36 @@ static void print_entry(FILE* file, sd_journal *j, int had_header) { } if (!pid && !uid && !gid && !sgnl && !exe) { - log_warning("empty coredump log entry"); - return; + log_warning("Empty coredump log entry"); + return -EINVAL; + } + + r = sd_journal_get_realtime_usec(j, &t); + if (r < 0) { + log_error("Failed to get realtime timestamp: %s", strerror(-r)); + return r; } + format_timestamp(buf, sizeof(buf), t); + if (!had_header) - fprintf(file, "%*s %*s %*s %*s %s\n", + fprintf(file, "%-*s %*s %*s %*s %*s %s\n", + FORMAT_TIMESTAMP_MAX-1, "TIME", 6, "PID", 5, "UID", 5, "GID", - 3, "sig", - "exe"); + 3, "SIG", + "EXE"); - fprintf(file, "%*s %*s %*s %*s %s\n", + fprintf(file, "%*s %*s %*s %*s %*s %s\n", + FORMAT_TIMESTAMP_MAX-1, buf, 6, pid, 5, uid, 5, gid, 3, sgnl, exe); + + return 0; } static int dump_list(sd_journal *j) { @@ -282,7 +297,7 @@ static int dump_list(sd_journal *j) { print_entry(stdout, j, found++); if (!found) { - log_error("no coredumps found"); + log_notice("No coredumps found"); return -ESRCH; } diff --git a/src/shared/util.h b/src/shared/util.h index a9c39b867e..8935beea2b 100644 --- a/src/shared/util.h +++ b/src/shared/util.h @@ -79,7 +79,7 @@ union dirent_storage { #define QUOTES "\"\'" #define COMMENTS "#;\n" -#define FORMAT_TIMESTAMP_MAX 64 +#define FORMAT_TIMESTAMP_MAX (5+11+9+4+1) #define FORMAT_TIMESTAMP_PRETTY_MAX 256 #define FORMAT_TIMESPAN_MAX 64 #define FORMAT_BYTES_MAX 8 |