On Fri, May 13, 2016 at 11:43:43AM +0100, Dimitris Papastamos wrote: > After I rebuilt and booted the kernel today I noticed dmesg -s > produces no output. I suspect this is to do with the recent change:
Here is alternative way to fix sendsyslog(2) with LOG_CONS. I also works when /dev/console is revoked and it does not break dmesg -s. bluhm Index: dev/cons.c =================================================================== RCS file: /data/mirror/openbsd/cvs/src/sys/dev/cons.c,v retrieving revision 1.25 diff -u -p -r1.25 cons.c --- dev/cons.c 14 Mar 2015 03:38:46 -0000 1.25 +++ dev/cons.c 13 May 2016 21:25:49 -0000 @@ -50,9 +50,8 @@ #include <dev/cons.h> -struct tty *constty = NULL; /* virtual console output device */ -struct vnode *cn_devvp; /* vnode for underlying device. */ -extern struct consdev *cn_tab; /* physical console device info */ +struct tty *constty = NULL; /* virtual console output device */ +struct vnode *cn_devvp = NULLVP; /* vnode for underlying device. */ int cnopen(dev_t dev, int flag, int mode, struct proc *p) Index: dev/cons.h =================================================================== RCS file: /data/mirror/openbsd/cvs/src/sys/dev/cons.h,v retrieving revision 1.17 diff -u -p -r1.17 cons.h --- dev/cons.h 29 Sep 2013 12:56:31 -0000 1.17 +++ dev/cons.h 13 May 2016 21:25:49 -0000 @@ -70,6 +70,8 @@ struct consdev { extern struct consdev constab[]; extern struct consdev *cn_tab; +extern struct tty *constty; +extern struct vnode *cn_devvp; struct knote; Index: kern/init_main.c =================================================================== RCS file: /data/mirror/openbsd/cvs/src/sys/kern/init_main.c,v retrieving revision 1.252 diff -u -p -r1.252 init_main.c --- kern/init_main.c 10 May 2016 23:54:00 -0000 1.252 +++ kern/init_main.c 13 May 2016 21:38:49 -0000 @@ -120,7 +120,7 @@ struct proc *reaperproc; extern struct user *proc0paddr; -struct vnode *rootvp, *swapdev_vp, *consolevp; +struct vnode *rootvp, *swapdev_vp; int boothowto; struct timespec boottime; int ncpus = 1; @@ -133,7 +133,7 @@ long __guard_local __attribute__((sectio /* XXX return int so gcc -Werror won't complain */ int main(void *); -void open_console(struct proc *); +void check_console(struct proc *); void start_init(void *); void start_cleaner(void *); void start_update(void *); @@ -570,30 +570,20 @@ static char *initpaths[] = { }; void -open_console(struct proc *p) +check_console(struct proc *p) { struct nameidata nd; - struct vnode *vp; int error; NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, "/dev/console", p); - error = vn_open(&nd, FWRITE, 0); + error = namei(&nd); if (error) { if (error == ENOENT) printf("warning: /dev/console does not exist\n"); else printf("warning: /dev/console error %d\n", error); - return; - } - vp = nd.ni_vp; - VOP_UNLOCK(vp, p); - if (!ISSET(vp->v_flag, VISTTY)) { - printf("warning: /dev/console is not a tty device\n"); - vn_close(vp, FWRITE, p->p_ucred, p); - return; - } - - consolevp = vp; + } else + vrele(nd.ni_vp); } /* @@ -626,7 +616,7 @@ start_init(void *arg) while (start_init_exec == 0) (void) tsleep((void *)&start_init_exec, PWAIT, "initexec", 0); - open_console(p); + check_console(p); /* process 0 ignores SIGCHLD, but we can't */ p->p_p->ps_sigacts->ps_flags = 0; Index: kern/subr_log.c =================================================================== RCS file: /data/mirror/openbsd/cvs/src/sys/kern/subr_log.c,v retrieving revision 1.39 diff -u -p -r1.39 subr_log.c --- kern/subr_log.c 10 May 2016 23:54:00 -0000 1.39 +++ kern/subr_log.c 13 May 2016 21:28:27 -0000 @@ -407,7 +407,7 @@ dosendsyslog(struct proc *p, const char struct iovec *ktriov = NULL; int iovlen; #endif - char pri[6]; + char pri[6], *kbuf; struct iovec aiov; struct uio auio; size_t i, len; @@ -415,7 +415,7 @@ dosendsyslog(struct proc *p, const char if (syslogf) FREF(syslogf); - else if (!ISSET(flags, LOG_CONS) || consolevp == NULL) + else if (!ISSET(flags, LOG_CONS)) return (ENOTCONN); else { /* @@ -467,21 +467,42 @@ dosendsyslog(struct proc *p, const char len = auio.uio_resid; if (syslogf) error = sosend(syslogf->f_data, NULL, &auio, NULL, NULL, 0); - else - error = cnwrite(0, &auio, 0); + else { + if (cn_devvp == NULLVP) { + if (sflg == UIO_USERSPACE) { + kbuf = malloc(len, M_TEMP, M_WAITOK); + error = copyin(aiov.iov_base, kbuf, len); + } else { + kbuf = aiov.iov_base; + error = 0; + } + if (error == 0) + for (i = 0; i < len; i++) { + cnputc(kbuf[i]); + auio.uio_resid--; + } + if (sflg == UIO_USERSPACE) + free(kbuf, M_TEMP, len); + } else + error = cnwrite(0, &auio, 0); + } if (error == 0) len -= auio.uio_resid; if (syslogf == NULL) { - aiov.iov_base = "\r\n"; - aiov.iov_len = 2; - auio.uio_iov = &aiov; - auio.uio_iovcnt = 1; - auio.uio_segflg = UIO_SYSSPACE; - auio.uio_rw = UIO_WRITE; - auio.uio_procp = p; - auio.uio_offset = 0; - auio.uio_resid = aiov.iov_len; - cnwrite(0, &auio, 0); + if (cn_devvp == NULLVP) { + cnputc('\n'); + } else { + aiov.iov_base = "\r\n"; + aiov.iov_len = 2; + auio.uio_iov = &aiov; + auio.uio_iovcnt = 1; + auio.uio_segflg = UIO_SYSSPACE; + auio.uio_rw = UIO_WRITE; + auio.uio_procp = p; + auio.uio_offset = 0; + auio.uio_resid = aiov.iov_len; + cnwrite(0, &auio, 0); + } } #ifdef KTRACE Index: kern/subr_prf.c =================================================================== RCS file: /data/mirror/openbsd/cvs/src/sys/kern/subr_prf.c,v retrieving revision 1.86 diff -u -p -r1.86 subr_prf.c --- kern/subr_prf.c 29 Sep 2015 03:19:24 -0000 1.86 +++ kern/subr_prf.c 13 May 2016 21:27:06 -0000 @@ -99,7 +99,6 @@ struct mutex kprintf_mutex = MUTEX_INITI * globals */ -extern struct tty *constty; /* pointer to console "window" tty */ extern int log_open; /* subr_log: is /dev/klog open? */ const char *panicstr; /* arg to first call to panic (used as a flag to indicate that panic has already been called). */ Index: kern/tty.c =================================================================== RCS file: /data/mirror/openbsd/cvs/src/sys/kern/tty.c,v retrieving revision 1.130 diff -u -p -r1.130 tty.c --- kern/tty.c 19 Mar 2016 12:04:15 -0000 1.130 +++ kern/tty.c 13 May 2016 21:41:33 -0000 @@ -201,8 +201,6 @@ ttyopen(dev_t device, struct tty *tp, st int ttyclose(struct tty *tp) { - extern struct tty *constty; /* Temporary virtual console. */ - if (constty == tp) constty = NULL; @@ -719,7 +717,6 @@ ttyoutput(int c, struct tty *tp) int ttioctl(struct tty *tp, u_long cmd, caddr_t data, int flag, struct proc *p) { - extern struct tty *constty; /* Temporary virtual console. */ extern int nlinesw; struct process *pr = p->p_p; int s, error; Index: sys/systm.h =================================================================== RCS file: /data/mirror/openbsd/cvs/src/sys/sys/systm.h,v retrieving revision 1.112 diff -u -p -r1.112 systm.h --- sys/systm.h 10 May 2016 23:54:01 -0000 1.112 +++ sys/systm.h 13 May 2016 21:32:27 -0000 @@ -99,8 +99,6 @@ extern struct vnode *rootvp; /* vnode eq extern dev_t swapdev; /* swapping device */ extern struct vnode *swapdev_vp;/* vnode equivalent to above */ -extern struct vnode *consolevp; /* vnode of console tty device */ - struct proc; struct process; #define curproc curcpu()->ci_curproc