[PATCH 2/4] trace_syscall: Print auxstr for failed syscall

Dmitry V. Levin ldv at altlinux.org
Wed Jul 23 21:57:57 UTC 2008


2008-04-19  Dmitry V. Levin <ldv at altlinux.org>

	* desc.c (sys_fcntl): Do not initialize auxstr for failed syscall.
	* process.c (sys_fork, sys_rfork) [USE_PROCFS]: Likewise.
	* signal.c (sys_signal): Likewise.
	* stream.c (internal_stream_ioctl): Likewise.
	* time.c (sys_adjtimex): Likewise.
	* syscall.c (trace_syscall): If RVAL_STR is set, then
	print auxstr for failed syscall as well.
---
 strace/desc.c    |    4 +++-
 strace/process.c |    4 ++--
 strace/signal.c  |    3 ++-
 strace/stream.c  |    2 +-
 strace/syscall.c |    2 ++
 strace/time.c    |    2 ++
 6 files changed, 12 insertions(+), 5 deletions(-)

--- a/strace/desc.c
+++ b/strace/desc.c
@@ -332,12 +332,14 @@ sys_fcntl(struct tcb *tcp)
 		case F_SETOWN: case F_GETOWN:
 			break;
 		case F_GETFD:
-			if (tcp->u_rval == 0)
+			if (syserror(tcp) || tcp->u_rval == 0)
 				return 0;
 			tcp->auxstr =
 				sprintflags("flags ", fdflags, tcp->u_rval);
 			return RVAL_HEX|RVAL_STR;
 		case F_GETFL:
+			if (syserror(tcp))
+				return 0;
 			tcp->auxstr = sprint_open_modes(tcp->u_rval);
 			return RVAL_HEX|RVAL_STR;
 		case F_GETLK:
--- a/strace/process.c
+++ b/strace/process.c
@@ -466,7 +466,7 @@ int
 sys_fork(tcp)
 struct tcb *tcp;
 {
-	if (exiting(tcp)) {
+	if (exiting(tcp) && !syserror(tcp)) {
 		if (getrval2(tcp)) {
 			tcp->auxstr = "child process";
 			return RVAL_UDECIMAL | RVAL_STR;
@@ -484,7 +484,7 @@ struct tcb *tcp;
 	if (entering(tcp)) {
 		tprintf ("%ld", tcp->u_arg[0]);
 	}
-	else {
+	else if (!syserror(tcp)) {
 		if (getrval2(tcp)) {
 			tcp->auxstr = "child process";
 			return RVAL_UDECIMAL | RVAL_STR;
--- a/strace/signal.c
+++ b/strace/signal.c
@@ -1202,7 +1202,7 @@ struct tcb *tcp;
 		}
 		return 0;
 	}
-	else {
+	else if (!syserror(tcp)) {
 		switch (tcp->u_rval) {
 		    case (int) SIG_ERR:
 			tcp->auxstr = "SIG_ERR"; break;
@@ -1215,6 +1215,7 @@ struct tcb *tcp;
 		}
 		return RVAL_HEX | RVAL_STR;
 	}
+	return 0;
 }
 
 #ifdef SVR4
--- a/strace/stream.c
+++ b/strace/stream.c
@@ -1177,7 +1177,7 @@ int arg;
 	}
 	if (exiting(tcp)) {
 		tprintf("}");
-		if (timod && tcp->u_rval) {
+		if (timod && tcp->u_rval && !syserror(tcp)) {
 			tcp->auxstr = xlookup (tli_errors, tcp->u_rval);
 			return RVAL_STR + 1;
 		}
--- a/strace/syscall.c
+++ b/strace/syscall.c
@@ -2368,6 +2368,8 @@ trace_syscall(struct tcb *tcp)
 						strerror(u_error));
 				break;
 			}
+			if ((sys_res & RVAL_STR) && tcp->auxstr)
+				tprintf(" (%s)", tcp->auxstr);
 		}
 		else {
 			if (sys_res & RVAL_NONE)
--- a/strace/time.c
+++ b/strace/time.c
@@ -674,6 +674,8 @@ sys_adjtimex(struct tcb *tcp)
 			tprintf("%#lx", tcp->u_arg[0]);
 		else if (tprint_timex(tcp, tcp->u_arg[0]) < 0)
 			tprintf("{...}");
+		if (syserror(tcp))
+			return 0;
 		tcp->auxstr = xlookup(adjtimex_state, tcp->u_rval);
 		if (tcp->auxstr)
 			return RVAL_STR;

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


More information about the Strace-devel mailing list