clean up import
This commit is contained in:
parent
acdc4b7e70
commit
7b442030ed
@ -1,5 +1,4 @@
|
|||||||
# from: @(#)Makefile 5.6 (Berkeley) 5/2/91
|
# @(#)Makefile 8.1 (Berkeley) 6/5/93
|
||||||
# $Id: Makefile,v 1.5 1994/01/28 00:34:52 cgd Exp $
|
|
||||||
|
|
||||||
PROG= dmesg
|
PROG= dmesg
|
||||||
MAN8= dmesg.0
|
MAN8= dmesg.0
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
.\" Copyright (c) 1980, 1991 Regents of the University of California.
|
.\" Copyright (c) 1980, 1991, 1993
|
||||||
.\" All rights reserved.
|
.\" The Regents of the University of California. All rights reserved.
|
||||||
.\"
|
.\"
|
||||||
.\" Redistribution and use in source and binary forms, with or without
|
.\" Redistribution and use in source and binary forms, with or without
|
||||||
.\" modification, are permitted provided that the following conditions
|
.\" modification, are permitted provided that the following conditions
|
||||||
@ -29,10 +29,9 @@
|
|||||||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
.\" SUCH DAMAGE.
|
.\" SUCH DAMAGE.
|
||||||
.\"
|
.\"
|
||||||
.\" from: @(#)dmesg.8 6.5 (Berkeley) 5/2/91
|
.\" @(#)dmesg.8 8.1 (Berkeley) 6/5/93
|
||||||
.\" $Id: dmesg.8,v 1.6 1993/08/01 07:39:28 mycroft Exp $
|
|
||||||
.\"
|
.\"
|
||||||
.Dd May 2, 1991
|
.Dd June 5, 1993
|
||||||
.Dt DMESG 8
|
.Dt DMESG 8
|
||||||
.Os BSD 4
|
.Os BSD 4
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
@ -53,14 +52,7 @@ Extract values associated with the name list from the specified core
|
|||||||
instead of the default ``/dev/kmem''.
|
instead of the default ``/dev/kmem''.
|
||||||
.It Fl N
|
.It Fl N
|
||||||
Extract the name list from the specified system instead of the default
|
Extract the name list from the specified system instead of the default
|
||||||
``/netbsd''.
|
``/vmunix''.
|
||||||
.El
|
|
||||||
.Sh FILES
|
|
||||||
.Bl -tag -width /dev/kmem -compact
|
|
||||||
.It Pa /dev/kmem
|
|
||||||
default kernel memory
|
|
||||||
.It Pa /netbsd
|
|
||||||
default system namelist
|
|
||||||
.El
|
.El
|
||||||
.Sh SEE ALSO
|
.Sh SEE ALSO
|
||||||
.Xr syslogd 8
|
.Xr syslogd 8
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*-
|
/*-
|
||||||
* Copyright (c) 1991 The Regents of the University of California.
|
* Copyright (c) 1991, 1993
|
||||||
* All rights reserved.
|
* The Regents of the University of California. All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
@ -32,53 +32,59 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef lint
|
#ifndef lint
|
||||||
char copyright[] =
|
static char copyright[] =
|
||||||
"@(#) Copyright (c) 1991 The Regents of the University of California.\n\
|
"@(#) Copyright (c) 1991, 1993\n\
|
||||||
All rights reserved.\n";
|
The Regents of the University of California. All rights reserved.\n";
|
||||||
#endif /* not lint */
|
#endif /* not lint */
|
||||||
|
|
||||||
#ifndef lint
|
#ifndef lint
|
||||||
/*static char sccsid[] = "from: @(#)dmesg.c 5.9 (Berkeley) 5/2/91";*/
|
static char sccsid[] = "@(#)dmesg.c 8.1 (Berkeley) 6/5/93";
|
||||||
static char rcsid[] = "$Id: dmesg.c,v 1.5 1993/10/13 18:33:58 jtc Exp $";
|
|
||||||
#endif /* not lint */
|
#endif /* not lint */
|
||||||
|
|
||||||
#include <sys/cdefs.h>
|
#include <sys/cdefs.h>
|
||||||
#include <sys/msgbuf.h>
|
#include <sys/msgbuf.h>
|
||||||
#include <time.h>
|
|
||||||
#include <nlist.h>
|
#include <fcntl.h>
|
||||||
#include <kvm.h>
|
#include <kvm.h>
|
||||||
#include <stdlib.h>
|
#include <limits.h>
|
||||||
|
#include <nlist.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <ctype.h>
|
#include <stdlib.h>
|
||||||
|
#include <time.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <vis.h>
|
||||||
|
|
||||||
struct nlist nl[] = {
|
struct nlist nl[] = {
|
||||||
#define X_MSGBUFP 0
|
#define X_MSGBUF 0
|
||||||
{ "_msgbufp" },
|
{ "_msgbufp" },
|
||||||
{ NULL },
|
{ NULL },
|
||||||
};
|
};
|
||||||
|
|
||||||
void usage(), vputc();
|
void usage __P((void));
|
||||||
void err __P((const char *, ...));
|
|
||||||
|
|
||||||
|
#define KREAD(addr, var) \
|
||||||
|
kvm_read(kd, addr, &var, sizeof(var)) != sizeof(var)
|
||||||
|
|
||||||
|
int
|
||||||
main(argc, argv)
|
main(argc, argv)
|
||||||
int argc;
|
int argc;
|
||||||
char **argv;
|
char *argv[];
|
||||||
{
|
{
|
||||||
register int ch, newl, skip;
|
register int ch, newl, skip;
|
||||||
register char *p, *ep;
|
register char *p, *ep;
|
||||||
struct msgbuf cur;
|
struct msgbuf *bufp, cur;
|
||||||
int msgbufat;
|
char *memf, *nlistf;
|
||||||
char *core, *namelist;
|
kvm_t *kd;
|
||||||
|
char buf[5];
|
||||||
|
|
||||||
core = namelist = NULL;
|
memf = nlistf = NULL;
|
||||||
while ((ch = getopt(argc, argv, "M:N:")) != EOF)
|
while ((ch = getopt(argc, argv, "M:N:")) != EOF)
|
||||||
switch(ch) {
|
switch(ch) {
|
||||||
case 'M':
|
case 'M':
|
||||||
core = optarg;
|
memf = optarg;
|
||||||
break;
|
break;
|
||||||
case 'N':
|
case 'N':
|
||||||
namelist = optarg;
|
nlistf = optarg;
|
||||||
break;
|
break;
|
||||||
case '?':
|
case '?':
|
||||||
default:
|
default:
|
||||||
@ -87,18 +93,25 @@ main(argc, argv)
|
|||||||
argc -= optind;
|
argc -= optind;
|
||||||
argv += optind;
|
argv += optind;
|
||||||
|
|
||||||
/* Read in kernel message buffer, do sanity checks. */
|
/*
|
||||||
if (kvm_openfiles(namelist, core, NULL) == -1)
|
* Discard setgid privileges if not the running kernel so that bad
|
||||||
err("kvm_openfiles: %s", kvm_geterr());
|
* guys can't print interesting stuff from kernel memory.
|
||||||
if (kvm_nlist(nl) == -1)
|
*/
|
||||||
err("kvm_nlist: %s", kvm_geterr());
|
if (memf != NULL || nlistf != NULL)
|
||||||
if (nl[X_MSGBUFP].n_type == 0)
|
setgid(getgid());
|
||||||
err("msgbufp not found namelist");
|
|
||||||
|
|
||||||
kvm_read((void *)nl[X_MSGBUFP].n_value, (void *)&msgbufat, sizeof(msgbufat));
|
/* Read in kernel message buffer, do sanity checks. */
|
||||||
kvm_read((void *)msgbufat, (void *)&cur, sizeof(cur));
|
if ((kd = kvm_open(nlistf, memf, NULL, O_RDONLY, "dmesg")) == NULL)
|
||||||
|
exit (1);
|
||||||
|
if (kvm_nlist(kd, nl) == -1)
|
||||||
|
errx(1, "kvm_nlist: %s", kvm_geterr(kd));
|
||||||
|
if (nl[X_MSGBUF].n_type == 0)
|
||||||
|
errx(1, "%s: msgbufp not found", nlistf ? nlistf : "namelist");
|
||||||
|
if (KREAD(nl[X_MSGBUF].n_value, bufp) || KREAD((long)bufp, cur))
|
||||||
|
errx(1, "kvm_read: %s", kvm_geterr(kd));
|
||||||
|
kvm_close(kd);
|
||||||
if (cur.msg_magic != MSG_MAGIC)
|
if (cur.msg_magic != MSG_MAGIC)
|
||||||
err("magic number incorrect");
|
errx(1, "magic number incorrect");
|
||||||
if (cur.msg_bufx >= MSG_BSIZE)
|
if (cur.msg_bufx >= MSG_BSIZE)
|
||||||
cur.msg_bufx = 0;
|
cur.msg_bufx = 0;
|
||||||
|
|
||||||
@ -124,64 +137,18 @@ main(argc, argv)
|
|||||||
}
|
}
|
||||||
if (ch == '\0')
|
if (ch == '\0')
|
||||||
continue;
|
continue;
|
||||||
newl = (ch = *p) == '\n';
|
newl = ch == '\n';
|
||||||
vputc(ch);
|
(void)vis(buf, ch, 0, 0);
|
||||||
|
if (buf[1] == 0)
|
||||||
|
(void)putchar(buf[0]);
|
||||||
|
else
|
||||||
|
(void)printf("%s", buf);
|
||||||
}
|
}
|
||||||
if (!newl)
|
if (!newl)
|
||||||
(void)putchar('\n');
|
(void)putchar('\n');
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
vputc(ch)
|
|
||||||
register int ch;
|
|
||||||
{
|
|
||||||
int meta;
|
|
||||||
|
|
||||||
if (!isascii(ch)) {
|
|
||||||
(void)putchar('M');
|
|
||||||
(void)putchar('-');
|
|
||||||
ch = toascii(ch);
|
|
||||||
meta = 1;
|
|
||||||
} else
|
|
||||||
meta = 0;
|
|
||||||
if (isprint(ch) || !meta && (ch == ' ' || ch == '\t' || ch == '\n'))
|
|
||||||
(void)putchar(ch);
|
|
||||||
else {
|
|
||||||
(void)putchar('^');
|
|
||||||
(void)putchar(ch == '\177' ? '?' : ch | 0100);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#if __STDC__
|
|
||||||
#include <stdarg.h>
|
|
||||||
#else
|
|
||||||
#include <varargs.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void
|
|
||||||
#if __STDC__
|
|
||||||
err(const char *fmt, ...)
|
|
||||||
#else
|
|
||||||
err(fmt, va_alist)
|
|
||||||
char *fmt;
|
|
||||||
va_dcl
|
|
||||||
#endif
|
|
||||||
{
|
|
||||||
va_list ap;
|
|
||||||
#if __STDC__
|
|
||||||
va_start(ap, fmt);
|
|
||||||
#else
|
|
||||||
va_start(ap);
|
|
||||||
#endif
|
|
||||||
(void)fprintf(stderr, "dmesg: ");
|
|
||||||
(void)vfprintf(stderr, fmt, ap);
|
|
||||||
va_end(ap);
|
|
||||||
(void)fprintf(stderr, "\n");
|
|
||||||
exit(1);
|
|
||||||
/* NOTREACHED */
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
usage()
|
usage()
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user