summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbluhm <bluhm@openbsd.org>2016-05-17 23:43:47 +0000
committerbluhm <bluhm@openbsd.org>2016-05-17 23:43:47 +0000
commit89e8e827065076b9ace9986dff9a83cb40ca1418 (patch)
tree82519d2b25a1aa8e1b68aaae63a377e8ea145e41
parentRefactor the handling of pledge and the optional user string: The three (diff)
downloadwireguard-openbsd-89e8e827065076b9ace9986dff9a83cb40ca1418.tar.xz
wireguard-openbsd-89e8e827065076b9ace9986dff9a83cb40ca1418.zip
Allow sendsyslog(2) with LOG_CONS even when /dev/console has not
been opened during init(8). Only log with cnwrite() if cn_devvp exists, otherwise use cnputc() as fallback. While there move extern declarations to dev/cons.h. input and OK deraadt@
-rw-r--r--sys/dev/cons.c7
-rw-r--r--sys/dev/cons.h4
-rw-r--r--sys/kern/subr_log.c34
-rw-r--r--sys/kern/subr_prf.c3
-rw-r--r--sys/kern/tty.c5
5 files changed, 37 insertions, 16 deletions
diff --git a/sys/dev/cons.c b/sys/dev/cons.c
index 9ed76068bbe..01aca1302c6 100644
--- a/sys/dev/cons.c
+++ b/sys/dev/cons.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cons.c,v 1.25 2015/03/14 03:38:46 jsg Exp $ */
+/* $OpenBSD: cons.c,v 1.26 2016/05/17 23:43:47 bluhm Exp $ */
/* $NetBSD: cons.c,v 1.30 1996/04/08 19:57:30 jonathan Exp $ */
/*
@@ -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)
diff --git a/sys/dev/cons.h b/sys/dev/cons.h
index 2aebc734339..13689ce5b15 100644
--- a/sys/dev/cons.h
+++ b/sys/dev/cons.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: cons.h,v 1.17 2013/09/29 12:56:31 kettenis Exp $ */
+/* $OpenBSD: cons.h,v 1.18 2016/05/17 23:43:47 bluhm Exp $ */
/* $NetBSD: cons.h,v 1.14 1996/03/14 19:08:35 christos Exp $ */
/*
@@ -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;
diff --git a/sys/kern/subr_log.c b/sys/kern/subr_log.c
index 15ef3812152..e3f66708dec 100644
--- a/sys/kern/subr_log.c
+++ b/sys/kern/subr_log.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: subr_log.c,v 1.40 2016/05/17 23:28:03 bluhm Exp $ */
+/* $OpenBSD: subr_log.c,v 1.41 2016/05/17 23:43:47 bluhm Exp $ */
/* $NetBSD: subr_log.c,v 1.11 1996/03/30 22:24:44 christos Exp $ */
/*
@@ -407,7 +407,7 @@ dosendsyslog(struct proc *p, const char *buf, size_t nbyte, int flags,
struct iovec *ktriov = NULL;
int iovlen;
#endif
- char pri[6];
+ char pri[6], *kbuf;
struct iovec aiov;
struct uio auio;
size_t i, len;
@@ -467,11 +467,34 @@ dosendsyslog(struct proc *p, const char *buf, size_t nbyte, int flags,
len = auio.uio_resid;
if (syslogf)
error = sosend(syslogf->f_data, NULL, &auio, NULL, NULL, 0);
- else
+ else if (cn_devvp)
error = cnwrite(0, &auio, 0);
+ else {
+ /* XXX console redirection breaks down... */
+ 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++) {
+ if (kbuf[i] == '\0')
+ break;
+ cnputc(kbuf[i]);
+ auio.uio_resid--;
+ }
+ if (sflg == UIO_USERSPACE)
+ free(kbuf, M_TEMP, len);
+ }
+
if (error == 0)
len -= auio.uio_resid;
- if (syslogf == NULL) {
+
+ if (syslogf)
+ ;
+ else if (cn_devvp) {
aiov.iov_base = "\r\n";
aiov.iov_len = 2;
auio.uio_iov = &aiov;
@@ -482,7 +505,8 @@ dosendsyslog(struct proc *p, const char *buf, size_t nbyte, int flags,
auio.uio_offset = 0;
auio.uio_resid = aiov.iov_len;
cnwrite(0, &auio, 0);
- }
+ } else
+ cnputc('\n');
#ifdef KTRACE
if (ktriov != NULL) {
diff --git a/sys/kern/subr_prf.c b/sys/kern/subr_prf.c
index 69e2e81faff..bb9c8ea6716 100644
--- a/sys/kern/subr_prf.c
+++ b/sys/kern/subr_prf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: subr_prf.c,v 1.86 2015/09/29 03:19:24 guenther Exp $ */
+/* $OpenBSD: subr_prf.c,v 1.87 2016/05/17 23:43:47 bluhm Exp $ */
/* $NetBSD: subr_prf.c,v 1.45 1997/10/24 18:14:25 chuck Exp $ */
/*-
@@ -99,7 +99,6 @@ struct mutex kprintf_mutex = MUTEX_INITIALIZER(IPL_HIGH);
* 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). */
diff --git a/sys/kern/tty.c b/sys/kern/tty.c
index 8a02edb030d..b64ad17ec84 100644
--- a/sys/kern/tty.c
+++ b/sys/kern/tty.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tty.c,v 1.130 2016/03/19 12:04:15 natano Exp $ */
+/* $OpenBSD: tty.c,v 1.131 2016/05/17 23:43:47 bluhm Exp $ */
/* $NetBSD: tty.c,v 1.68.4.2 1996/06/06 16:04:52 thorpej Exp $ */
/*-
@@ -201,8 +201,6 @@ ttyopen(dev_t device, struct tty *tp, struct proc *p)
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;