summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Shalayeff <mickey@cvs.openbsd.org>2002-06-29 02:58:15 +0000
committerMichael Shalayeff <mickey@cvs.openbsd.org>2002-06-29 02:58:15 +0000
commitc0554ba6d63022a79862679d814744c07c6df2da (patch)
tree237d5924abea3f504264664879af6a4e9edc37cf
parent6fa49d4fc35346c081420a80605527f962dd0e81 (diff)
kqfilter for the log. niels said i can commit it if it works
and i converted syslog to libevent and it works now (;
-rw-r--r--sys/kern/subr_log.c52
-rw-r--r--sys/sys/conf.h6
2 files changed, 54 insertions, 4 deletions
diff --git a/sys/kern/subr_log.c b/sys/kern/subr_log.c
index dd990012764..0921d9e0c0e 100644
--- a/sys/kern/subr_log.c
+++ b/sys/kern/subr_log.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: subr_log.c,v 1.7 2001/04/06 04:42:07 csapuntz Exp $ */
+/* $OpenBSD: subr_log.c,v 1.8 2002/06/29 02:58:14 mickey Exp $ */
/* $NetBSD: subr_log.c,v 1.11 1996/03/30 22:24:44 christos Exp $ */
/*
@@ -69,6 +69,12 @@ int msgbufmapped; /* is the message buffer mapped */
int msgbufenabled; /* is logging to the buffer enabled */
struct msgbuf *msgbufp; /* the mapped buffer, itself. */
+void filt_logrdetach(struct knote *kn);
+int filt_logread(struct knote *kn, long hint);
+
+struct filterops logread_filtops =
+ { 1, NULL, filt_logrdetach, filt_logread};
+
void
initmsgbuf(buf, bufsize)
caddr_t buf;
@@ -198,6 +204,49 @@ logselect(dev, rw, p)
return (0);
}
+int
+logkqfilter(dev_t dev, struct knote *kn)
+{
+ struct klist *klist;
+ int s;
+
+ switch (kn->kn_filter) {
+ case EVFILT_READ:
+ klist = &logsoftc.sc_selp.si_note;
+ kn->kn_fop = &logread_filtops;
+ break;
+ default:
+ return (1);
+ }
+
+ kn->kn_hook = (void *)msgbufp;
+
+ s = splhigh();
+ SLIST_INSERT_HEAD(klist, kn, kn_selnext);
+ splx(s);
+
+ return (0);
+}
+
+void
+filt_logrdetach(struct knote *kn)
+{
+ int s = splhigh();
+
+ SLIST_REMOVE(&logsoftc.sc_selp.si_note, kn, knote, kn_selnext);
+ splx(s);
+}
+
+int
+filt_logread(struct knote *kn, long hint)
+{
+ struct msgbuf *p = (struct msgbuf *)kn->kn_hook;
+
+ kn->kn_data = (int)(p->msg_bufx - p->msg_bufr);
+
+ return (p->msg_bufx != p->msg_bufr);
+}
+
void
logwakeup()
{
@@ -211,6 +260,7 @@ logwakeup()
wakeup((caddr_t)msgbufp);
logsoftc.sc_state &= ~LOG_RDWAIT;
}
+ KNOTE(&logsoftc.sc_selp.si_note, 0);
}
/*ARGSUSED*/
diff --git a/sys/sys/conf.h b/sys/sys/conf.h
index 9372a14e17c..6e1bc2e45d8 100644
--- a/sys/sys/conf.h
+++ b/sys/sys/conf.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: conf.h,v 1.62 2002/06/24 19:00:33 mickey Exp $ */
+/* $OpenBSD: conf.h,v 1.63 2002/06/29 02:58:14 mickey Exp $ */
/* $NetBSD: conf.h,v 1.33 1996/05/03 20:03:32 christos Exp $ */
/*-
@@ -275,12 +275,12 @@ extern struct cdevsw cdevsw[];
dev_init(c,n,tty), dev_init(c,n,select), (dev_type_mmap((*))) enodev, \
D_TTY | D_KQFILTER, ttkqfilter }
-/* open, close, read, ioctl, select, nokqfilter -- XXX should be a generic device */
+/* open, close, read, ioctl, select, kqfilter -- XXX should be a generic device */
#define cdev_log_init(c,n) { \
dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \
(dev_type_write((*))) enodev, dev_init(c,n,ioctl), \
(dev_type_stop((*))) enodev, 0, dev_init(c,n,select), \
- (dev_type_mmap((*))) enodev }
+ (dev_type_mmap((*))) enodev, D_KQFILTER, dev_init(c,n,kqfilter) }
/* open */
#define cdev_fd_init(c,n) { \