summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2002-06-23 20:01:26 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2002-06-23 20:01:26 +0000
commitdf76e10a5850dbc56d189fd0ac3eec402d0939d9 (patch)
tree9da547ff875534783dda3a784a31ea25c6ef4b59 /usr.bin
parent0e487d9ea8a83d70aab5fbadd4d297a625da75b1 (diff)
add -p pid feature, and ansi at the same time; millert ok
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/kdump/kdump.17
-rw-r--r--usr.bin/kdump/kdump.c84
2 files changed, 45 insertions, 46 deletions
diff --git a/usr.bin/kdump/kdump.1 b/usr.bin/kdump/kdump.1
index a714e1103c8..e840d776dee 100644
--- a/usr.bin/kdump/kdump.1
+++ b/usr.bin/kdump/kdump.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: kdump.1,v 1.7 2000/03/08 03:11:30 aaron Exp $
+.\" $OpenBSD: kdump.1,v 1.8 2002/06/23 20:01:25 deraadt Exp $
.\"
.\" Copyright (c) 1990, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -45,6 +45,7 @@
.Op Fl e Ar emulation
.Op Fl f Ar file
.Op Fl m Ar maxdata
+.Op Fl p Ar pid
.Op Fl t Op cenis
.Sh DESCRIPTION
.Nm
@@ -92,6 +93,10 @@ values are replaced with the
string.
Suppressing this feature yields a more consistent output format and is
easily amenable to further processing.
+.It Fl p Ar pid
+Show output only for the
+.Ar pid
+specified.
.It Fl R
Display relative timestamps (time since previous entry).
.It Fl T
diff --git a/usr.bin/kdump/kdump.c b/usr.bin/kdump/kdump.c
index 389d34323a5..ad9ad66f4fa 100644
--- a/usr.bin/kdump/kdump.c
+++ b/usr.bin/kdump/kdump.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kdump.c,v 1.16 2002/06/12 06:07:15 mpech Exp $ */
+/* $OpenBSD: kdump.c,v 1.17 2002/06/23 20:01:25 deraadt Exp $ */
/*-
* Copyright (c) 1988, 1993
@@ -43,7 +43,7 @@ static char copyright[] =
#if 0
static char sccsid[] = "@(#)kdump.c 8.4 (Berkeley) 4/28/95";
#endif
-static char *rcsid = "$OpenBSD: kdump.c,v 1.16 2002/06/12 06:07:15 mpech Exp $";
+static char *rcsid = "$OpenBSD: kdump.c,v 1.17 2002/06/23 20:01:25 deraadt Exp $";
#endif /* not lint */
#include <sys/param.h>
@@ -70,6 +70,7 @@ static char *rcsid = "$OpenBSD: kdump.c,v 1.16 2002/06/12 06:07:15 mpech Exp $";
int timestamp, decimal, fancy = 1, tail, maxdata;
char *tracefile = DEF_TRACEFILE;
struct ktr_header ktr_header;
+pid_t pid = -1;
#define eqs(s1, s2) (strcmp((s1), (s2)) == 0)
@@ -158,17 +159,15 @@ static void setemul(const char *);
static void usage(void);
int
-main(argc, argv)
- int argc;
- char *argv[];
+main(int argc, char *argv[])
{
- int ch, ktrlen, size;
- void *m;
+ int ch, ktrlen, size, silent;
int trpoints = ALL_POINTS;
+ void *m;
current = &emulations[0]; /* native */
- while ((ch = getopt(argc, argv, "e:f:dlm:nRTt:")) != -1)
+ while ((ch = getopt(argc, argv, "e:f:dlm:nRp:Tt:")) != -1)
switch (ch) {
case 'e':
setemul(optarg);
@@ -188,6 +187,9 @@ main(argc, argv)
case 'n':
fancy = 0;
break;
+ case 'p':
+ pid = atoi(optarg);
+ break;
case 'R':
timestamp = 2; /* relative timestamp */
break;
@@ -211,7 +213,10 @@ main(argc, argv)
if (!freopen(tracefile, "r", stdin))
err(1, "%s", tracefile);
while (fread_tail(&ktr_header, sizeof(struct ktr_header), 1)) {
- if (trpoints & (1<<ktr_header.ktr_type))
+ silent = 0;
+ if (pid != -1 && pid != ktr_header.ktr_pid)
+ silent = 1;
+ if (silent == 0 && trpoints & (1<<ktr_header.ktr_type))
dumpheader(&ktr_header);
if ((ktrlen = ktr_header.ktr_len) < 0)
errx(1, "bogus length 0x%x", ktrlen);
@@ -223,6 +228,8 @@ main(argc, argv)
}
if (ktrlen && fread_tail(m, ktrlen, 1) == 0)
errx(1, "data too short");
+ if (silent)
+ continue;
if ((trpoints & (1<<ktr_header.ktr_type)) == 0)
continue;
switch (ktr_header.ktr_type) {
@@ -255,9 +262,7 @@ main(argc, argv)
}
static int
-fread_tail(buf, size, num)
- void *buf;
- int num, size;
+fread_tail(void *buf, int size, int num)
{
int i;
@@ -269,11 +274,10 @@ fread_tail(buf, size, num)
}
static void
-dumpheader(kth)
- struct ktr_header *kth;
+dumpheader(struct ktr_header *kth)
{
- char unknown[64], *type;
static struct timeval prevtime;
+ char unknown[64], *type;
struct timeval temp;
switch (kth->ktr_type) {
@@ -299,7 +303,8 @@ dumpheader(kth)
type = "EMUL";
break;
default:
- (void)sprintf(unknown, "UNKNOWN(%d)", kth->ktr_type);
+ (void)snprintf(unknown, sizeof unknown, "UNKNOWN(%d)",
+ kth->ktr_type);
type = unknown;
}
@@ -317,8 +322,7 @@ dumpheader(kth)
}
static void
-ioctldecode(cmd)
- u_long cmd;
+ioctldecode(u_long cmd)
{
char dirbuf[4], *dir = dirbuf;
@@ -337,8 +341,7 @@ ioctldecode(cmd)
}
static void
-ktrsyscall(ktr)
- struct ktr_syscall *ktr;
+ktrsyscall(struct ktr_syscall *ktr)
{
int argsize = ktr->ktr_argsize;
register_t *ap;
@@ -353,6 +356,7 @@ ktrsyscall(ktr)
if (fancy) {
if (ktr->ktr_code == SYS_ioctl) {
const char *cp;
+
if (decimal)
(void)printf("(%ld", (long)*ap);
else
@@ -392,8 +396,7 @@ ktrsyscall(ktr)
}
static void
-ktrsysret(ktr)
- struct ktr_sysret *ktr;
+ktrsysret(struct ktr_sysret *ktr)
{
int ret = ktr->ktr_retval;
int error = ktr->ktr_error;
@@ -428,17 +431,13 @@ ktrsysret(ktr)
}
static void
-ktrnamei(cp, len)
- const char *cp;
- int len;
+ktrnamei(const char *cp, int len)
{
(void)printf("\"%.*s\"\n", len, cp);
}
static void
-ktremul(cp, len)
- char *cp;
- int len;
+ktremul(char *cp, int len)
{
char name[1024];
@@ -453,17 +452,13 @@ ktremul(cp, len)
}
static void
-ktrgenio(ktr, len)
- struct ktr_genio *ktr;
- int len;
+ktrgenio(struct ktr_genio *ktr, int len)
{
- int datalen = len - sizeof (struct ktr_genio);
char *dp = (char *)ktr + sizeof (struct ktr_genio);
- char *cp;
- int col = 0;
- int width;
- char visbuf[5];
+ int datalen = len - sizeof (struct ktr_genio);
static int screenwidth = 0;
+ int col = 0, width;
+ char visbuf[5], *cp;
if (screenwidth == 0) {
struct winsize ws;
@@ -483,6 +478,7 @@ ktrgenio(ktr, len)
for (; datalen > 0; datalen--, dp++) {
(void) vis(visbuf, *dp, VIS_CSTYLE, *(dp+1));
cp = visbuf;
+
/*
* Keep track of printables and
* space chars (like fold(1)).
@@ -491,7 +487,7 @@ ktrgenio(ktr, len)
(void)putchar('\t');
col = 8;
}
- switch(*cp) {
+ switch (*cp) {
case '\n':
col = 0;
(void)putchar('\n');
@@ -517,8 +513,7 @@ ktrgenio(ktr, len)
}
static void
-ktrpsig(psig)
- struct ktr_psig *psig;
+ktrpsig(struct ktr_psig *psig)
{
(void)printf("SIG%s ", sys_signame[psig->signo]);
if (psig->action == SIG_DFL)
@@ -541,27 +536,26 @@ ktrpsig(psig)
}
static void
-ktrcsw(cs)
- struct ktr_csw *cs;
+ktrcsw(struct ktr_csw *cs)
{
(void)printf("%s %s\n", cs->out ? "stop" : "resume",
cs->user ? "user" : "kernel");
}
static void
-usage()
+usage(void)
{
(void)fprintf(stderr,
-"usage: kdump [-dnlRT] [-e emulation] [-f trfile] [-m maxdata] [-t [cnis]]\n");
+"usage: kdump [-dnlRT] [-e emulation] [-p pid] [-f trfile] [-m maxdata] [-t [cnis]]\n");
exit(1);
}
static void
-setemul(name)
- const char *name;
+setemul(const char *name)
{
int i;
+
for (i = 0; emulations[i].name != NULL; i++)
if (strcmp(emulations[i].name, name) == 0) {
current = &emulations[i];