git: e61884183ed4 - stable/14 - libc: Add inotify support
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Wed, 05 Aug 2026 15:16:23 UTC
The branch stable/14 has been updated by markj:
URL: https://cgit.FreeBSD.org/src/commit/?id=e61884183ed4bbe84dfcc242fecd2bffb943af96
commit e61884183ed4bbe84dfcc242fecd2bffb943af96
Author: Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2025-07-03 20:08:59 +0000
Commit: Mark Johnston <markj@FreeBSD.org>
CommitDate: 2026-08-05 15:15:14 +0000
libc: Add inotify support
inotify_init() and inotify_init1() are implemented using __specialfd(2).
inotify_add_watch() is implemented in terms of inotify_add_watch_at(2).
Reviewed by: kib
MFC after: 3 months
Sponsored by: Klara, Inc.
Differential Revision: https://reviews.freebsd.org/D50315
(cherry picked from commit 245ff4c4b2c2728674121a5d9736a5e079bd00b2)
---
lib/libc/gen/Makefile.inc | 1 +
lib/libc/gen/Symbol.map | 3 +++
lib/libc/gen/inotify.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++
lib/libc/sys/Symbol.map | 2 ++
4 files changed, 55 insertions(+)
diff --git a/lib/libc/gen/Makefile.inc b/lib/libc/gen/Makefile.inc
index 271340ca49f7..730be5f9a030 100644
--- a/lib/libc/gen/Makefile.inc
+++ b/lib/libc/gen/Makefile.inc
@@ -95,6 +95,7 @@ SRCS+= __getosreldate.c \
glob.c \
glob-compat11.c \
initgroups.c \
+ inotify.c \
isatty.c \
isinf.c \
isnan.c \
diff --git a/lib/libc/gen/Symbol.map b/lib/libc/gen/Symbol.map
index 890d826c3c6e..7d27c9a79645 100644
--- a/lib/libc/gen/Symbol.map
+++ b/lib/libc/gen/Symbol.map
@@ -463,6 +463,9 @@ FBSD_1.8 {
execvpe;
fdscandir;
fdscandir_b;
+ inotify_add_watch;
+ inotify_init;
+ inotify_init1;
psiginfo;
rtld_get_var;
rtld_set_var;
diff --git a/lib/libc/gen/inotify.c b/lib/libc/gen/inotify.c
new file mode 100644
index 000000000000..b3590e0f5e4d
--- /dev/null
+++ b/lib/libc/gen/inotify.c
@@ -0,0 +1,49 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2025 Klara, Inc.
+ */
+
+#include "namespace.h"
+#include <sys/types.h>
+#include <sys/fcntl.h>
+#include <sys/inotify.h>
+#include <sys/specialfd.h>
+#include "un-namespace.h"
+#include "libc_private.h"
+
+/*
+ * Provide compatibility with libinotify, which uses different values for these
+ * flags.
+ */
+#define IN_NONBLOCK_OLD 0x80000
+#define IN_CLOEXEC_OLD 0x00800
+
+int
+inotify_add_watch(int fd, const char *pathname, uint32_t mask)
+{
+ return (inotify_add_watch_at(fd, AT_FDCWD, pathname, mask));
+}
+
+int
+inotify_init1(int flags)
+{
+ struct specialfd_inotify args;
+
+ if ((flags & IN_NONBLOCK_OLD) != 0) {
+ flags &= ~IN_NONBLOCK_OLD;
+ flags |= IN_NONBLOCK;
+ }
+ if ((flags & IN_CLOEXEC_OLD) != 0) {
+ flags &= ~IN_CLOEXEC_OLD;
+ flags |= IN_CLOEXEC;
+ }
+ args.flags = flags;
+ return (__sys___specialfd(SPECIALFD_INOTIFY, &args, sizeof(args)));
+}
+
+int
+inotify_init(void)
+{
+ return (inotify_init1(0));
+}
diff --git a/lib/libc/sys/Symbol.map b/lib/libc/sys/Symbol.map
index 506d88d46c34..432e89c726e4 100644
--- a/lib/libc/sys/Symbol.map
+++ b/lib/libc/sys/Symbol.map
@@ -426,6 +426,8 @@ FBSD_1.7 {
FBSD_1.8 {
getrlimitusage;
+ inotify_add_watch_at;
+ inotify_rm_watch;
kcmp;
setcred;
};