[PATCH v3] Print absolute paths in printpathn when -yy is used

Dmitry V. Levin ldv at altlinux.org
Tue Jun 17 00:27:23 UTC 2014


Hi Zubin,

On Sun, Jun 15, 2014 at 09:14:05AM +0530, zubin.mithra at gmail.com wrote:
> --- a/defs.h
> +++ b/defs.h
> @@ -641,6 +641,7 @@ extern long getrval2(struct tcb *);
>   */
>  extern int setbpt(struct tcb *);
>  extern int clearbpt(struct tcb *);
> +int print_tracee_cwd(struct tcb *);

I still think there is no need to export this function yet.

> @@ -588,11 +588,18 @@ printpathn(struct tcb *tcp, long addr, int n)
>  		tprintf("%#lx", addr);
>  	else {
>  		char *outstr;
> +		int retval = -1;
>  
>  		path[n] = '\0';
> +		if (show_fd_path > 1 && *path && *path != '/')
> +			retval = print_tracee_cwd(tcp);
>  		n++;
>  		outstr = alloca(4 * n); /* 4*(n-1) + 3 for quotes and NUL */
>  		string_quote(path, outstr, -1, n);
> +
> +		/* Dont print opening quotes if cwd is printed */
> +		if (retval != -1)
> +			outstr += 1;
>  		tprints(outstr);
>  		if (!nul_seen)
>  			tprints("...");

I'd prefer true/false semantics for print_tracee_cwd return value, e.g.

	bool prefix_printed = false;
	...
	prefix_printed = print_tracee_cwd(tcp);
	...
	if (prefix_printed)

> @@ -1549,3 +1556,30 @@ clearbpt(struct tcb *tcp)
>  	tcp->flags &= ~TCB_BPTSET;
>  	return 0;
>  }
> +
> +int
> +print_tracee_cwd(struct tcb *tcp)

... so let's make this function static bool.

> +{
> +	int link_size = sizeof("/proc/%u/cwd") + sizeof(int) * 3;

sizeof("/proc//cwd") + sizeof(int) * 3 is sufficient, but I do not insist. :)

> +	char linkpath[link_size];
> +	char cwd[MAXPATHLEN+2];
> +	ssize_t n;
> +
> +	snprintf(linkpath, link_size, "/proc/%u/cwd", tcp->pid);
> +	n = readlink(linkpath, cwd, MAXPATHLEN);
> +
> +	if (n > 0) {
> +		char *outstr;
> +
> +		cwd[n++] = '/';
> +		cwd[n++] = '\0';
> +
> +		/* cwd has n-1 characters followed by a null */
> +		outstr = alloca(4 * n); /* 4*(n-1) + 3 for quotes and NUL */
> +		string_quote(cwd, outstr, -1, n);
> +		outstr[strlen(outstr)-1] = '\0'; /* Don't print the closing quotes */
> +		tprints(outstr);
> +		return 0;

		return true;

> +	}
> +	return -1;

	return false;

> +}

Besides that, the patch is OK.


-- 
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/20140617/df372492/attachment.bin>


More information about the Strace-devel mailing list