From: robert Date: Sat, 13 Jan 2018 12:58:40 +0000 (+0000) Subject: introduce a filter called EVFILT_DEVICE that can be used to notify X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=586ac5a17b495f9217afcad55bf601907d19d47c;p=openbsd introduce a filter called EVFILT_DEVICE that can be used to notify listeners of device state changes. currently only supports NOTE_CHANGE that will be used by drm(4) ok kettenis@ --- diff --git a/lib/libc/sys/kqueue.2 b/lib/libc/sys/kqueue.2 index 7dbd3a55c9b..41fbc23db6f 100644 --- a/lib/libc/sys/kqueue.2 +++ b/lib/libc/sys/kqueue.2 @@ -1,4 +1,4 @@ -.\" $OpenBSD: kqueue.2,v 1.35 2017/07/10 06:38:07 dlg Exp $ +.\" $OpenBSD: kqueue.2,v 1.36 2018/01/13 12:58:40 robert Exp $ .\" .\" Copyright (c) 2000 Jonathan Lemon .\" All rights reserved. @@ -26,7 +26,7 @@ .\" .\" $FreeBSD: src/lib/libc/sys/kqueue.2,v 1.18 2001/02/14 08:48:35 guido Exp $ .\" -.Dd $Mdocdate: July 10 2017 $ +.Dd $Mdocdate: January 13 2018 $ .Dt KQUEUE 2 .Os .Sh NAME @@ -451,6 +451,19 @@ contains the number of times the timeout has expired since the last call to This filter automatically sets the .Dv EV_CLEAR flag internally. +.It Dv EVFILT_DEVICE +Takes a descriptor as the identifier, and the events to watch for in +.Va fflags , +and returns when one or more of the reuqested events occur on the +descriptor. The events to monitor are: +.Bl -tag -width XXNOTE_CHANGE +.It Dv NOTE_CHANGE +A device change event has occured, e.g. an HDMI cable has been plugged in to a port. +.El +.Pp +On return, +.Va fflags +contains the events which triggered the filter. .El .Sh RETURN VALUES .Fn kqueue diff --git a/sys/kern/kern_event.c b/sys/kern/kern_event.c index 96663208e71..fb9cad360b1 100644 --- a/sys/kern/kern_event.c +++ b/sys/kern/kern_event.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_event.c,v 1.83 2017/12/18 10:10:53 mpi Exp $ */ +/* $OpenBSD: kern_event.c,v 1.84 2018/01/13 12:58:40 robert Exp $ */ /*- * Copyright (c) 1999,2000,2001 Jonathan Lemon @@ -137,6 +137,7 @@ struct filterops *sysfilt_ops[] = { &proc_filtops, /* EVFILT_PROC */ &sig_filtops, /* EVFILT_SIGNAL */ &timer_filtops, /* EVFILT_TIMER */ + &file_filtops, /* EVFILT_DEVICE */ }; void KQREF(struct kqueue *); diff --git a/sys/sys/event.h b/sys/sys/event.h index c3b2b285bfc..e29c1128975 100644 --- a/sys/sys/event.h +++ b/sys/sys/event.h @@ -1,4 +1,4 @@ -/* $OpenBSD: event.h,v 1.29 2017/12/21 21:04:38 millert Exp $ */ +/* $OpenBSD: event.h,v 1.30 2018/01/13 12:58:40 robert Exp $ */ /*- * Copyright (c) 1999,2000,2001 Jonathan Lemon @@ -38,8 +38,9 @@ #define EVFILT_PROC (-5) /* attached to struct process */ #define EVFILT_SIGNAL (-6) /* attached to struct process */ #define EVFILT_TIMER (-7) /* timers */ +#define EVFILT_DEVICE (-8) /* devices */ -#define EVFILT_SYSCOUNT 7 +#define EVFILT_SYSCOUNT 8 #define EV_SET(kevp_, a, b, c, d, e, f) do { \ struct kevent *kevp = (kevp_); \ @@ -111,6 +112,9 @@ struct kevent { #define NOTE_TRACKERR 0x00000002 /* could not track child */ #define NOTE_CHILD 0x00000004 /* am a child process */ +/* data/hint flags for EVFILT_DEVICE, shared with userspace */ +#define NOTE_CHANGE 0x00000001 /* device change event */ + /* * This is currently visible to userland to work around broken * programs which pull in or .