[PATCH] Decode paths associated with file descriptors returned by syscalls

Dmitry V. Levin ldv at altlinux.org
Fri May 30 01:11:43 UTC 2014


On Wed, May 28, 2014 at 09:20:04PM +0530, zubin.mithra at gmail.com wrote:
> From: Zubin Mithra <zubin.mithra at gmail.com>
> 
> * Type of `show_fd_path` changed from `bool` to `unsigned int` to
>   support the `-yy` flag.

This change is no longer needed in this patch.

> * util.c (returns_fd): New function that checks if the tcb refers
>   to a function that returns a file descriptor.
> * (trace_syscall_exiting): Use returns_fd to determine whether
>   tcp->u_rval is a file descriptor.

Please have a look at GNU ChangeLog style guideline:
http://www.gnu.org/prep/standards/html_node/Change-Logs.html

* defs.h (returns_fd): New prototype.
* util.c (returns_fd): New function that checks if the tcb refers
to a function that returns a file descriptor.
* syscall.c (trace_syscall_exiting): Use returns_fd to determine whether
tcp->u_rval is a file descriptor.

> diff --git a/syscall.c b/syscall.c
> index 28bdb66..4932bbe 100644
> --- a/syscall.c
> +++ b/syscall.c
> @@ -2669,7 +2669,12 @@ trace_syscall_exiting(struct tcb *tcp)
>  				tprintf("= %lu", tcp->u_rval);
>  				break;
>  			case RVAL_DECIMAL:
> -				tprintf("= %ld", tcp->u_rval);
> +				if ( show_fd_path && returns_fd(tcp) ) {

Please don't add a space after the opening parenthesis and before the
closing parenthesis.

> diff --git a/util.c b/util.c
> index ff18b87..b1f1e90 100644
> --- a/util.c
> +++ b/util.c
> @@ -1549,3 +1549,16 @@ clearbpt(struct tcb *tcp)
>  	tcp->flags &= ~TCB_BPTSET;
>  	return 0;
>  }
> +
> +bool
> +returns_fd(struct tcb *tcp)
> +{
> +	if ( tcp->s_ent->sys_func == sys_open   ||
> +	     tcp->s_ent->sys_func == sys_openat ||
> +	     tcp->s_ent->sys_func == sys_creat  ||
> +	     tcp->s_ent->sys_func == sys_dup    ||
> +	     tcp->s_ent->sys_func == sys_dup2   ||
> +	     tcp->s_ent->sys_func == sys_dup3 )
> +		return 1;
> +	return 0;
> +}

This could be simplified to
	return tcp->s_ent->sys_func == sys_open   ||
	       tcp->s_ent->sys_func == sys_openat ||
	       tcp->s_ent->sys_func == sys_creat  ||
	       tcp->s_ent->sys_func == sys_dup    ||
	       tcp->s_ent->sys_func == sys_dup2   ||
	       tcp->s_ent->sys_func == sys_dup3;


-- 
ldv
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://lists.strace.io/pipermail/strace-devel/attachments/20140530/f0d90abc/attachment.bin>


More information about the Strace-devel mailing list