From 5a8e77ff1345e698bada10562b04a17823bfa1fe Mon Sep 17 00:00:00 2001 From: Baptiste Daroussin Date: Mon, 7 Nov 2022 12:42:04 +0100 Subject: [PATCH 1/2] devctl: allow to register a hook to receive the events --- sys/kern/kern_devctl.c | 16 ++++++++++++++++ sys/sys/devctl.h | 4 ++++ 2 files changed, 20 insertions(+) diff --git a/sys/kern/kern_devctl.c b/sys/kern/kern_devctl.c index 414a2b74cbc7..a4e54a8d8b3e 100644 --- a/sys/kern/kern_devctl.c +++ b/sys/kern/kern_devctl.c @@ -134,6 +134,10 @@ static struct filterops devctl_rfiltops = { static struct cdev *devctl_dev; static void devaddq(const char *type, const char *what, device_t dev); +static struct devctlbridge { + send_event_f *send_f; +} devctl_notify_hook = { .send_f = NULL }; + static void devctl_init(void) { @@ -435,6 +439,8 @@ devctl_notify(const char *system, const char *subsystem, const char *type, if (system == NULL || subsystem == NULL || type == NULL) return; + if (devctl_notify_hook.send_f != NULL) + devctl_notify_hook.send_f(system, subsystem, type, data); dei = devctl_alloc_dei_sb(&sb); if (dei == NULL) return; @@ -569,4 +575,14 @@ devctl_safe_quote_sb(struct sbuf *sb, const char *src) } } +void +devctl_set_notify_hook(send_event_f *hook) +{ + devctl_notify_hook.send_f = hook; +} +void +devctl_unset_notify_hook(void) +{ + devctl_notify_hook.send_f = NULL; +} diff --git a/sys/sys/devctl.h b/sys/sys/devctl.h index b72cd28dfce8..326614514cc1 100644 --- a/sys/sys/devctl.h +++ b/sys/sys/devctl.h @@ -17,6 +17,10 @@ void devctl_notify(const char *__system, const char *__subsystem, const char *__type, const char *__data); struct sbuf; void devctl_safe_quote_sb(struct sbuf *__sb, const char *__src); +typedef void send_event_f(const char *system, const char *subsystem, + const char *type, const char *data); +void devctl_set_notify_hook(send_event_f *hook); +void devctl_unset_notify_hook(void); #endif #endif /* _SYS_DEVCTL_H_ */ -- 2.38.1