Changeset View
Changeset View
Standalone View
Standalone View
usr.bin/truss/main.c
Show First 20 Lines • Show All 53 Lines • ▼ Show 20 Lines | |||||
#include "truss.h" | #include "truss.h" | ||||
#include "extern.h" | #include "extern.h" | ||||
#include "syscall.h" | #include "syscall.h" | ||||
static void | static void | ||||
usage(void) | usage(void) | ||||
{ | { | ||||
fprintf(stderr, "%s\n%s\n", | fprintf(stderr, "%s\n%s\n", | ||||
"usage: truss [-cfaedDHS] [-o file] [-s strsize] -p pid", | "usage: truss [-cfaedDHS] [-o file] [-s strsize] [-t timeout] -p pid", | ||||
" truss [-cfaedDHS] [-o file] [-s strsize] command [args]"); | " truss [-cfaedDHS] [-o file] [-s strsize] [-t timeout] command [args]"); | ||||
exit(1); | exit(1); | ||||
} | } | ||||
int | int | ||||
main(int ac, char **av) | main(int ac, char **av) | ||||
{ | { | ||||
struct sigaction sa; | struct sigaction sa; | ||||
struct trussinfo *trussinfo; | struct trussinfo *trussinfo; | ||||
char *fname; | char *fname; | ||||
char **command; | char **command; | ||||
pid_t pid; | pid_t pid; | ||||
int c; | int c; | ||||
fname = NULL; | fname = NULL; | ||||
/* Initialize the trussinfo struct */ | /* Initialize the trussinfo struct */ | ||||
trussinfo = (struct trussinfo *)calloc(1, sizeof(struct trussinfo)); | trussinfo = (struct trussinfo *)calloc(1, sizeof(struct trussinfo)); | ||||
if (trussinfo == NULL) | if (trussinfo == NULL) | ||||
errx(1, "calloc() failed"); | errx(1, "calloc() failed"); | ||||
pid = 0; | pid = 0; | ||||
trussinfo->outfile = stderr; | trussinfo->outfile = stderr; | ||||
trussinfo->strsize = 32; | trussinfo->strsize = 32; | ||||
trussinfo->timeout = 0; | |||||
trussinfo->curthread = NULL; | trussinfo->curthread = NULL; | ||||
LIST_INIT(&trussinfo->proclist); | LIST_INIT(&trussinfo->proclist); | ||||
init_syscalls(); | init_syscalls(); | ||||
while ((c = getopt(ac, av, "p:o:facedDs:SH")) != -1) { | while ((c = getopt(ac, av, "p:o:facedDs:t:SH")) != -1) { | ||||
switch (c) { | switch (c) { | ||||
case 'p': /* specified pid */ | case 'p': /* specified pid */ | ||||
pid = atoi(optarg); | pid = atoi(optarg); | ||||
/* make sure i don't trace me */ | /* make sure i don't trace me */ | ||||
if (pid == getpid()) { | if (pid == getpid()) { | ||||
errx(2, "attempt to grab self."); | errx(2, "attempt to grab self."); | ||||
} | } | ||||
break; | break; | ||||
Show All 15 Lines | while ((c = getopt(ac, av, "p:o:facedDs:t:SH")) != -1) { | ||||
case 'D': /* Relative timestamps */ | case 'D': /* Relative timestamps */ | ||||
trussinfo->flags |= RELATIVETIMESTAMPS; | trussinfo->flags |= RELATIVETIMESTAMPS; | ||||
break; | break; | ||||
case 'o': /* Specified output file */ | case 'o': /* Specified output file */ | ||||
fname = optarg; | fname = optarg; | ||||
break; | break; | ||||
case 's': /* Specified string size */ | case 's': /* Specified string size */ | ||||
trussinfo->strsize = atoi(optarg); | trussinfo->strsize = atoi(optarg); | ||||
break; | |||||
case 't': /* Pending syscall timeout */ | |||||
trussinfo->timeout = atoi(optarg); | |||||
break; | break; | ||||
case 'S': /* Don't trace signals */ | case 'S': /* Don't trace signals */ | ||||
trussinfo->flags |= NOSIGS; | trussinfo->flags |= NOSIGS; | ||||
break; | break; | ||||
case 'H': | case 'H': | ||||
trussinfo->flags |= DISPLAYTIDS; | trussinfo->flags |= DISPLAYTIDS; | ||||
break; | break; | ||||
default: | default: | ||||
▲ Show 20 Lines • Show All 77 Lines • Show Last 20 Lines |