[PATCH v5] Print absolute paths in printpathn when -yy is used

Zubin Mithra zubin.mithra at gmail.com
Mon Aug 11 04:01:25 UTC 2014


Hi Dmitry,

On Mon, Aug 11, 2014 at 8:50 AM, Zubin Mithra <zubin.mithra at gmail.com>
wrote:

> Hi Dmitry,
>
>
>> No, -y should not change, conversion of all relative paths to absolute
>> should be controlled by another option.
>>
>
> Thanks, got it. Currently I'm using the -A option for absolute path
> decoding.
>
>
>> When descriptors decoding is enabled, descriptors passed to *at syscalls
>> are decoded anyway, so we could use this information to decode relative
>> paths passed to *at syscalls.
>>
>
> 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).
>
> sys_symlinkat(const char *oldname, int newfd, const char *newname);
>


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).


diff --git a/util.c b/util.c
index c78e962..57ea9fe 100644
--- a/util.c
+++ b/util.c
@@ -559,6 +559,60 @@ string_quote(const char *instr, char *outstr, long
len, int size)
  return 0;
 }
+
+/* Returns the index of the dirfd to be decoded if the syscall
+ * is a *at syscall */
+static bool
+is_at_syscall(struct tcb *tcp)
+{
+ if  (tcp->s_ent->sys_func == sys_openat     ||
+     tcp->s_ent->sys_func == sys_mkdirat    ||
+     tcp->s_ent->sys_func == sys_mknodat    ||
+     tcp->s_ent->sys_func == sys_fchownat   ||
+     tcp->s_ent->sys_func == sys_futimesat  ||
+     tcp->s_ent->sys_func == sys_newfstatat ||
+     tcp->s_ent->sys_func == sys_unlinkat   ||
+     tcp->s_ent->sys_func == sys_renameat   ||
+     tcp->s_ent->sys_func == sys_linkat     ||
+     tcp->s_ent->sys_func == sys_readlinkat ||
+     tcp->s_ent->sys_func == sys_fchmodat   ||
+     tcp->s_ent->sys_func == sys_faccessat)
+ return 0;
+ else if (tcp->s_ent->sys_func == sys_symlinkat)
+ return 1;
+ return -1;
+}
+
 /*
  * Print path string specified by address `addr' and length `n'.
  * If path length exceeds `n', append `...' to the output.
@@ -584,11 +638,29 @@ printpathn(struct tcb *tcp, long addr, int n)
  tprintf("%#lx", addr);
  else {
  char *outstr;
+ bool prefix_printed = false;

  path[n] = '\0';
+ if (show_abs_path && *path && *path != '/') {
+ int index = is_at_syscall(tcp);
+ if (index == -1)
+ prefix_printed = print_tracee_cwd(tcp);
+ else {
+ char path[PATH_MAX + 1];
+ if (getfdpath(tcp, tcp->u_arg[index], path,
+            sizeof(path)) >= 0) {
+ prefix_printed = true;
+ tprintf("\"%s", path);
+ }
+ }
+ }
  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 (prefix_printed)
+ outstr += 1;
  tprints(outstr);
  if (!nul_seen)
  tprints("...");


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?


Thanks
-- zm
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.strace.io/pipermail/strace-devel/attachments/20140811/e6b4dddd/attachment.html>


More information about the Strace-devel mailing list