chiark / gitweb /
coredump: add 3 more metadata fields to coredump entries
authorLennart Poettering <lennart@poettering.net>
Wed, 18 Jun 2014 21:55:36 +0000 (23:55 +0200)
committerLennart Poettering <lennart@poettering.net>
Wed, 18 Jun 2014 22:00:24 +0000 (00:00 +0200)
src/journal/coredump.c
src/journal/coredumpctl.c

index a396491a4bc11e45bb8bee28f12064e957e76679..3365f9f1466e4105e34421c1e9f606c5deadfe75 100644 (file)
@@ -346,16 +346,16 @@ int main(int argc, char* argv[]) {
         _cleanup_free_ char *core_pid = NULL, *core_uid = NULL, *core_gid = NULL, *core_signal = NULL,
                 *core_timestamp = NULL, *core_comm = NULL, *core_exe = NULL, *core_unit = NULL,
                 *core_session = NULL, *core_message = NULL, *core_cmdline = NULL, *coredump_data = NULL,
         _cleanup_free_ char *core_pid = NULL, *core_uid = NULL, *core_gid = NULL, *core_signal = NULL,
                 *core_timestamp = NULL, *core_comm = NULL, *core_exe = NULL, *core_unit = NULL,
                 *core_session = NULL, *core_message = NULL, *core_cmdline = NULL, *coredump_data = NULL,
-                *coredump_filename = NULL;
+                *coredump_filename = NULL, *core_slice = NULL, *core_cgroup = NULL, *core_owner_uid = NULL;
 
         _cleanup_close_ int coredump_fd = -1;
 
 
         _cleanup_close_ int coredump_fd = -1;
 
-        struct iovec iovec[14];
+        struct iovec iovec[17];
         off_t coredump_size;
         int r, j = 0;
         off_t coredump_size;
         int r, j = 0;
-        pid_t pid;
-        uid_t uid;
+        uid_t uid, owner_uid;
         gid_t gid;
         gid_t gid;
+        pid_t pid;
         char *t;
 
         /* Make sure we never enter a loop */
         char *t;
 
         /* Make sure we never enter a loop */
@@ -459,6 +459,21 @@ int main(int argc, char* argv[]) {
                         IOVEC_SET_STRING(iovec[j++], core_session);
         }
 
                         IOVEC_SET_STRING(iovec[j++], core_session);
         }
 
+        if (sd_pid_get_owner_uid(pid, &owner_uid) >= 0) {
+                asprintf(&core_owner_uid, "COREDUMP_OWNER_UID=" UID_FMT, owner_uid);
+
+                if (core_owner_uid)
+                        IOVEC_SET_STRING(iovec[j++], core_owner_uid);
+        }
+
+        if (sd_pid_get_slice(pid, &t) >= 0) {
+                core_slice = strappend("COREDUMP_SLICE=", t);
+                free(t);
+
+                if (core_slice)
+                        IOVEC_SET_STRING(iovec[j++], core_slice);
+        }
+
         if (get_process_exe(pid, &t) >= 0) {
                 core_exe = strappend("COREDUMP_EXE=", t);
                 free(t);
         if (get_process_exe(pid, &t) >= 0) {
                 core_exe = strappend("COREDUMP_EXE=", t);
                 free(t);
@@ -475,6 +490,14 @@ int main(int argc, char* argv[]) {
                         IOVEC_SET_STRING(iovec[j++], core_cmdline);
         }
 
                         IOVEC_SET_STRING(iovec[j++], core_cmdline);
         }
 
+        if (cg_pid_get_path_shifted(pid, NULL, &t) >= 0) {
+                core_cgroup = strappend("COREDUMP_CGROUP=", t);
+                free(t);
+
+                if (core_cgroup)
+                        IOVEC_SET_STRING(iovec[j++], core_cgroup);
+        }
+
         core_timestamp = strjoin("COREDUMP_TIMESTAMP=", argv[ARG_TIMESTAMP], "000000", NULL);
         if (core_timestamp)
                 IOVEC_SET_STRING(iovec[j++], core_timestamp);
         core_timestamp = strjoin("COREDUMP_TIMESTAMP=", argv[ARG_TIMESTAMP], "000000", NULL);
         if (core_timestamp)
                 IOVEC_SET_STRING(iovec[j++], core_timestamp);
index 8699716679ec276039bce5e6d2c4bad33b9ea373..ea459469ee686dddbd15a2f35a8dc37f1e0cd495 100644 (file)
@@ -402,7 +402,8 @@ static int print_info(FILE *file, sd_journal *j, bool need_space) {
                 *pid = NULL, *uid = NULL, *gid = NULL,
                 *sgnl = NULL, *exe = NULL, *comm = NULL, *cmdline = NULL,
                 *unit = NULL, *user_unit = NULL, *session = NULL,
                 *pid = NULL, *uid = NULL, *gid = NULL,
                 *sgnl = NULL, *exe = NULL, *comm = NULL, *cmdline = NULL,
                 *unit = NULL, *user_unit = NULL, *session = NULL,
-                *boot_id = NULL, *machine_id = NULL, *hostname = NULL, *coredump = NULL;
+                *boot_id = NULL, *machine_id = NULL, *hostname = NULL,
+                *coredump = NULL, *slice = NULL, *cgroup = NULL, *owner_uid = NULL;
         const void *d;
         size_t l;
 
         const void *d;
         size_t l;
 
@@ -420,6 +421,9 @@ static int print_info(FILE *file, sd_journal *j, bool need_space) {
                 retrieve(d, l, "COREDUMP_UNIT", &unit);
                 retrieve(d, l, "COREDUMP_USER_UNIT", &user_unit);
                 retrieve(d, l, "COREDUMP_SESSION", &session);
                 retrieve(d, l, "COREDUMP_UNIT", &unit);
                 retrieve(d, l, "COREDUMP_USER_UNIT", &user_unit);
                 retrieve(d, l, "COREDUMP_SESSION", &session);
+                retrieve(d, l, "COREDUMP_OWNER_UID", &owner_uid);
+                retrieve(d, l, "COREDUMP_SLICE", &slice);
+                retrieve(d, l, "COREDUMP_CGROUP", &cgroup);
                 retrieve(d, l, "_BOOT_ID", &boot_id);
                 retrieve(d, l, "_MACHINE_ID", &machine_id);
                 retrieve(d, l, "_HOSTNAME", &hostname);
                 retrieve(d, l, "_BOOT_ID", &boot_id);
                 retrieve(d, l, "_MACHINE_ID", &machine_id);
                 retrieve(d, l, "_HOSTNAME", &hostname);
@@ -429,12 +433,42 @@ static int print_info(FILE *file, sd_journal *j, bool need_space) {
                 fputs("\n", file);
 
         fprintf(file,
                 fputs("\n", file);
 
         fprintf(file,
-                "           PID: %s\n"
-                "           UID: %s\n"
-                "           GID: %s\n",
-                strna(pid),
-                strna(uid),
-                strna(gid));
+                "           PID: %s%s%s\n",
+                ansi_highlight(), strna(pid), ansi_highlight_off());
+
+        if (uid) {
+                uid_t n;
+
+                if (parse_uid(uid, &n) >= 0) {
+                        _cleanup_free_ char *u = NULL;
+
+                        u = uid_to_name(n);
+                        fprintf(file,
+                                "           UID: %s (%s)\n",
+                                uid, u);
+                } else {
+                        fprintf(file,
+                                "           UID: %s\n",
+                                uid);
+                }
+        }
+
+        if (gid) {
+                gid_t n;
+
+                if (parse_gid(gid, &n) >= 0) {
+                        _cleanup_free_ char *g = NULL;
+
+                        g = gid_to_name(n);
+                        fprintf(file,
+                                "           GID: %s (%s)\n",
+                                gid, g);
+                } else {
+                        fprintf(file,
+                                "           GID: %s\n",
+                                gid);
+                }
+        }
 
         if (sgnl) {
                 int sig;
 
         if (sgnl) {
                 int sig;
@@ -446,17 +480,37 @@ static int print_info(FILE *file, sd_journal *j, bool need_space) {
         }
 
         if (exe)
         }
 
         if (exe)
-                fprintf(file, "    Executable: %s\n", exe);
+                fprintf(file, "    Executable: %s%s%s\n", ansi_highlight(), exe, ansi_highlight_off());
         if (comm)
                 fprintf(file, "          Comm: %s\n", comm);
         if (cmdline)
                 fprintf(file, "  Command Line: %s\n", cmdline);
         if (comm)
                 fprintf(file, "          Comm: %s\n", comm);
         if (cmdline)
                 fprintf(file, "  Command Line: %s\n", cmdline);
+        if (cgroup)
+                fprintf(file, " Control Group: %s\n", cgroup);
         if (unit)
                 fprintf(file, "          Unit: %s\n", unit);
         if (user_unit)
                 fprintf(file, "     User Unit: %s\n", unit);
         if (unit)
                 fprintf(file, "          Unit: %s\n", unit);
         if (user_unit)
                 fprintf(file, "     User Unit: %s\n", unit);
+        if (slice)
+                fprintf(file, "         Slice: %s\n", slice);
         if (session)
                 fprintf(file, "       Session: %s\n", session);
         if (session)
                 fprintf(file, "       Session: %s\n", session);
+        if (owner_uid) {
+                uid_t n;
+
+                if (parse_uid(owner_uid, &n) >= 0) {
+                        _cleanup_free_ char *u = NULL;
+
+                        u = uid_to_name(n);
+                        fprintf(file,
+                                "     Owner UID: %s (%s)\n",
+                                owner_uid, u);
+                } else {
+                        fprintf(file,
+                                "     Owner UID: %s\n",
+                                owner_uid);
+                }
+        }
         if (boot_id)
                 fprintf(file, "       Boot ID: %s\n", boot_id);
         if (machine_id)
         if (boot_id)
                 fprintf(file, "       Boot ID: %s\n", boot_id);
         if (machine_id)