crash-stack: Get executable name from cmdline 61/115561/1
authorSunmin Lee <sunm.lee@samsung.com>
Mon, 20 Feb 2017 09:46:44 +0000 (18:46 +0900)
committerSunmin Lee <sunm.lee@samsung.com>
Mon, 20 Feb 2017 09:46:44 +0000 (18:46 +0900)
The executable name in crash-stack is different with sys-assert.
In case of some applications, "exe" has indicated real path of app
that makes it hard to know what the actual app name is.
It's better to refer to "cmdline" instead.

Change-Id: I4895dbce427d50cd20a593585f2640554a4268fc
Signed-off-by: Sunmin Lee <sunm.lee@samsung.com>
src/crash-stack/crash-stack.c

index ca33a54..01c4b7f 100644 (file)
@@ -510,14 +510,22 @@ void callstack_destructor(Callstack *callstack)
  */
 static void __crash_stack_print_exe(FILE* outputfile, pid_t pid)
 {
+       int fd, ret;
        char file_path[PATH_MAX];
-       char link_path[PATH_MAX];
+       char cmd_path[PATH_MAX];
 
-       snprintf(link_path, PATH_MAX, "/proc/%d/exe", pid);
-       if (readlink(link_path, file_path, PATH_MAX) == -1) {
+       snprintf(cmd_path, PATH_MAX, "/proc/%d/cmdline", pid);
+       if ((fd = open(cmd_path, O_RDONLY)) < 0)
+               return;
+
+       if ((ret = read(fd, file_path, sizeof(file_path))) <= 0) {
+               close(fd);
                return;
        }
+       file_path[ret] = '\0';
+
        fprintf(outputfile, "Executable File Path: %s\n", file_path);
+       close(fd);
 }
 
 /**