diff options
author | mdodd <mdodd@FreeBSD.org> | 2002-08-04 00:46:48 +0000 |
---|---|---|
committer | mdodd <mdodd@FreeBSD.org> | 2002-08-04 00:46:48 +0000 |
commit | 357fc6060d6acc804f9b5950000f1dfe7054417d (patch) | |
tree | 5faa50a8195f6ac5d6ceda995a1b3603dde4a3aa /usr.bin/truss/i386-fbsd.c | |
parent | 8cc0839b134c422ecc8ab8449ce6badd3bc0f792 (diff) | |
download | FreeBSD-src-357fc6060d6acc804f9b5950000f1dfe7054417d.zip FreeBSD-src-357fc6060d6acc804f9b5950000f1dfe7054417d.tar.gz |
Parameterize globals.
PR: bin/25587 (in part)
MFC after: 3 weeks
Diffstat (limited to 'usr.bin/truss/i386-fbsd.c')
-rw-r--r-- | usr.bin/truss/i386-fbsd.c | 40 |
1 files changed, 21 insertions, 19 deletions
diff --git a/usr.bin/truss/i386-fbsd.c b/usr.bin/truss/i386-fbsd.c index 89110b5..702db80 100644 --- a/usr.bin/truss/i386-fbsd.c +++ b/usr.bin/truss/i386-fbsd.c @@ -58,13 +58,13 @@ static const char rcsid[] = #include <string.h> #include <unistd.h> +#include "truss.h" #include "syscall.h" static int fd = -1; static int cpid = -1; extern int Procfd; -extern FILE *outfile; #include "syscalls.h" static int nsyscalls = sizeof(syscallnames) / sizeof(syscallnames[0]); @@ -111,7 +111,7 @@ clear_fsc() { */ void -i386_syscall_entry(int pid, int nargs) { +i386_syscall_entry(struct trussinfo *trussinfo, int nargs) { char buf[32]; struct reg regs = { 0 }; int syscall; @@ -119,14 +119,14 @@ i386_syscall_entry(int pid, int nargs) { unsigned int parm_offset; struct syscall *sc; - if (fd == -1 || pid != cpid) { - sprintf(buf, "/proc/%d/regs", pid); + if (fd == -1 || trussinfo->pid != cpid) { + sprintf(buf, "/proc/%d/regs", trussinfo->pid); fd = open(buf, O_RDWR); if (fd == -1) { - fprintf(outfile, "-- CANNOT READ REGISTERS --\n"); + fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n"); return; } - cpid = pid; + cpid = trussinfo->pid; } clear_fsc(); @@ -157,7 +157,7 @@ i386_syscall_entry(int pid, int nargs) { fsc.name = (syscall < 0 || syscall > nsyscalls) ? NULL : syscallnames[syscall]; if (!fsc.name) { - fprintf(outfile, "-- UNKNOWN SYSCALL %d --\n", syscall); + fprintf(trussinfo->outfile, "-- UNKNOWN SYSCALL %d --\n", syscall); } if (nargs == 0) @@ -173,7 +173,7 @@ i386_syscall_entry(int pid, int nargs) { fsc.nargs = sc->nargs; } else { #if DEBUG - fprintf(outfile, "unknown syscall %s -- setting args to %d\n", + fprintf(trussinfo->outfile, "unknown syscall %s -- setting args to %d\n", fsc.name, nargs); #endif fsc.nargs = nargs; @@ -214,7 +214,7 @@ i386_syscall_entry(int pid, int nargs) { } #if DEBUG - fprintf(outfile, "\n"); + fprintf(trussinfo->outfile, "\n"); #endif /* @@ -225,7 +225,7 @@ i386_syscall_entry(int pid, int nargs) { */ if (!strcmp(fsc.name, "execve") || !strcmp(fsc.name, "exit")) { - print_syscall(outfile, fsc.name, fsc.nargs, fsc.s_args); + print_syscall(trussinfo, fsc.name, fsc.nargs, fsc.s_args); } return; @@ -238,8 +238,8 @@ i386_syscall_entry(int pid, int nargs) { * the sytem call number instead of, say, an error status). */ -void -i386_syscall_exit(int pid, int syscall) { +int +i386_syscall_exit(struct trussinfo *trussinfo, int syscall) { char buf[32]; struct reg regs; int retval; @@ -247,19 +247,21 @@ i386_syscall_exit(int pid, int syscall) { int errorp; struct syscall *sc; - if (fd == -1 || pid != cpid) { - sprintf(buf, "/proc/%d/regs", pid); + if (fd == -1 || trussinfo->pid != cpid) { + sprintf(buf, "/proc/%d/regs", trussinfo->pid); fd = open(buf, O_RDONLY); if (fd == -1) { - fprintf(outfile, "-- CANNOT READ REGISTERS --\n"); + fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n"); return; } - cpid = pid; + cpid = trussinfo->pid; } lseek(fd, 0L, 0); - if (read(fd, ®s, sizeof(regs)) != sizeof(regs)) + if (read(fd, ®s, sizeof(regs)) != sizeof(regs)) { + fprintf(trussinfo->outfile, "\n"); return; + } retval = regs.r_eax; errorp = !!(regs.r_eflags & PSL_C); @@ -302,8 +304,8 @@ i386_syscall_exit(int pid, int syscall) { * but that complicates things considerably. */ - print_syscall_ret(outfile, fsc.name, fsc.nargs, fsc.s_args, errorp, retval); + print_syscall_ret(trussinfo, fsc.name, fsc.nargs, fsc.s_args, errorp, retval); clear_fsc(); - return; + return (retval); } |