diff options
author | Marco Pfatschbacher <mpf@cvs.openbsd.org> | 2015-01-13 10:07:59 +0000 |
---|---|---|
committer | Marco Pfatschbacher <mpf@cvs.openbsd.org> | 2015-01-13 10:07:59 +0000 |
commit | 5b24b13f08f874b5ddcdbd1b3b67aab8b6c0d035 (patch) | |
tree | 6b27f7b8aec09dad4470ca130344e22e9305d158 /sys | |
parent | ca2d9d704351ca6f7b0ee5cabf2dbdb4e7c156c7 (diff) |
Add dmesg -s support, to view the output of rc(8) system startup messages.
Help and feedback by Theo and Miod.
OK deraadt@, manpage-ok jmc@
Diffstat (limited to 'sys')
-rw-r--r-- | sys/kern/kern_sysctl.c | 25 | ||||
-rw-r--r-- | sys/kern/subr_log.c | 20 | ||||
-rw-r--r-- | sys/kern/subr_prf.c | 4 | ||||
-rw-r--r-- | sys/kern/tty.c | 15 | ||||
-rw-r--r-- | sys/sys/msgbuf.h | 6 | ||||
-rw-r--r-- | sys/sys/sysctl.h | 6 |
6 files changed, 55 insertions, 21 deletions
diff --git a/sys/kern/kern_sysctl.c b/sys/kern/kern_sysctl.c index a3f807dc5be..04e08d21fbe 100644 --- a/sys/kern/kern_sysctl.c +++ b/sys/kern/kern_sysctl.c @@ -1,4 +1,4 @@ -/* $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 $ */ /*- @@ -444,19 +444,30 @@ kern_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp, 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)); diff --git a/sys/kern/subr_log.c b/sys/kern/subr_log.c index ec1e2ebb850..6720d5ede34 100644 --- a/sys/kern/subr_log.c +++ b/sys/kern/subr_log.c @@ -1,4 +1,4 @@ -/* $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 $ */ /* @@ -74,8 +74,8 @@ struct logsoftc { 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); @@ -113,17 +113,23 @@ initmsgbuf(caddr_t buf, size_t bufsize) /* 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; diff --git a/sys/kern/subr_prf.c b/sys/kern/subr_prf.c index 899fcb529d5..06f2cc60161 100644 --- a/sys/kern/subr_prf.c +++ b/sys/kern/subr_prf.c @@ -1,4 +1,4 @@ -/* $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 $ */ /*- @@ -349,7 +349,7 @@ kputchar(int c, int flags, struct tty *tp) 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 diff --git a/sys/kern/tty.c b/sys/kern/tty.c index c9b8cc6adbe..419f6e65d90 100644 --- a/sys/kern/tty.c +++ b/sys/kern/tty.c @@ -1,4 +1,4 @@ -/* $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 $ */ /*- @@ -52,6 +52,7 @@ #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> @@ -63,6 +64,7 @@ #include <uvm/uvm_extern.h> +#include <dev/cons.h> #include <dev/rndvar.h> #include "pty.h" @@ -1786,6 +1788,17 @@ loop: } 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 diff --git a/sys/sys/msgbuf.h b/sys/sys/msgbuf.h index bce761e3036..8ca1511b061 100644 --- a/sys/sys/msgbuf.h +++ b/sys/sys/msgbuf.h @@ -1,4 +1,4 @@ -/* $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 $ */ /* @@ -42,8 +42,10 @@ struct msgbuf { 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 diff --git a/sys/sys/sysctl.h b/sys/sys/sysctl.h index 58d53eb1f8c..a8004cdedea 100644 --- a/sys/sys/sysctl.h +++ b/sys/sys/sysctl.h @@ -1,4 +1,4 @@ -/* $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 $ */ /* @@ -182,7 +182,9 @@ struct ctlname { #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 }, \ |