Fix: Dump executable base-address with readlink
authorPaul Woegerer <paul_woegerer@mentor.com>
Tue, 25 Feb 2014 09:47:00 +0000 (10:47 +0100)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Tue, 25 Feb 2014 10:16:34 +0000 (05:16 -0500)
The previous approach only worked if the traced executable was invoked
via its fully qualified path. Using readlink to determine the full
qualified path of the traced executable works reliably even when the
traced executable is started via PATH lookup.

Signed-off-by: Paul Woegerer <paul_woegerer@mentor.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
liblttng-ust/lttng-ust-baddr.c

index 42ae630d99eadd1132025599f13c4505dd697a81..922899b44e50406042d47480e713686350a3c703 100644 (file)
@@ -154,21 +154,22 @@ static
 void dump_exec_baddr(struct extract_data *data)
 {
        void *owner = data->owner;
-       Dl_info dl_info = { 0 };
        void *base_addr_ptr;
-       char resolved_path[PATH_MAX];
+       char exe_path[PATH_MAX];
+       ssize_t exe_len;
 
        base_addr_ptr = data->exec_baddr;
        if (!base_addr_ptr)
                return;
        /*
-        * We have to use Dl_info to determine the executable full path.
+        * We have to use /proc/self/exe to determine the executable full
+        * path.
         */
-       if (!dladdr(base_addr_ptr, &dl_info))
+       exe_len = readlink("/proc/self/exe", exe_path, sizeof(exe_path) - 1);
+       if (exe_len <= 0)
                return;
-       if (!realpath(dl_info.dli_fname, resolved_path))
-               return;
-       trace_baddr(base_addr_ptr, resolved_path, 0, owner);
+       exe_path[exe_len] = '\0';
+       trace_baddr(base_addr_ptr, exe_path, 0, owner);
 }
 
 int lttng_ust_baddr_statedump(void *owner)
This page took 0.026779 seconds and 4 git commands to generate.