<div dir="ltr">Hi Dmitry,<div class="gmail_extra"><br><div class="gmail_quote">On Mon, Aug 11, 2014 at 8:50 AM, Zubin Mithra <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:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra">Hi Dmitry,</div><div class="gmail_extra">
<br><div class="gmail_quote"><div class=""><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div>
<br>
</div>No, -y should not change, conversion of all relative paths to absolute<br>
should be controlled by another option.<br></blockquote><div><br></div></div><div>Thanks, got it. Currently I'm using the -A option for absolute path decoding.</div><div class=""><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
When descriptors decoding is enabled, descriptors passed to *at syscalls<br>
are decoded anyway, so we could use this information to decode relative<br>
paths passed to *at syscalls.<br></blockquote><div><br></div></div><div>Sounds good -- however the sys_symlinkat syscall seems to be an edge case that needs to be handled separately(oldname uses cwd and newname uses newfd).</div>
<div><br></div><div>sys_symlinkat(const char *oldname, int newfd, const char *newname);</div></div></div></div></blockquote><div><br></div><div><br></div><div>Currently this is how I've implemented it(this is a portion of the diff minus the usage/documentation/variable declaration/print_tracee_cwd function for brevity).</div>
<div><br></div><div><br></div><div><div>diff --git a/util.c b/util.c</div><div>index c78e962..57ea9fe 100644</div><div>--- a/util.c</div><div>+++ b/util.c</div><div>@@ -559,6 +559,60 @@ string_quote(const char *instr, char *outstr, long len, int size)</div>
<div> <span class="" style="white-space:pre"> </span>return 0;</div><div> }</div><div>+</div><div>+/* Returns the index of the dirfd to be decoded if the syscall</div><div>+ * is a *at syscall */</div><div>+static bool</div>
<div>+is_at_syscall(struct tcb *tcp)</div><div>+{</div><div>+<span class="" style="white-space:pre"> </span>if (tcp->s_ent->sys_func == sys_openat ||</div><div>+<span class="" style="white-space:pre"> </span> tcp->s_ent->sys_func == sys_mkdirat ||</div>
<div>+<span class="" style="white-space:pre"> </span> tcp->s_ent->sys_func == sys_mknodat ||</div><div>+<span class="" style="white-space:pre"> </span> tcp->s_ent->sys_func == sys_fchownat ||</div>
<div>+<span class="" style="white-space:pre"> </span> tcp->s_ent->sys_func == sys_futimesat ||</div><div>+<span class="" style="white-space:pre"> </span> tcp->s_ent->sys_func == sys_newfstatat ||</div>
<div>+<span class="" style="white-space:pre"> </span> tcp->s_ent->sys_func == sys_unlinkat ||</div><div>+<span class="" style="white-space:pre"> </span> tcp->s_ent->sys_func == sys_renameat ||</div>
<div>+<span class="" style="white-space:pre"> </span> tcp->s_ent->sys_func == sys_linkat ||</div><div>+<span class="" style="white-space:pre"> </span> tcp->s_ent->sys_func == sys_readlinkat ||</div>
<div>+<span class="" style="white-space:pre"> </span> tcp->s_ent->sys_func == sys_fchmodat ||</div><div>+<span class="" style="white-space:pre"> </span> tcp->s_ent->sys_func == sys_faccessat)</div><div>
+<span class="" style="white-space:pre"> </span>return 0;</div><div>+<span class="" style="white-space:pre"> </span>else if (tcp->s_ent->sys_func == sys_symlinkat)</div><div>+<span class="" style="white-space:pre"> </span>return 1;</div>
<div>+<span class="" style="white-space:pre"> </span>return -1;</div><div>+}</div><div>+</div><div> /*</div><div> * Print path string specified by address `addr' and length `n'.</div><div> * If path length exceeds `n', append `...' to the output.</div>
<div>@@ -584,11 +638,29 @@ printpathn(struct tcb *tcp, long addr, int n)</div><div> <span class="" style="white-space:pre"> </span>tprintf("%#lx", addr);</div><div> <span class="" style="white-space:pre"> </span>else {</div>
<div> <span class="" style="white-space:pre"> </span>char *outstr;</div><div>+<span class="" style="white-space:pre"> </span>bool prefix_printed = false;</div><div><br></div><div> <span class="" style="white-space:pre"> </span>path[n] = '\0';</div>
<div>+<span class="" style="white-space:pre"> </span>if (show_abs_path && *path && *path != '/') {</div><div>+<span class="" style="white-space:pre"> </span>int index = is_at_syscall(tcp);</div>
<div>+<span class="" style="white-space:pre"> </span>if (index == -1)</div><div>+<span class="" style="white-space:pre"> </span>prefix_printed = print_tracee_cwd(tcp);</div><div>+<span class="" style="white-space:pre"> </span>else {</div>
<div>+<span class="" style="white-space:pre"> </span>char path[PATH_MAX + 1];</div><div>+<span class="" style="white-space:pre"> </span>if (getfdpath(tcp, tcp->u_arg[index], path,</div><div>+<span class="" style="white-space:pre"> </span> <span class="" style="white-space:pre"> </span> sizeof(path)) >= 0) {</div>
<div>+<span class="" style="white-space:pre"> </span>prefix_printed = true;</div><div>+<span class="" style="white-space:pre"> </span>tprintf("\"%s", path);</div><div>+<span class="" style="white-space:pre"> </span>}</div>
<div>+<span class="" style="white-space:pre"> </span>}</div><div>+<span class="" style="white-space:pre"> </span>}</div><div> <span class="" style="white-space:pre"> </span>n++;</div><div> <span class="" style="white-space:pre"> </span>outstr = alloca(4 * n); /* 4*(n-1) + 3 for quotes and NUL */</div>
<div> <span class="" style="white-space:pre"> </span>string_quote(path, outstr, -1, n);</div><div>+</div><div>+<span class="" style="white-space:pre"> </span>/* Dont print opening quotes if cwd is printed */</div><div>+<span class="" style="white-space:pre"> </span>if (prefix_printed)</div>
<div>+<span class="" style="white-space:pre"> </span>outstr += 1;</div><div> <span class="" style="white-space:pre"> </span>tprints(outstr);</div><div> <span class="" style="white-space:pre"> </span>if (!nul_seen)</div>
<div> <span class="" style="white-space:pre"> </span>tprints("...");</div></div><div> </div><div><br></div><div>Does this implementation look OK? In order for this to work, defs.h would need declarations of sys_openat etc. Or is adding a new header file(atsyscall.h) for containing these declarations a good idea?</div>
<div><br></div><div><br></div><div>Thanks</div><div>-- zm</div></div></div></div>