diff options
author | Visa Hankala <visa@cvs.openbsd.org> | 2020-08-18 13:41:50 +0000 |
---|---|---|
committer | Visa Hankala <visa@cvs.openbsd.org> | 2020-08-18 13:41:50 +0000 |
commit | f6602c45fa96b34f85e1e52e2686839a9a4e6029 (patch) | |
tree | 94eafa39a40546180282531cc88657f1f1c438a1 /sys/kern/subr_log.c | |
parent | a4f0ae1ddcf873977022b5be5b921fb255fbac38 (diff) |
Fix kn_data returned by filt_logread().
Take into account the circular nature of the message buffer when
computing the number of available bytes. Move the computation into
a separate function and use it with the kevent(2) and ioctl(2)
interfaces.
OK mpi@
Diffstat (limited to 'sys/kern/subr_log.c')
-rw-r--r-- | sys/kern/subr_log.c | 37 |
1 files changed, 21 insertions, 16 deletions
diff --git a/sys/kern/subr_log.c b/sys/kern/subr_log.c index c53f395ccec..093e260ba31 100644 --- a/sys/kern/subr_log.c +++ b/sys/kern/subr_log.c @@ -1,4 +1,4 @@ -/* $OpenBSD: subr_log.c,v 1.67 2020/08/18 13:38:24 visa Exp $ */ +/* $OpenBSD: subr_log.c,v 1.68 2020/08/18 13:41:49 visa Exp $ */ /* $NetBSD: subr_log.c,v 1.11 1996/03/30 22:24:44 christos Exp $ */ /* @@ -95,6 +95,7 @@ const struct filterops logread_filtops = { int dosendsyslog(struct proc *, const char *, size_t, int, enum uio_seg); void logtick(void *); +size_t msgbuf_getlen(struct msgbuf *); void initmsgbuf(caddr_t buf, size_t bufsize) @@ -162,6 +163,20 @@ msgbuf_putchar(struct msgbuf *mbp, const char c) splx(s); } +size_t +msgbuf_getlen(struct msgbuf *mbp) +{ + long len; + int s; + + s = splhigh(); + len = mbp->msg_bufx - mbp->msg_bufr; + if (len < 0) + len += mbp->msg_bufs; + splx(s); + return (len); +} + int logopen(dev_t dev, int flags, int mode, struct proc *p) { @@ -296,14 +311,10 @@ filt_logrdetach(struct knote *kn) int filt_logread(struct knote *kn, long hint) { - struct msgbuf *p = (struct msgbuf *)kn->kn_hook; - int s, event = 0; + struct msgbuf *mbp = kn->kn_hook; - s = splhigh(); - kn->kn_data = (int)(p->msg_bufx - p->msg_bufr); - event = (p->msg_bufx != p->msg_bufr); - splx(s); - return (event); + kn->kn_data = msgbuf_getlen(mbp); + return (kn->kn_data != 0); } void @@ -356,19 +367,13 @@ int logioctl(dev_t dev, u_long com, caddr_t data, int flag, struct proc *p) { struct file *fp; - long l; - int error, s; + int error; switch (com) { /* return number of characters immediately available */ case FIONREAD: - s = splhigh(); - l = msgbufp->msg_bufx - msgbufp->msg_bufr; - splx(s); - if (l < 0) - l += msgbufp->msg_bufs; - *(int *)data = l; + *(int *)data = (int)msgbuf_getlen(msgbufp); break; case FIONBIO: |