From 30b42b6dfff6513bc654b0bc6f1388eda0d8ea77 Mon Sep 17 00:00:00 2001 From: jraynard Date: Wed, 19 Jun 1996 09:56:30 +0000 Subject: Merged in 4.4Lite2 versions, added $Id$'s. The ktrace changes should fix the garbage error messages printed out under certain circumstances. --- usr.bin/ktrace/ktrace.c | 62 +++++++++++++++++++++++++------------------------ usr.bin/ktrace/subr.c | 6 +++++ 2 files changed, 38 insertions(+), 30 deletions(-) (limited to 'usr.bin') diff --git a/usr.bin/ktrace/ktrace.c b/usr.bin/ktrace/ktrace.c index e584265..38577f3 100644 --- a/usr.bin/ktrace/ktrace.c +++ b/usr.bin/ktrace/ktrace.c @@ -38,7 +38,11 @@ static char copyright[] = #endif /* not lint */ #ifndef lint +#if 0 static char sccsid[] = "@(#)ktrace.c 8.1 (Berkeley) 6/6/93"; +#endif +static const char rcsid[] = + "$Id$"; #endif /* not lint */ #include @@ -48,15 +52,15 @@ static char sccsid[] = "@(#)ktrace.c 8.1 (Berkeley) 6/6/93"; #include #include #include + +#include #include -#include +#include + #include "ktrace.h" -void noktrace() { - (void)fprintf(stderr, "ktrace: ktrace not enabled in kernel,to use ktrace\n"); - (void)fprintf(stderr, "you need to add a line \"options KTRACE\" to your kernel\n"); - exit(1); -} +void no_ktrace __P((int)); +void usage __P((void)); main(argc, argv) int argc; @@ -72,9 +76,6 @@ main(argc, argv) append = ops = pidset = inherit = 0; trpoints = DEF_POINTS; tracefile = DEF_TRACEFILE; - /* set up a signal handler for SIGSYS, this indicates that ktrace - is not enabled in the kernel */ - signal(SIGSYS, noktrace); while ((ch = getopt(argc,argv,"aCcdf:g:ip:t:")) != EOF) switch((char)ch) { case 'a': @@ -107,8 +108,7 @@ main(argc, argv) case 't': trpoints = getpoints(optarg); if (trpoints < 0) { - (void)fprintf(stderr, - "ktrace: unknown facility in %s\n", optarg); + warnx("unknown facility in %s", optarg); usage(); } break; @@ -117,13 +117,14 @@ main(argc, argv) } argv += optind; argc -= optind; - + if (pidset && *argv || !pidset && !*argv) usage(); - + if (inherit) trpoints |= KTRFAC_INHERIT; + (void)signal(SIGSYS, no_ktrace); if (clear != NOTSET) { if (clear == CLEARALL) { ops = KTROP_CLEAR | KTRFLAG_DESCEND; @@ -133,24 +134,23 @@ main(argc, argv) ops |= pid ? KTROP_CLEAR : KTROP_CLEARFILE; if (ktrace(tracefile, ops, trpoints, pid) < 0) - error(tracefile); + err(1, tracefile); exit(0); } if ((fd = open(tracefile, O_CREAT | O_WRONLY | (append ? 0 : O_TRUNC), DEFFILEMODE)) < 0) - error(tracefile); + err(1, tracefile); (void)close(fd); - if (*argv) { + if (*argv) { if (ktrace(tracefile, ops, trpoints, getpid()) < 0) - error(); + err(1, tracefile); execvp(argv[0], &argv[0]); - error(argv[0]); - exit(1); + err(1, "exec of '%s' failed", argv[0]); } else if (ktrace(tracefile, ops, trpoints, pid) < 0) - error(tracefile); + err(1, tracefile); exit(0); } @@ -160,27 +160,29 @@ rpid(p) static int first; if (first++) { - (void)fprintf(stderr, - "ktrace: only one -g or -p flag is permitted.\n"); + warnx("only one -g or -p flag is permitted."); usage(); } if (!*p) { - (void)fprintf(stderr, "ktrace: illegal process id.\n"); + warnx("illegal process id."); usage(); } return(atoi(p)); } -error(name) - char *name; -{ - (void)fprintf(stderr, "ktrace: %s: %s.\n", name, strerror(errno)); - exit(1); -} - +void usage() { (void)fprintf(stderr, "usage:\tktrace [-aCcid] [-f trfile] [-g pgid] [-p pid] [-t [acgn]\n\tktrace [-aCcid] [-f trfile] [-t [acgn] command\n"); exit(1); } + +void +no_ktrace(sig) + int sig; +{ + (void)fprintf(stderr, +"error:\tktrace() system call not supported in the running kernel\n\tre-compile kernel with 'options KTRACE'\n"); + exit(1); +} diff --git a/usr.bin/ktrace/subr.c b/usr.bin/ktrace/subr.c index 6076c24..5698b65 100644 --- a/usr.bin/ktrace/subr.c +++ b/usr.bin/ktrace/subr.c @@ -32,7 +32,11 @@ */ #ifndef lint +#if 0 static char sccsid[] = "@(#)subr.c 8.1 (Berkeley) 6/6/93"; +#endif +static const char rcsid[] = + "$Id$"; #endif /* not lint */ #include @@ -41,7 +45,9 @@ static char sccsid[] = "@(#)subr.c 8.1 (Berkeley) 6/6/93"; #include #include #include + #include + #include "ktrace.h" getpoints(s) -- cgit v1.1