* Copyright (c) 1991 The Regents of the University of California.
* %sccs.include.redist.c%
"@(#) Copyright (c) 1991 The Regents of the University of California.\n\
static char sccsid
[] = "@(#)dmesg.c 5.10 (Berkeley) %G%";
void err
__P((const char *, ...));
register int ch
, newl
, skip
;
while ((ch
= getopt(argc
, argv
, "M:N:")) != EOF
)
* Discard setgid privileges if not the running kernel so that bad
* guys can't print interesting stuff from kernel memory.
if (memf
!= NULL
|| nlistf
!= NULL
)
/* Read in kernel message buffer, do sanity checks. */
if (kvm_openfiles(nlistf
, memf
, NULL
) == -1)
err("kvm_openfiles: %s", kvm_geterr());
err("kvm_nlist: %s", kvm_geterr());
if (nl
[X_MSGBUF
].n_type
== 0)
err("s: msgbuf not found", nlistf
? nlistf
: "namelist");
kvm_read((void *)nl
[X_MSGBUF
].n_value
, (void *)&cur
, sizeof(cur
));
if (cur
.msg_magic
!= MSG_MAGIC
)
err("magic number incorrect");
if (cur
.msg_bufx
>= MSG_BSIZE
)
* The message buffer is circular; start at the read pointer, and
* go to the write pointer - 1.
p
= cur
.msg_bufc
+ cur
.msg_bufx
;
ep
= cur
.msg_bufc
+ cur
.msg_bufx
- 1;
for (newl
= skip
= 0; p
!= ep
; ++p
) {
if (p
== cur
.msg_bufc
+ MSG_BSIZE
)
/* Skip "\n<.*>" syslog sequences. */
newl
= (ch
= *p
) == '\n';
if (isprint(ch
) || !meta
&& (ch
== ' ' || ch
== '\t' || ch
== '\n'))
(void)putchar(ch
== '\177' ? '?' : ch
| 0100);
err(const char *fmt
, ...)
(void)fprintf(stderr
, "dmesg: ");
(void)vfprintf(stderr
, fmt
, ap
);
(void)fprintf(stderr
, "\n");
(void)fprintf(stderr
, "usage: dmesg [-M core] [-N system]\n");