Change the way the process name is reading 35/227535/2
authorMateusz Moscicki <m.moscicki2@partner.samsung.com>
Wed, 11 Mar 2020 09:38:38 +0000 (10:38 +0100)
committerMateusz Moscicki <m.moscicki2@partner.samsung.com>
Thu, 12 Mar 2020 11:20:46 +0000 (12:20 +0100)
Applications launched by process pool have a modified
/proc/<pid>/cmdline, so cmdline must be treated in a specific way.  Now
the process name is the content of /proc/<pid>/cmdline to the first
occurrence of ' ' (space) or '\0' (NULL byte).

Change-Id: I3af1b9d1df86540b16ea238baa0f03152545e408
Signed-off-by: Mateusz Moscicki <m.moscicki2@partner.samsung.com>
src/crash-manager/crash-manager.c

index 1154283..7e88660 100644 (file)
@@ -309,6 +309,24 @@ close_fd:
        return -1;
 }
 
+void get_proc_name(const char *cmd_line, char *buff, size_t buff_len)
+{
+       assert(buff != NULL);
+       char *space = strchr(cmd_line, ' ');
+       size_t name_len;
+
+       if (space == NULL)
+               name_len = strlen(cmd_line);
+       else
+               name_len = space - cmd_line;
+
+       if (name_len > buff_len - 1)
+               name_len = buff_len - 1;
+
+       strncpy(buff, cmd_line, name_len);
+
+       buff[name_len] = '\0';
+}
 
 static void set_crash_info_defaults(struct crash_info *cinfo)
 {
@@ -347,12 +365,14 @@ bool set_crash_info(struct crash_info *cinfo)
                return false;
        }
 
+       char proc_name[PATH_MAX];
+       get_proc_name(cinfo->cmd_line, proc_name, sizeof(proc_name));
        const char *suffix = config.report_type >= REP_TYPE_FULL ? (config.allow_zip ? ".zip" : "") : ".info";
        bool is_app = set_appinfo(cinfo->cmd_line, &cinfo->appid, &cinfo->pkgid);
        if (!cinfo->appid || !cinfo->pkgid)
                goto out_oom;
 
-       if (-1 == asprintf(&cinfo->name,        "%s_%d_%s",       is_app ? cinfo->pkgid : basename(cinfo->cmd_path), cinfo->pid_info, date)
+       if (-1 == asprintf(&cinfo->name,        "%s_%d_%s",       is_app ? cinfo->pkgid : basename(proc_name), cinfo->pid_info, date)
         || -1 == asprintf(&cinfo->pfx,         "%s/%s",          cinfo->temp_dir, cinfo->name)
         || -1 == asprintf(&cinfo->info_path,   "%s/%s.info",     cinfo->pfx, cinfo->name)
         || -1 == asprintf(&cinfo->core_path,   "%s/%s.coredump", cinfo->pfx, cinfo->name)
@@ -528,6 +548,9 @@ static bool execute_minicoredump(struct crash_info *cinfo, int *exit_code)
 
        const char *without_core_str = config.dump_core ? NULL : "-s";
 
+       char proc_name[PATH_MAX];
+       get_proc_name(cinfo->cmd_line, proc_name, sizeof(proc_name));
+
        /* Execute minicoredumper */
        char *args[] = {
                        MINICOREDUMPER_BIN_PATH,   // minicoredumper filename path
@@ -537,7 +560,7 @@ static bool execute_minicoredump(struct crash_info *cinfo, int *exit_code)
                        sig_str,                   // %s - number of signal
                        time_str,                  // %t - time of dump
                        "localhost",               // %h - hostname
-                       basename(cinfo->cmd_path), // %e - exe name (need for result filename)
+                       basename(proc_name), // %e - exe name (need for result filename)
                        MINICOREDUMPER_CONFIG_PATH, // config file
                        "-d",
                        cinfo->pfx,            // temp dir