Read the /proc/<PID>/comm earlier 95/234095/2
authorMateusz Moscicki <m.moscicki2@partner.samsung.com>
Thu, 21 May 2020 10:55:24 +0000 (12:55 +0200)
committerMateusz Moscicki <m.moscicki2@partner.samsung.com>
Fri, 22 May 2020 13:09:10 +0000 (15:09 +0200)
Change-Id: Ied692bc4e770c9aa3b8f03f7a2515214bc40cb63

src/crash-manager/crash-manager.c
src/crash-manager/crash-manager.h

index 42044be..6011369 100644 (file)
@@ -299,6 +299,13 @@ static bool get_cmd_info(struct crash_info *cinfo)
        if (!cinfo->cmd_line)
                return false;
 
+       if (!read_proc_file(cinfo->tid_info, "comm", buf, sizeof(buf), filter_drop_trailing_whitespace))
+               goto err;
+
+       cinfo->comm = strdup(buf);
+       if (!cinfo->comm)
+               goto err;
+
        if (!get_exe_path(cinfo->pid_info, buf, sizeof(buf)))
                goto err;
 
@@ -311,6 +318,8 @@ static bool get_cmd_info(struct crash_info *cinfo)
 err:
        free(cinfo->cmd_line);
        cinfo->cmd_line = NULL;
+       free(cinfo->comm);
+       cinfo->comm = NULL;
        return false;
 }
 
@@ -616,9 +625,6 @@ static void launch_dbus_notify(struct crash_info *cinfo)
 
        char pid_str[11], tid_str[11], sig_str[11];
        char *prstatus_fd_str = NULL;
-       char tid_comm_str[KERNEL_DEFINED_TASK_COMM_LEN + 1] = { 0, };
-
-       (void)read_proc_file(cinfo->tid_info, "comm", tid_comm_str, sizeof(tid_comm_str), filter_drop_trailing_whitespace);
 
        if (asprintf(&prstatus_fd_str, "%d", cinfo->prstatus_fd) == -1) {
                _E("Unable to allocate memory: %m");
@@ -641,7 +647,7 @@ static void launch_dbus_notify(struct crash_info *cinfo)
                        "--reportpath", cinfo->result_path,
                        "--prstatus_fd", prstatus_fd_str,
                        "--signal", sig_str,
-                       "--tid-comm", tid_comm_str,
+                       "--tid-comm", cinfo->comm,
                        legacy_notification_str,
                        NULL };
 
@@ -1208,6 +1214,7 @@ static void free_crash_info(struct crash_info *cinfo)
 {
        free(cinfo->cmd_line);
        free(cinfo->cmd_path);
+       free(cinfo->comm);
        free(cinfo->temp_dir);
        free(cinfo->result_path);
        free(cinfo->app_root_path);
@@ -1233,6 +1240,7 @@ void crash_info_init(struct crash_info *cinfo)
        cinfo->executable_path = NULL;
        cinfo->cmd_line = NULL;
        cinfo->cmd_path = NULL;
+       cinfo->comm = NULL;
        cinfo->temp_dir = NULL;
        cinfo->app_root_path = NULL;
        cinfo->pfx = NULL;
index 320ef41..bd4f85b 100644 (file)
@@ -36,6 +36,7 @@ struct crash_info {
        int prstatus_fd;
        char *cmd_line;
        char *cmd_path;
+       char *comm;
        char *temp_dir;
        char *name;
        char *app_root_path;