coredumpctl: show timestamps in list

This commit is contained in:
Lennart Poettering 2012-10-26 20:34:39 +02:00
parent 34741aa3e2
commit 684341b073
2 changed files with 24 additions and 9 deletions

View file

@ -232,12 +232,15 @@ static int retrieve(const void *data,
return 0; 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_ const char _cleanup_free_
*pid = NULL, *uid = NULL, *gid = NULL, *pid = NULL, *uid = NULL, *gid = NULL,
*sgnl = NULL, *exe = NULL; *sgnl = NULL, *exe = NULL;
const void *d; const void *d;
size_t l; size_t l;
usec_t t;
char buf[FORMAT_TIMESTAMP_MAX];
int r;
SD_JOURNAL_FOREACH_DATA(j, d, l) { SD_JOURNAL_FOREACH_DATA(j, d, l) {
retrieve(d, l, "COREDUMP_PID", &pid); 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) { if (!pid && !uid && !gid && !sgnl && !exe) {
log_warning("empty coredump log entry"); log_warning("Empty coredump log entry");
return; 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) 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", 6, "PID",
5, "UID", 5, "UID",
5, "GID", 5, "GID",
3, "sig", 3, "SIG",
"exe"); "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, 6, pid,
5, uid, 5, uid,
5, gid, 5, gid,
3, sgnl, 3, sgnl,
exe); exe);
return 0;
} }
static int dump_list(sd_journal *j) { static int dump_list(sd_journal *j) {
@ -282,7 +297,7 @@ static int dump_list(sd_journal *j) {
print_entry(stdout, j, found++); print_entry(stdout, j, found++);
if (!found) { if (!found) {
log_error("no coredumps found"); log_notice("No coredumps found");
return -ESRCH; return -ESRCH;
} }

View file

@ -79,7 +79,7 @@ union dirent_storage {
#define QUOTES "\"\'" #define QUOTES "\"\'"
#define COMMENTS "#;\n" #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_TIMESTAMP_PRETTY_MAX 256
#define FORMAT_TIMESPAN_MAX 64 #define FORMAT_TIMESPAN_MAX 64
#define FORMAT_BYTES_MAX 8 #define FORMAT_BYTES_MAX 8