Help and feedback by Theo and Miod.
OK deraadt@, manpage-ok jmc@
-.\" $OpenBSD: dmesg.8,v 1.14 2013/08/14 06:32:35 jmc Exp $
+.\" $OpenBSD: dmesg.8,v 1.15 2015/01/13 10:07:58 mpf Exp $
.\" $NetBSD: dmesg.8,v 1.9 1995/03/18 14:54:47 cgd Exp $
.\"
.\" Copyright (c) 1980, 1991, 1993
.\"
.\" @(#)dmesg.8 8.1 (Berkeley) 6/5/93
.\"
-.Dd $Mdocdate: August 14 2013 $
+.Dd $Mdocdate: January 13 2015 $
.Dt DMESG 8
.Os
.Sh NAME
.Nd display the system message buffer
.Sh SYNOPSIS
.Nm dmesg
+.Op Fl s
.Op Fl M Ar core
.Op Fl N Ar system
.Sh DESCRIPTION
.Ar system
instead of the default
.Pa /bsd .
+.It Fl s
+Display the contents of the console message buffer instead.
+This can be used to review
+.Xr rc 8
+system startup messages.
+This option is limited to the superuser.
.El
.Sh FILES
.Bl -tag -width /var/run/dmesg.boot -compact
-/* $OpenBSD: dmesg.c,v 1.23 2014/04/22 20:43:12 tedu Exp $ */
+/* $OpenBSD: dmesg.c,v 1.24 2015/01/13 10:07:58 mpf Exp $ */
/* $NetBSD: dmesg.c,v 1.8 1995/03/18 14:54:49 cgd Exp $ */
/*-
char *p;
struct msgbuf cur;
char *memf, *nlistf, *bufdata = NULL;
+ int startupmsgs = 0;
char buf[5];
memf = nlistf = NULL;
- while ((ch = getopt(argc, argv, "M:N:")) != -1)
+ while ((ch = getopt(argc, argv, "sM:N:")) != -1)
switch(ch) {
+ case 's':
+ startupmsgs = 1;
+ break;
case 'M':
memf = optarg;
break;
size_t len;
mib[0] = CTL_KERN;
- mib[1] = KERN_MSGBUFSIZE;
+ mib[1] = startupmsgs ? KERN_CONSBUFSIZE : KERN_MSGBUFSIZE;
len = sizeof(msgbufsize);
if (sysctl(mib, 2, &msgbufsize, &len, NULL, 0))
err(1, "sysctl: KERN_MSGBUFSIZE");
if (bufdata == NULL)
errx(1, "couldn't allocate space for buffer data");
- mib[1] = KERN_MSGBUF;
+ mib[1] = startupmsgs ? KERN_CONSBUF : KERN_MSGBUF;
len = msgbufsize;
if (sysctl(mib, 2, bufdata, &len, NULL, 0))
err(1, "sysctl: KERN_MSGBUF");
{
extern char *__progname;
- fprintf(stderr, "usage: %s [-M core] [-N system]\n", __progname);
+ fprintf(stderr, "usage: %s [-s] [-M core] [-N system]\n", __progname);
exit(1);
}
-/* $OpenBSD: kern_sysctl.c,v 1.277 2014/12/12 07:45:46 tedu Exp $ */
+/* $OpenBSD: kern_sysctl.c,v 1.278 2015/01/13 10:07:58 mpf Exp $ */
/* $NetBSD: kern_sysctl.c,v 1.17 1996/05/20 17:49:05 mrg Exp $ */
/*-
return (sysctl_rdint(oldp, oldlenp, newp, 0));
#endif
case KERN_MSGBUFSIZE:
+ case KERN_CONSBUFSIZE: {
+ struct msgbuf *mp;
+ mp = (name[0] == KERN_MSGBUFSIZE) ? msgbufp : consbufp;
/*
* deal with cases where the message buffer has
* become corrupted.
*/
- if (!msgbufp || msgbufp->msg_magic != MSG_MAGIC)
+ if (!mp || mp->msg_magic != MSG_MAGIC)
return (ENXIO);
- return (sysctl_rdint(oldp, oldlenp, newp, msgbufp->msg_bufs));
- case KERN_MSGBUF:
+ return (sysctl_rdint(oldp, oldlenp, newp, mp->msg_bufs));
+ }
+ case KERN_CONSBUF:
+ if ((error = suser(p, 0)))
+ return (error);
+ /* FALLTHROUGH */
+ case KERN_MSGBUF: {
+ struct msgbuf *mp;
+ mp = (name[0] == KERN_MSGBUF) ? msgbufp : consbufp;
/* see note above */
- if (!msgbufp || msgbufp->msg_magic != MSG_MAGIC)
+ if (!mp || mp->msg_magic != MSG_MAGIC)
return (ENXIO);
- return (sysctl_rdstruct(oldp, oldlenp, newp, msgbufp,
- msgbufp->msg_bufs + offsetof(struct msgbuf, msg_bufc)));
+ return (sysctl_rdstruct(oldp, oldlenp, newp, mp,
+ mp->msg_bufs + offsetof(struct msgbuf, msg_bufc)));
+ }
case KERN_MALLOCSTATS:
return (sysctl_malloc(name + 1, namelen - 1, oldp, oldlenp,
newp, newlen, p));
-/* $OpenBSD: subr_log.c,v 1.25 2014/12/13 21:05:33 doug Exp $ */
+/* $OpenBSD: subr_log.c,v 1.26 2015/01/13 10:07:58 mpf Exp $ */
/* $NetBSD: subr_log.c,v 1.11 1996/03/30 22:24:44 christos Exp $ */
/*
int log_open; /* also used in log() */
int msgbufmapped; /* is the message buffer mapped */
-int msgbufenabled; /* is logging to the buffer enabled */
struct msgbuf *msgbufp; /* the mapped buffer, itself. */
+struct msgbuf *consbufp; /* console message buffer. */
struct file *syslogf;
void filt_logrdetach(struct knote *kn);
/* Always start new buffer data on a new line. */
if (mbp->msg_bufx > 0 && mbp->msg_bufc[mbp->msg_bufx - 1] != '\n')
- msgbuf_putchar('\n');
+ msgbuf_putchar(msgbufp, '\n');
/* mark it as ready for use. */
- msgbufmapped = msgbufenabled = 1;
+ msgbufmapped = 1;
+
+ /* Set up a buffer to collect /dev/console output */
+ consbufp = malloc(CONSBUFSIZE, M_TEMP, M_NOWAIT|M_ZERO);
+ if (consbufp) {
+ new_bufs = CONSBUFSIZE - offsetof(struct msgbuf, msg_bufc);
+ consbufp->msg_magic = MSG_MAGIC;
+ consbufp->msg_bufs = new_bufs;
+ }
}
void
-msgbuf_putchar(const char c)
+msgbuf_putchar(struct msgbuf *mbp, const char c)
{
- struct msgbuf *mbp = msgbufp;
-
if (mbp->msg_magic != MSG_MAGIC)
/* Nothing we can do */
return;
-/* $OpenBSD: subr_prf.c,v 1.83 2014/07/13 23:49:40 uebayasi Exp $ */
+/* $OpenBSD: subr_prf.c,v 1.84 2015/01/13 10:07:58 mpf Exp $ */
/* $NetBSD: subr_prf.c,v 1.45 1997/10/24 18:14:25 chuck Exp $ */
/*-
constty = NULL;
if ((flags & TOLOG) &&
c != '\0' && c != '\r' && c != 0177 && msgbufmapped)
- msgbuf_putchar(c);
+ msgbuf_putchar(msgbufp, c);
if ((flags & TOCONS) && (constty == NULL || ddb_active) && c != '\0')
(*v_putc)(c);
#ifdef DDB
-/* $OpenBSD: tty.c,v 1.119 2014/12/17 19:42:15 tedu Exp $ */
+/* $OpenBSD: tty.c,v 1.120 2015/01/13 10:07:58 mpf Exp $ */
/* $NetBSD: tty.c,v 1.68.4.2 1996/06/06 16:04:52 thorpej Exp $ */
/*-
#include <sys/lock.h>
#include <sys/syslog.h>
#include <sys/malloc.h>
+#include <sys/msgbuf.h>
#include <sys/signalvar.h>
#include <sys/resourcevar.h>
#include <sys/sysctl.h>
#include <uvm/uvm_extern.h>
+#include <dev/cons.h>
#include <dev/rndvar.h>
#include "pty.h"
}
if (cc > obufcc)
obufcc = cc;
+
+ /* duplicate /dev/console output into console buffer */
+ if (consbufp && cn_tab &&
+ cn_tab->cn_dev == tp->t_dev && tp->t_gen == 0) {
+ int i;
+ for (i = 0; i < cc; i++) {
+ char c = cp[i];
+ if (c != '\0' && c != '\r' && c != 0177)
+ msgbuf_putchar(consbufp, c);
+ }
+ }
}
/*
* If nothing fancy need be done, grab those characters we
-/* $OpenBSD: msgbuf.h,v 1.8 2005/04/14 21:58:50 krw Exp $ */
+/* $OpenBSD: msgbuf.h,v 1.9 2015/01/13 10:07:58 mpf Exp $ */
/* $NetBSD: msgbuf.h,v 1.8 1995/03/26 20:24:27 jtc Exp $ */
/*
char msg_bufc[1]; /* buffer */
};
#ifdef _KERNEL
+#define CONSBUFSIZE (16 * 1024) /* console message buffer size */
extern struct msgbuf *msgbufp;
+extern struct msgbuf *consbufp;
void initmsgbuf(caddr_t buf, size_t bufsize);
-void msgbuf_putchar(const char c);
+void msgbuf_putchar(struct msgbuf *, const char c);
#endif
-/* $OpenBSD: sysctl.h,v 1.153 2014/12/12 07:45:46 tedu Exp $ */
+/* $OpenBSD: sysctl.h,v 1.154 2015/01/13 10:07:58 mpf Exp $ */
/* $NetBSD: sysctl.h,v 1.16 1996/04/09 20:55:36 cgd Exp $ */
/*
#define KERN_PROC_NOBROADCASTKILL 79 /* node: proc no broadcast kill */
#define KERN_PROC_VMMAP 80 /* node: proc vmmap */
#define KERN_GLOBAL_PTRACE 81 /* allow ptrace globally */
-#define KERN_MAXID 82 /* number of valid kern ids */
+#define KERN_CONSBUFSIZE 82 /* int: console message buffer size */
+#define KERN_CONSBUF 83 /* console message buffer */
+#define KERN_MAXID 84 /* number of valid kern ids */
#define CTL_KERN_NAMES { \
{ 0, 0 }, \