[PATCH v3] Print absolute paths in printpathn when -yy is used
zubin.mithra at gmail.com
zubin.mithra at gmail.com
Sun Jun 15 03:44:05 UTC 2014
From: Zubin Mithra <zubin.mithra at gmail.com>
* 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
Signed-off-by: Zubin Mithra <zubin.mithra at gmail.com>
---
defs.h | 3 ++-
strace.1 | 3 +++
strace.c | 4 ++--
util.c | 34 ++++++++++++++++++++++++++++++++++
4 files changed, 41 insertions(+), 3 deletions(-)
diff --git a/defs.h b/defs.h
index 1a3b483..acd627d 100644
--- a/defs.h
+++ b/defs.h
@@ -562,7 +562,7 @@ extern bool iflag;
extern bool count_wallclock;
extern unsigned int qflag;
extern bool not_failing_only;
-extern bool show_fd_path;
+extern unsigned int show_fd_path;
extern bool hide_log_until_execve;
/* are we filtering traces based on paths? */
extern const char **paths_selected;
@@ -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 *);
extern const char *signame(int);
extern void pathtrace_select(const char *);
diff --git a/strace.1 b/strace.1
index c310d65..681974d 100644
--- a/strace.1
+++ b/strace.1
@@ -321,6 +321,9 @@ Print all strings in hexadecimal string format.
.B \-y
Print paths associated with file descriptor arguments.
.TP
+.B \-yy
+Print absolute paths instead of relative paths everywhere.
+.TP
.BI "\-a " column
Align return values in a specific column (default column 40).
.TP
diff --git a/strace.c b/strace.c
index 46c9d63..a17506a 100644
--- a/strace.c
+++ b/strace.c
@@ -129,7 +129,7 @@ static int post_attach_sigstop = TCB_IGNORE_ONE_SIGSTOP;
bool not_failing_only = 0;
/* Show path associated with fd arguments */
-bool show_fd_path = 0;
+unsigned int show_fd_path = 0;
static bool detach_on_execve = 0;
/* Are we "strace PROG" and need to skip detach on first execve? */
@@ -1734,7 +1734,7 @@ init(int argc, char *argv[])
xflag++;
break;
case 'y':
- show_fd_path = 1;
+ show_fd_path++;
break;
case 'v':
qualify("abbrev=none");
diff --git a/util.c b/util.c
index 33482d5..74af3e8 100644
--- a/util.c
+++ b/util.c
@@ -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("...");
@@ -1549,3 +1556,30 @@ clearbpt(struct tcb *tcp)
tcp->flags &= ~TCB_BPTSET;
return 0;
}
+
+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];
+ 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 -1;
+}
--
1.8.4
More information about the Strace-devel
mailing list