[PATCH] Convert relative to absolute paths in printpathn

Dmitry V. Levin ldv at altlinux.org
Sat May 31 00:09:43 UTC 2014


On Thu, May 29, 2014 at 07:46:35PM +0530, zubin.mithra at gmail.com wrote:
> From: Zubin Mithra <zubin.mithra at gmail.com>
> 
> * util.c (print_abspath): New function that converts
>   a relative to an absolute path.
> * util.c (get_tracee_cwd): New function that finds
>   the current working directory of the tracee.
> * (printpathn): Use print_abspath to print out links
>   if `-yy` flag is used.
> 
> Signed-off-by: Zubin Mithra <zubin.mithra at gmail.com>
> ---
>  defs.h |  2 ++
>  util.c | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
>  2 files changed, 70 insertions(+), 3 deletions(-)
> 
> diff --git a/defs.h b/defs.h
> index 5381e60..25d845d 100644
> --- a/defs.h
> +++ b/defs.h
> @@ -631,6 +631,8 @@ extern const char *signame(int);
>  extern void pathtrace_select(const char *);
>  extern int pathtrace_match(struct tcb *);
>  extern int getfdpath(struct tcb *, int, char *, unsigned);
> +extern int get_tracee_cwd(struct tcb *, char *);
> +extern bool print_abspath(struct tcb *, char *, int);
>  
>  extern const char *xlookup(const struct xlat *, int);
>  
> diff --git a/util.c b/util.c
> index b1f1e90..68af3ae 100644
> --- a/util.c
> +++ b/util.c
> @@ -593,9 +593,17 @@ printpathn(struct tcb *tcp, long addr, int n)
>  		n++;
>  		outstr = alloca(4 * n); /* 4*(n-1) + 3 for quotes and NUL */
>  		string_quote(path, outstr, -1, n);
> -		tprints(outstr);
> -		if (!nul_seen)
> -			tprints("...");
> +		if (show_fd_path == 2) {
> +			/* "..." is printed if the length of current working
> +			   directory + length of outstr > 4096 */
> +			if (print_abspath(tcp, outstr, nul_seen))
> +				tprints("...");
> +		}
> +		else {
> +			tprints(outstr);
> +			if (!nul_seen)
> +				tprints("...");
> +		}

In this way only the original path will be string_quote'ed, and cwd will
be left intact (try your code with strace -xx).

What I suggest is simply to fetch cwd prefix, string_quote and print it
right before the current outstr related code in printpathn.


-- 
ldv
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://lists.strace.io/pipermail/strace-devel/attachments/20140531/85b9826c/attachment.bin>


More information about the Strace-devel mailing list