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
@ -38,7 +38,11 @@ static char copyright[] =
|
|||||||
#endif /* not lint */
|
#endif /* not lint */
|
||||||
|
|
||||||
#ifndef lint
|
#ifndef lint
|
||||||
|
#if 0
|
||||||
static char sccsid[] = "@(#)ktrace.c 8.1 (Berkeley) 6/6/93";
|
static char sccsid[] = "@(#)ktrace.c 8.1 (Berkeley) 6/6/93";
|
||||||
|
#endif
|
||||||
|
static const char rcsid[] =
|
||||||
|
"$Id$";
|
||||||
#endif /* not lint */
|
#endif /* not lint */
|
||||||
|
|
||||||
#include <sys/param.h>
|
#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/errno.h>
|
||||||
#include <sys/uio.h>
|
#include <sys/uio.h>
|
||||||
#include <sys/ktrace.h>
|
#include <sys/ktrace.h>
|
||||||
|
|
||||||
|
#include <err.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <signal.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "ktrace.h"
|
#include "ktrace.h"
|
||||||
|
|
||||||
void noktrace() {
|
void no_ktrace __P((int));
|
||||||
(void)fprintf(stderr, "ktrace: ktrace not enabled in kernel,to use ktrace\n");
|
void usage __P((void));
|
||||||
(void)fprintf(stderr, "you need to add a line \"options KTRACE\" to your kernel\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
main(argc, argv)
|
main(argc, argv)
|
||||||
int argc;
|
int argc;
|
||||||
@ -72,9 +76,6 @@ main(argc, argv)
|
|||||||
append = ops = pidset = inherit = 0;
|
append = ops = pidset = inherit = 0;
|
||||||
trpoints = DEF_POINTS;
|
trpoints = DEF_POINTS;
|
||||||
tracefile = DEF_TRACEFILE;
|
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)
|
while ((ch = getopt(argc,argv,"aCcdf:g:ip:t:")) != EOF)
|
||||||
switch((char)ch) {
|
switch((char)ch) {
|
||||||
case 'a':
|
case 'a':
|
||||||
@ -107,8 +108,7 @@ main(argc, argv)
|
|||||||
case 't':
|
case 't':
|
||||||
trpoints = getpoints(optarg);
|
trpoints = getpoints(optarg);
|
||||||
if (trpoints < 0) {
|
if (trpoints < 0) {
|
||||||
(void)fprintf(stderr,
|
warnx("unknown facility in %s", optarg);
|
||||||
"ktrace: unknown facility in %s\n", optarg);
|
|
||||||
usage();
|
usage();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -117,13 +117,14 @@ main(argc, argv)
|
|||||||
}
|
}
|
||||||
argv += optind;
|
argv += optind;
|
||||||
argc -= optind;
|
argc -= optind;
|
||||||
|
|
||||||
if (pidset && *argv || !pidset && !*argv)
|
if (pidset && *argv || !pidset && !*argv)
|
||||||
usage();
|
usage();
|
||||||
|
|
||||||
if (inherit)
|
if (inherit)
|
||||||
trpoints |= KTRFAC_INHERIT;
|
trpoints |= KTRFAC_INHERIT;
|
||||||
|
|
||||||
|
(void)signal(SIGSYS, no_ktrace);
|
||||||
if (clear != NOTSET) {
|
if (clear != NOTSET) {
|
||||||
if (clear == CLEARALL) {
|
if (clear == CLEARALL) {
|
||||||
ops = KTROP_CLEAR | KTRFLAG_DESCEND;
|
ops = KTROP_CLEAR | KTRFLAG_DESCEND;
|
||||||
@ -133,24 +134,23 @@ main(argc, argv)
|
|||||||
ops |= pid ? KTROP_CLEAR : KTROP_CLEARFILE;
|
ops |= pid ? KTROP_CLEAR : KTROP_CLEARFILE;
|
||||||
|
|
||||||
if (ktrace(tracefile, ops, trpoints, pid) < 0)
|
if (ktrace(tracefile, ops, trpoints, pid) < 0)
|
||||||
error(tracefile);
|
err(1, tracefile);
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((fd = open(tracefile, O_CREAT | O_WRONLY | (append ? 0 : O_TRUNC),
|
if ((fd = open(tracefile, O_CREAT | O_WRONLY | (append ? 0 : O_TRUNC),
|
||||||
DEFFILEMODE)) < 0)
|
DEFFILEMODE)) < 0)
|
||||||
error(tracefile);
|
err(1, tracefile);
|
||||||
(void)close(fd);
|
(void)close(fd);
|
||||||
|
|
||||||
if (*argv) {
|
if (*argv) {
|
||||||
if (ktrace(tracefile, ops, trpoints, getpid()) < 0)
|
if (ktrace(tracefile, ops, trpoints, getpid()) < 0)
|
||||||
error();
|
err(1, tracefile);
|
||||||
execvp(argv[0], &argv[0]);
|
execvp(argv[0], &argv[0]);
|
||||||
error(argv[0]);
|
err(1, "exec of '%s' failed", argv[0]);
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
else if (ktrace(tracefile, ops, trpoints, pid) < 0)
|
else if (ktrace(tracefile, ops, trpoints, pid) < 0)
|
||||||
error(tracefile);
|
err(1, tracefile);
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -160,27 +160,29 @@ rpid(p)
|
|||||||
static int first;
|
static int first;
|
||||||
|
|
||||||
if (first++) {
|
if (first++) {
|
||||||
(void)fprintf(stderr,
|
warnx("only one -g or -p flag is permitted.");
|
||||||
"ktrace: only one -g or -p flag is permitted.\n");
|
|
||||||
usage();
|
usage();
|
||||||
}
|
}
|
||||||
if (!*p) {
|
if (!*p) {
|
||||||
(void)fprintf(stderr, "ktrace: illegal process id.\n");
|
warnx("illegal process id.");
|
||||||
usage();
|
usage();
|
||||||
}
|
}
|
||||||
return(atoi(p));
|
return(atoi(p));
|
||||||
}
|
}
|
||||||
|
|
||||||
error(name)
|
void
|
||||||
char *name;
|
|
||||||
{
|
|
||||||
(void)fprintf(stderr, "ktrace: %s: %s.\n", name, strerror(errno));
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
usage()
|
usage()
|
||||||
{
|
{
|
||||||
(void)fprintf(stderr,
|
(void)fprintf(stderr,
|
||||||
"usage:\tktrace [-aCcid] [-f trfile] [-g pgid] [-p pid] [-t [acgn]\n\tktrace [-aCcid] [-f trfile] [-t [acgn] command\n");
|
"usage:\tktrace [-aCcid] [-f trfile] [-g pgid] [-p pid] [-t [acgn]\n\tktrace [-aCcid] [-f trfile] [-t [acgn] command\n");
|
||||||
exit(1);
|
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
|
#ifndef lint
|
||||||
|
#if 0
|
||||||
static char sccsid[] = "@(#)subr.c 8.1 (Berkeley) 6/6/93";
|
static char sccsid[] = "@(#)subr.c 8.1 (Berkeley) 6/6/93";
|
||||||
|
#endif
|
||||||
|
static const char rcsid[] =
|
||||||
|
"$Id$";
|
||||||
#endif /* not lint */
|
#endif /* not lint */
|
||||||
|
|
||||||
#include <sys/param.h>
|
#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/proc.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <sys/ktrace.h>
|
#include <sys/ktrace.h>
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "ktrace.h"
|
#include "ktrace.h"
|
||||||
|
|
||||||
getpoints(s)
|
getpoints(s)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user