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

Mike Frysinger vapier at gentoo.org
Tue Jun 17 02:29:48 UTC 2014


On Tue 17 Jun 2014 04:27:23 Dmitry V. Levin wrote:
> On Sun, Jun 15, 2014 at 09:14:05AM +0530, zubin.mithra at gmail.com wrote:
> > +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.

maybe:
	const char fmt[] = "/proc/%u/cwd";
	size_t link_size = sizeof(fmt) ...
	...
	snprintf(linkpath, link_size, fmt, ...);

i'd also highlight:
 - snprintf 2nd arg is size_t, not int
 - return value of snprintf really needs to be checked
 - assuming sizeof(int) * 3 is large enough to hold the string representation 
of a number is really bad form.  sure, it works, but it's ugly as sin.

all that said, this is exactly the sort of thing asprintf() was invented.  so 
really we should delete all this logic and do:
	char *path = asprintf("/proc/%u/cwd", tcp->pid);
	if (!path)
		return false;
	... do stuff with path ...
	free(path);
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.strace.io/pipermail/strace-devel/attachments/20140616/3c163225/attachment.bin>


More information about the Strace-devel mailing list