* Copyright (c) 1988 The Regents of the University of California.
* %sccs.include.redist.c%
"@(#) Copyright (c) 1988 The Regents of the University of California.\n\
static char sccsid
[] = "@(#)ktrace.c 5.2 (Berkeley) %G%";
enum { NOTSET
, CLEAR
, CLEARALL
} clear
;
int append
, ch
, fd
, inherit
, ops
, pid
, pidset
, trpoints
;
append
= ops
= pidset
= 0;
tracefile
= DEF_TRACEFILE
;
while ((ch
= getopt(argc
,argv
,"aCcdf:g:ip:t:")) != EOF
)
trpoints
= getpoints(optarg
);
"ktrace: unknown facility in %s\n", optarg
);
if (pidset
&& *argv
|| !pidset
&& !*argv
)
trpoints
|= KTRFAC_INHERIT
;
ops
= KTROP_CLEAR
| KTRFLAG_DESCEND
;
ops
|= pid
? KTROP_CLEAR
: KTROP_CLEARFILE
;
if (ktrace(tracefile
, ops
, trpoints
, pid
) < 0)
if ((fd
= open(tracefile
, O_CREAT
| O_WRONLY
| (append
? 0 : O_TRUNC
),
if (ktrace(tracefile
, ops
, trpoints
, getpid()) < 0)
execvp(argv
[0], &argv
[0]);
else if (ktrace(tracefile
, ops
, trpoints
, pid
) < 0)
"ktrace: only one -g or -p flag is permitted.\n");
(void)fprintf(stderr
, "ktrace: illegal process id.\n");
(void)fprintf(stderr
, "ktrace: %s: %s.\n", name
, strerror(errno
));
"usage:\tktrace [-aCcid] [-f trfile] [-g pgid] [-p pid] [-t [acgn]\n\tktrace [-aCcid] [-f trfile] [-t [acgn] command\n");