All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH lttng-ust] Fix: Dump executable base-address with readlink
@ 2014-02-25  9:47 Paul Woegerer
  0 siblings, 0 replies; 2+ messages in thread
From: Paul Woegerer @ 2014-02-25  9:47 UTC (permalink / raw)
  To: lttng-dev, mathieu.desnoyers

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>
---
 liblttng-ust/lttng-ust-baddr.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/liblttng-ust/lttng-ust-baddr.c b/liblttng-ust/lttng-ust-baddr.c
index 42ae630..3ae4e03 100644
--- a/liblttng-ust/lttng-ust-baddr.c
+++ b/liblttng-ust/lttng-ust-baddr.c
@@ -154,21 +154,21 @@ 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)
-- 
1.8.5.2

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH lttng-ust] Fix: Dump executable base-address with readlink
       [not found] <1393321620-14770-1-git-send-email-paul_woegerer@mentor.com>
@ 2014-02-25 10:18 ` Mathieu Desnoyers
  0 siblings, 0 replies; 2+ messages in thread
From: Mathieu Desnoyers @ 2014-02-25 10:18 UTC (permalink / raw)
  To: Paul Woegerer; +Cc: lttng-dev

merged with small style updates.

Thanks!

Mathieu

----- Original Message -----
> From: "Paul Woegerer" <paul_woegerer@mentor.com>
> To: lttng-dev@lists.lttng.org, "mathieu desnoyers" <mathieu.desnoyers@efficios.com>
> Sent: Tuesday, February 25, 2014 4:47:00 AM
> Subject: [PATCH lttng-ust] Fix: Dump executable base-address with readlink
> 
> 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>
> ---
>  liblttng-ust/lttng-ust-baddr.c | 14 +++++++-------
>  1 file changed, 7 insertions(+), 7 deletions(-)
> 
> diff --git a/liblttng-ust/lttng-ust-baddr.c b/liblttng-ust/lttng-ust-baddr.c
> index 42ae630..3ae4e03 100644
> --- a/liblttng-ust/lttng-ust-baddr.c
> +++ b/liblttng-ust/lttng-ust-baddr.c
> @@ -154,21 +154,21 @@ 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)
> --
> 1.8.5.2
> 
> 

-- 
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2014-02-25 10:18 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-02-25  9:47 [PATCH lttng-ust] Fix: Dump executable base-address with readlink Paul Woegerer
     [not found] <1393321620-14770-1-git-send-email-paul_woegerer@mentor.com>
2014-02-25 10:18 ` Mathieu Desnoyers

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.