Merged in 4.4Lite2 versions, added $Id$'s. The ktrace changes should
fix the garbage error messages printed out under certain circumstances.
This commit is contained in:
parent
985a18a7c1
commit
0bff613275
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=16509
@ -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 <sys/param.h>
|
||||
@ -48,15 +52,15 @@ static char sccsid[] = "@(#)ktrace.c 8.1 (Berkeley) 6/6/93";
|
||||
#include <sys/errno.h>
|
||||
#include <sys/uio.h>
|
||||
#include <sys/ktrace.h>
|
||||
|
||||
#include <err.h>
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#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);
|
||||
}
|
||||
|
@ -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 <sys/param.h>
|
||||
@ -41,7 +45,9 @@ static char sccsid[] = "@(#)subr.c 8.1 (Berkeley) 6/6/93";
|
||||
#include <sys/proc.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/ktrace.h>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "ktrace.h"
|
||||
|
||||
getpoints(s)
|
||||
|
Loading…
Reference in New Issue
Block a user