Hi Zubin,

On Sun, Jun 15, 2014 at 09:14:05AM +0530, zubin.mit...@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

Attachment: pgpxWnh2svE9v.pgp
Description: PGP signature

------------------------------------------------------------------------------
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
Strace-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/strace-devel

Reply via email to