only seeing successful system calls

Michal Ludvig michal at logix.cz
Wed Nov 6 05:26:05 UTC 2002


On Sun, 3 Nov 2002, Marty Leisner wrote:

> When using strace I  sometimes like to see the system calls
> which work (instead of all the system calls).

Thanks, I've slightly modified and committed it (see attachment). Actually 
your patch didn't care if the syscall returned zero or any other value, 
but instead if it failed or not. So I've renamed the variable, cleaned 
it up a bit and committed.

Michal Ludvig
-------------- next part --------------
? autom4te-2.53.cache
Index: ChangeLog
===================================================================
RCS file: /cvsroot/strace/strace/ChangeLog,v
retrieving revision 1.164
diff -u -p -r1.164 ChangeLog
--- ChangeLog	9 Oct 2002 09:16:22 -0000	1.164
+++ ChangeLog	6 Nov 2002 13:10:51 -0000
@@ -1,3 +1,7 @@
+2002-11-06  Michal Ludvig  <mludvig at suse.cz>
+
+	* strace.c (not_failing_only): New.
+
 2002-10-08  Heiko Carstens <heiko.carstens at de.ibm.com>
 
 	Missing complete changelog for 2002-10-07 commit:
Index: defs.h
===================================================================
RCS file: /cvsroot/strace/strace/defs.h,v
retrieving revision 1.31
diff -u -p -r1.31 defs.h
--- defs.h	23 Sep 2002 15:41:02 -0000	1.31
+++ defs.h	6 Nov 2002 13:10:51 -0000
@@ -553,3 +553,5 @@ do {									\
 #ifdef IA64
 extern long ia32;
 #endif
+
+extern int not_failing_only;
Index: strace.c
===================================================================
RCS file: /cvsroot/strace/strace/strace.c,v
retrieving revision 1.30
diff -u -p -r1.30 strace.c
--- strace.c	23 May 2002 11:02:22 -0000	1.30
+++ strace.c	6 Nov 2002 13:10:51 -0000
@@ -67,6 +67,9 @@ int rflag = 0, tflag = 0, dtime = 0, cfl
 int iflag = 0, xflag = 0, qflag = 0;
 int pflag_seen = 0;
 
+/* Sometimes we want to print only succeeding syscalls. */
+int not_failing_only = 0;
+
 char *username = NULL;
 uid_t run_uid;
 gid_t run_gid;
@@ -154,6 +157,7 @@ usage: strace [-dffhiqrtttTvVxx] [-a col
 -s strsize -- limit length of print strings to STRSIZE chars (default %d)\n\
 -S sortby -- sort syscall counts by: time, calls, name, nothing (default %s)\n\
 -u username -- run command as username handling setuid and/or setgid\n\
+-z -- print only succeeding syscalls\n\
 ", DEFAULT_ACOLUMN, DEFAULT_STRLEN, DEFAULT_SORTBY);
 	exit(exitval);
 }
@@ -190,7 +194,7 @@ char *argv[];
 	set_sortby(DEFAULT_SORTBY);
 	set_personality(DEFAULT_PERSONALITY);
 	while ((c = getopt(argc, argv,
-		"+cdfFhiqrtTvVxa:e:o:O:p:s:S:u:")) != EOF) {
+		"+cdfFhiqrtTvVxza:e:o:O:p:s:S:u:")) != EOF) {
 		switch (c) {
 		case 'c':
 			cflag++;
@@ -233,6 +237,9 @@ char *argv[];
 		case 'V':
 			printf("%s\n", version);
 			exit(0);
+			break;
+		case 'z':
+			not_failing_only = 1;
 			break;
 		case 'a':
 			acolumn = atoi(optarg);
Index: syscall.c
===================================================================
RCS file: /cvsroot/strace/strace/syscall.c,v
retrieving revision 1.38
diff -u -p -r1.38 syscall.c
--- syscall.c	7 Oct 2002 14:31:11 -0000	1.38
+++ syscall.c	6 Nov 2002 13:10:51 -0000
@@ -1742,8 +1742,11 @@ struct tcb *tcp;
 		if (tcp->scno >= nsyscalls || tcp->scno < 0
 		    || (qual_flags[tcp->scno] & QUAL_RAW))
 			sys_res = printargs(tcp);
-		else
+		else {
+			if (not_failing_only && tcp->u_error)
+				return;	/* ignore failed syscalls */
 			sys_res = (*sysent[tcp->scno].sys_func)(tcp);
+		}	
 		u_error = tcp->u_error;
 		tprintf(") ");
 		tabto(acolumn);


More information about the Strace-devel mailing list