diff -u strace_4.0.orig.tar.gz#utar/strace-4.0/file.c strace/file.c --- strace_4.0.orig.tar.gz#utar/strace-4.0/file.c Fri Jul 9 02:32:54 1999 +++ strace/file.c Sat Dec 11 23:53:14 1999 @@ -1397,6 +1397,10 @@ d->d_namlen, d->d_namlen, d->d_name); } #endif /* SUNOS4 */ + if (!d->d_reclen) { + tprintf("/* d_reclen == 0, problem here */"); + break; + } i += d->d_reclen; dents++; } diff -u strace_4.0.orig.tar.gz#utar/strace-4.0/process.c strace/process.c --- strace_4.0.orig.tar.gz#utar/strace-4.0/process.c Fri Jun 11 15:18:40 1999 +++ strace/process.c Sun Nov 21 22:17:43 1999 @@ -294,6 +294,21 @@ } int +change_syscall(tcp, new) +struct tcb *tcp; +int new; +{ +#if defined(I386) && defined(LINUX) + /* Attempt to make vfork into fork, which we can follow. */ + if (ptrace(PTRACE_POKEUSER, tcp->pid, + (void *)(ORIG_EAX * 4), new) < 0) + return -1; + return 0; +#endif + return -1; +} + +int internal_fork(tcp) struct tcb *tcp; { @@ -303,16 +318,10 @@ #ifdef SYS_vfork if (tcp->scno == SYS_vfork) { -#if defined(I386) && defined(LINUX) /* Attempt to make vfork into fork, which we can follow. */ if (!followvfork || - ptrace(PTRACE_POKEUSR, tcp->pid, - (void *)(ORIG_EAX * 4), SYS_fork) < 0) + change_syscall(tcp, SYS_fork) < 0) dont_follow = 1; - -#else - dont_follow = 1; -#endif } #endif #ifdef SYS_clone diff -u strace_4.0.orig.tar.gz#utar/strace-4.0/strace.c strace/strace.c --- strace_4.0.orig.tar.gz#utar/strace-4.0/strace.c Mon Jun 28 15:17:16 1999 +++ strace/strace.c Thu Dec 9 12:00:38 1999 @@ -59,7 +59,10 @@ int acolumn = DEFAULT_ACOLUMN; int max_strlen = DEFAULT_STRLEN; char *outfname = NULL; +char *filter = NULL; +int filterf = -1; FILE *outf; +int inf; struct tcb tcbtab[MAX_PROCS]; int nprocs; char *progname; @@ -170,7 +173,7 @@ set_sortby(DEFAULT_SORTBY); set_personality(DEFAULT_PERSONALITY); while ((c = getopt(argc, argv, - "+cdfFhiqrtTvVxa:e:o:O:p:s:S:u:")) != EOF) { + "+cdfFhiqrtTvVxa:e:o:O:p:s:S:u:y:")) != EOF) { switch (c) { case 'c': cflag++; @@ -223,6 +226,9 @@ case 'o': outfname = strdup(optarg); break; + case 'y': /* Notice you can use something like ./strace -y 'cat >&2 | cat <&2' ls to filter interactively */ + filter = strdup(optarg); + break; case 'O': set_overhead(atoi(optarg)); break; @@ -233,8 +239,8 @@ break; } if (pid == getpid()) { - fprintf(stderr, "%s: I'm sorry, I can't let you do that, Dave.", progname); - break; + fprintf(stderr, "%s: I'm sorry, I can't let you do that, Dave.\n", progname); + exit(1); } if ((tcp = alloctcb(pid)) == NULL) { fprintf(stderr, "%s: tcb table full, please recompile strace\n", @@ -306,6 +312,28 @@ } } + if (filter) { + int pin[2], pout[2]; + pipe(pin); + pipe(pout); + if (!fork()) { /* Child */ + close(0); + dup(pin[0]); + close(1); + dup(pout[1]); + close(pin[0]); + close(pin[1]); + close(pout[0]); + close(pout[1]); + system( filter ); + exit(0); + } + close(pin[0]); + close(pout[1]); + outf = fdopen(pin[1], "w"); + filterf = pout[0]; + } + #ifndef SVR4 setreuid(geteuid(), getuid()); #endif diff -u strace_4.0.orig.tar.gz#utar/strace-4.0/syscall.c strace/syscall.c --- strace_4.0.orig.tar.gz#utar/strace-4.0/syscall.c Thu Jun 24 15:55:29 1999 +++ strace/syscall.c Mon Nov 29 10:23:03 1999 @@ -1263,6 +1303,11 @@ sys_res = (*sysent[tcp->scno].sys_func)(tcp); if (fflush(tcp->outf) == EOF) return -1; + + res = syscall_monitor(tcp); + if (res != 1) + return -1; + tcp->flags |= TCB_INSYSCALL; /* Measure the entrance time as late as possible to avoid errors. */ if (dtime) @@ -1454,4 +1499,32 @@ fprintf(outf, "%6.6s %4ld.%06ld %11.11s %9d %9.9s %s\n", "100.00", (long) tv_cum.tv_sec, (long) tv_cum.tv_usec, "", call_cum, error_str, "total"); +} + +static int +syscall_monitor(tcp) +struct tcb *tcp; +{ + char res = 0; + extern int filterf; + + if (filterf == -1) + return 1; + + tprintf( " ALLOW? (y/n/k)\n" ); + retry: + if (fflush(tcp->outf) == EOF) + return -1; + if (read(filterf, &res, 1)!=1) + return -1; + switch(res) { + case 'n': + if (change_syscall(tcp, __NR_getpmsg) == 0) + case 'y': + return 1; + case 'k': + return -1; + default: + goto retry; + } } diff -u strace_4.0.orig.tar.gz#utar/strace-4.0/util.c strace/util.c --- strace_4.0.orig.tar.gz#utar/strace-4.0/util.c Tue Jun 22 17:28:30 1999 +++ strace/util.c Sat Dec 11 23:53:13 1999 @@ -318,6 +318,7 @@ struct tcb *tcp; long addr; { + tprintf("(at: %x) ", tcp->u_arg[0]); if (umovestr(tcp, addr, MAXPATHLEN, path) < 0) tprintf("%#lx", addr); else @@ -331,6 +332,7 @@ long addr; int n; { + tprintf("(at: %x) ", tcp->u_arg[0]); if (umovestr(tcp, addr, n, path) < 0) tprintf("%#lx", addr); else {