<div dir="ltr"><div class="gmail_extra">Hello,<br><br><div class="gmail_quote">On Tue, Jul 1, 2014 at 3:13 PM, <span dir="ltr"><<a href="mailto:zubin.mithra@gmail.com" target="_blank">zubin.mithra@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">From: Zubin Mithra <<a href="mailto:zubin.mithra@gmail.com">zubin.mithra@gmail.com</a>><br>
<br>
* defs.h (show_fd_path): Change type to unsigned int.<br>
* strace.c (show_fd_path): Update usage to count y flag.<br>
(usage): Update to add -yy option.<br>
* util.c (print_tracee_cwd): New function.<br>
(printpathn): Update to use print_tracee_cwd and print<br>
absolute path.<br>
* strace.1: Add description of -yy option.<br>
<br>
Signed-off-by: Zubin Mithra <<a href="mailto:zubin.mithra@gmail.com">zubin.mithra@gmail.com</a>><br>
---<br>
defs.h | 2 +-<br>
strace.1 | 3 +++<br>
strace.c | 5 +++--<br>
util.c | 38 ++++++++++++++++++++++++++++++++++++++<br>
4 files changed, 45 insertions(+), 3 deletions(-)<br>
<br>
diff --git a/defs.h b/defs.h<br>
index 1a3b483..050341d 100644<br>
--- a/defs.h<br>
+++ b/defs.h<br>
@@ -562,7 +562,7 @@ extern bool iflag;<br>
extern bool count_wallclock;<br>
extern unsigned int qflag;<br>
extern bool not_failing_only;<br>
-extern bool show_fd_path;<br>
+extern unsigned int show_fd_path;<br>
extern bool hide_log_until_execve;<br>
/* are we filtering traces based on paths? */<br>
extern const char **paths_selected;<br>
diff --git a/strace.1 b/strace.1<br>
index 2a24c38..4504359 100644<br>
--- a/strace.1<br>
+++ b/strace.1<br>
@@ -321,6 +321,9 @@ Print all strings in hexadecimal string format.<br>
.B \-y<br>
Print paths associated with file descriptor arguments.<br>
.TP<br>
+.B \-yy<br>
+Print absolute paths instead of relative paths everywhere.<br>
+.TP<br>
.BI "\-a " column<br>
Align return values in a specific column (default column 40).<br>
.TP<br>
diff --git a/strace.c b/strace.c<br>
index 4154cde..28e2488 100644<br>
--- a/strace.c<br>
+++ b/strace.c<br>
@@ -129,7 +129,7 @@ static int post_attach_sigstop = TCB_IGNORE_ONE_SIGSTOP;<br>
bool not_failing_only = 0;<br>
<br>
/* Show path associated with fd arguments */<br>
-bool show_fd_path = 0;<br>
+unsigned int show_fd_path = 0;<br>
<br>
static bool detach_on_execve = 0;<br>
/* Are we "strace PROG" and need to skip detach on first execve? */<br>
@@ -216,6 +216,7 @@ usage: strace [-CdffhiqrtttTvVxxy] [-I n] [-e expr]...\n\<br>
-v -- verbose mode: print unabbreviated argv, stat, termios, etc. args\n\<br>
-x -- print non-ascii strings in hex, -xx -- print all strings in hex\n\<br>
-y -- print paths associated with file descriptor arguments\n\<br>
+-yy -- print absolute paths instead of relative paths everywhere\n\<br>
-h -- print help message, -V -- print version\n\<br>
-a column -- alignment COLUMN for printing syscall results (default %d)\n\<br>
-b execve -- detach on this syscall\n\<br>
@@ -1734,7 +1735,7 @@ init(int argc, char *argv[])<br>
xflag++;<br>
break;<br>
case 'y':<br>
- show_fd_path = 1;<br>
+ show_fd_path++;<br>
break;<br>
case 'v':<br>
qualify("abbrev=none");<br>
diff --git a/util.c b/util.c<br>
index 33482d5..0c34b77 100644<br>
--- a/util.c<br>
+++ b/util.c<br>
@@ -563,6 +563,37 @@ string_quote(const char *instr, char *outstr, long len, int size)<br>
return 0;<br>
}<br>
<br>
+<br>
+/*<br>
+ * Print the current working directory of the tracee process<br>
+ */<br>
+static bool<br>
+print_tracee_cwd(struct tcb *tcp)<br>
+{<br>
+ int link_size = sizeof("/proc//cwd") + sizeof(int) * 3;<br>
+ char linkpath[link_size];<br>
+ char cwd[MAXPATHLEN + 2];<br>
+ ssize_t n;<br>
+<br>
+ snprintf(linkpath, link_size, "/proc/%u/cwd", tcp->pid);<br>
+ n = readlink(linkpath, cwd, MAXPATHLEN);<br>
+<br>
+ if (n > 0) {<br>
+ char *outstr;<br>
+<br>
+ cwd[n++] = '/';<br>
+ cwd[n++] = '\0';<br>
+<br>
+ /* cwd has n-1 characters followed by a null */<br>
+ outstr = alloca(4 * n); /* 4*(n-1) + 3 for quotes and NUL */<br>
+ string_quote(cwd, outstr, -1, n);<br>
+ outstr[strlen(outstr)-1] = '\0'; /* Don't print the closing quotes */<br>
+ tprints(outstr);<br>
+ return true;<br>
+ }<br>
+ return false;<br>
+}<br>
+<br>
/*<br>
* Print path string specified by address `addr' and length `n'.<br>
* If path length exceeds `n', append `...' to the output.<br>
@@ -588,11 +619,18 @@ printpathn(struct tcb *tcp, long addr, int n)<br>
tprintf("%#lx", addr);<br>
else {<br>
char *outstr;<br>
+ bool prefix_printed = false;<br>
<br>
path[n] = '\0';<br>
+ if (show_fd_path > 1 && *path && *path != '/')<br>
+ prefix_printed = print_tracee_cwd(tcp);<br>
n++;<br>
outstr = alloca(4 * n); /* 4*(n-1) + 3 for quotes and NUL */<br>
string_quote(path, outstr, -1, n);<br>
+<br>
+ /* Dont print opening quotes if cwd is printed */<br>
+ if (prefix_printed)<br>
+ outstr += 1;<br>
tprints(outstr);<br>
if (!nul_seen)<br>
tprints("...");<br>
<span class="HOEnZb"><font color="#888888">--<br>
1.8.4<br>
<br></font></span></blockquote><div><br></div><div>Could someone take a look at this patch please? There is a "-yy documentation part" and a "change show_fd_path to unsigned int" which need not be a part of another patch I just submitted(sockfd decoding related) if this could be merged.</div>
<div><br></div><div><br></div><div>Thanks!</div><div>-- zm</div></div><br></div></div>