On Sun 15 Jun 2014 09:14:05 [email protected] wrote: > From: Zubin Mithra <[email protected]> > > * defs.h (show_fd_path): Change type to unsigned int. > * strace.c (show_fd_path): Update usage to count y flag. > * util.c (print_tracee_cwd): New function. > (printpathn): Update to use print_tracee_cwd and print > absolute path. > * strace.1: Add description of -yy option
you should also update the usage string so `strace -h` documents -yy
> +int
> +print_tracee_cwd(struct tcb *tcp)
> +{
> + int link_size = sizeof("/proc/%u/cwd") + sizeof(int) * 3;
> + char linkpath[link_size];
> + char cwd[MAXPATHLEN+2];
there should be spaces around that +
> + ssize_t n;
> +
> + snprintf(linkpath, link_size, "/proc/%u/cwd", tcp->pid);
> + n = readlink(linkpath, cwd, MAXPATHLEN);
anytime you start using magic constant lengths for paths, you know you're
probably doing something wrong. you have to remember that some systems don't
have a max path length restriction so these constants won't even be defined.
if you lstat() the path, the st_size will tell you the length, however that
has a TOCTOU race (another thread could change the working dir), so i guess
that's not really viable :(.
you could use an alloca() buffer starting at a "large enough" value to cover
most common cases (like 256) and put it into a loop -- when the return value
of readlink is equal to bufsiz, double the buffer length and try again.
i would also highlight that some systems (really just nommu) really do not
want large buffer stacks because the stack size is fixed. by putting large
values there, you can easily blow it (which this code is doing). if this
particular func matters to performance, we can use a cached malloc buffer
(that you can realloc() to increase over time).
-mike
signature.asc
Description: This is a digitally signed message part.
------------------------------------------------------------------------------ HPCC Systems Open Source Big Data Platform from LexisNexis Risk Solutions Find What Matters Most in Your Big Data with HPCC Systems Open Source. Fast. Scalable. Simple. Ideal for Dirty Data. Leverages Graph Analysis for Fast Processing & Easy Data Exploration http://p.sf.net/sfu/hpccsystems
_______________________________________________ Strace-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/strace-devel
