RFC: path display and path filtering features.

Dmitry V. Levin ldv at altlinux.org
Tue Mar 22 14:02:49 UTC 2011


On Wed, Mar 16, 2011 at 07:43:36AM -0500, Grant Edwards wrote:
> Attached are updated diffs against git HEAD as of a few minutes ago...

I've made a few minor corrections, most essential of them are early
include of "defs.h" (due to config.h), and check for tcp->scno
before pathtrace_match() call (because the latter uses tcp->scno).

Would you like to prepare a commit message?

diff --git a/defs.h b/defs.h
index ecfd7c0..9e1f5f4 100644
--- a/defs.h
+++ b/defs.h
@@ -453,7 +453,7 @@ struct tcb {
 #define syserror(tcp)	((tcp)->u_error != 0)
 #define verbose(tcp)	(qual_flags[(tcp)->scno] & QUAL_VERBOSE)
 #define abbrev(tcp)	(qual_flags[(tcp)->scno] & QUAL_ABBREV)
-#define filtered(tcp)   ((tcp)->flags & TCB_FILTERED)
+#define filtered(tcp)	((tcp)->flags & TCB_FILTERED)
 
 struct xlat {
 	int val;
diff --git a/pathtrace.c b/pathtrace.c
index 495122d..2980a12 100644
--- a/pathtrace.c
+++ b/pathtrace.c
@@ -1,4 +1,3 @@
-
 /*
  * Copyright (c) 2011, Comtrol Corp.
  * All rights reserved.
@@ -27,11 +26,11 @@
  *
  */
 
+#include "defs.h"
+
 #include <ctype.h>
 #include <limits.h>
 
-#include "defs.h"
-
 #ifdef HAVE_POLL_H
 #include <poll.h>
 #endif
@@ -67,6 +66,7 @@ static int
 upathmatch(struct tcb *tcp, unsigned long upath)
 {
 	char    path[PATH_MAX + 1];
+
 	return umovestr(tcp, upath, sizeof path, path) == 0 &&
 		pathmatch(path);
 }
@@ -135,8 +135,8 @@ pathtrace_select(char *path)
 		return 0;
 	}
 
-	fprintf(stderr, "Requested path '%s' resolved into '%s'\n", path,
-		rpath);
+	fprintf(stderr, "Requested path '%s' resolved into '%s'\n",
+		path, rpath);
 	return storepath(rpath);
 }
 
@@ -249,7 +249,8 @@ pathtrace_match(struct tcb *tcp)
 
 		if (s->sys_func == sys_oldselect)
 		{
-			if (umoven(tcp, tcp->u_arg[0], sizeof oldargs, (char*)oldargs) < 0)
+			if (umoven(tcp, tcp->u_arg[0], sizeof oldargs,
+				   (char*) oldargs) < 0)
 			{
 				fprintf(stderr, "umoven() failed\n");
 				return 0;
@@ -259,9 +260,9 @@ pathtrace_match(struct tcb *tcp)
 			args = tcp->u_arg;
 
 		nfds = args[0];
-		fdsize = ((((nfds + 7) / 8) + sizeof(long) -
-			   1) & -sizeof(long));
-		fds = (fd_set *) malloc(fdsize);
+		fdsize = ((((nfds + 7) / 8) + sizeof(long) - 1)
+			  & -sizeof(long));
+		fds = malloc(fdsize);
 
 		if (fds == NULL)
 		{
@@ -269,7 +270,7 @@ pathtrace_match(struct tcb *tcp)
 			return 0;
 		}
 
-		for (i = 1; i <= 3; i++)
+		for (i = 1; i <= 3; ++i)
 		{
 			if (args[i] == 0)
 				continue;
@@ -280,7 +281,7 @@ pathtrace_match(struct tcb *tcp)
 				continue;
 			}
 
-			for (j = 0; j < nfds; j++)
+			for (j = 0; j < nfds; ++j)
 				if (FD_ISSET(j, fds) && fdmatch(tcp, j))
 				{
 					free(fds);
diff --git a/strace.c b/strace.c
index f8ae0d0..7874d19 100644
--- a/strace.c
+++ b/strace.c
@@ -105,7 +105,7 @@ static bool daemonized_tracer = 0;
 int not_failing_only = 0;
 
 /* Show path associated with fd arguments */
-int show_fd_path;
+int show_fd_path = 0;
 
 /* are we filtering traces based on paths? */
 int tracing_paths = 0;
diff --git a/syscall.c b/syscall.c
index 213492a..6987011 100644
--- a/syscall.c
+++ b/syscall.c
@@ -2688,10 +2688,10 @@ trace_syscall_entering(struct tcb *tcp)
 
 	internal_syscall(tcp);
 
-	if ((tracing_paths && !pathtrace_match(tcp)) ||
-	    (tcp->scno >= 0 && tcp->scno < nsyscalls && !(qual_flags[tcp->scno] & QUAL_TRACE))) {
-		tcp->flags |= TCB_FILTERED;
-		tcp->flags |= TCB_INSYSCALL;
+	if ((tcp->scno >= 0 && tcp->scno < nsyscalls &&
+	     !(qual_flags[tcp->scno] & QUAL_TRACE)) ||
+	    (tracing_paths && !pathtrace_match(tcp))) {
+		tcp->flags |= TCB_INSYSCALL | TCB_FILTERED;
 		return 0;
 	}
 
diff --git a/util.c b/util.c
index 57e11be..d6c4df7 100644
--- a/util.c
+++ b/util.c
@@ -419,7 +419,8 @@ void
 printfd(struct tcb *tcp, int fd)
 {
 	char *p;
-	if (show_fd_path && (p=getfdpath(tcp, fd)))
+
+	if (show_fd_path && (p = getfdpath(tcp, fd)))
 		tprintf("%d<%s>", fd, p);
 	else
 		tprintf("%d", fd);
@@ -1781,29 +1782,24 @@ err:
 
 #endif /* SUNOS4 */
 
-#ifdef LINUX
-#include <unistd.h>
-
 // get path associated with fd
 char *getfdpath(struct tcb *tcp, int fd)
 {
+#ifdef LINUX
 	static char path[PATH_MAX+1];
 	char linkpath[64];
 	ssize_t n;
-	
+
 	if (fd < 0)
 		return NULL;
-	
+
 	snprintf(linkpath, sizeof linkpath, "/proc/%d/fd/%d", tcp->pid, fd);
 	n = readlink(linkpath, path, (sizeof path) - 1);
 	if (n <= 0)
 		return NULL;
 	path[n] = '\0';
 	return path;
-}
 #else
-char *getfdpath(struct tcb *tcp, int fd)
-{
 	return NULL;
-}
 #endif
+}


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


More information about the Strace-devel mailing list