]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
basic: split out inotify-related calls from fs-util.h → inotify-util.h
authorLennart Poettering <lennart@poettering.net>
Tue, 5 Oct 2021 12:44:17 +0000 (14:44 +0200)
committerLennart Poettering <lennart@poettering.net>
Tue, 5 Oct 2021 14:14:37 +0000 (16:14 +0200)
15 files changed:
src/basic/fs-util.c
src/basic/fs-util.h
src/basic/inotify-util.c [new file with mode: 0644]
src/basic/inotify-util.h [new file with mode: 0644]
src/basic/meson.build
src/basic/terminal-util.c
src/core/cgroup.c
src/core/manager.c
src/core/path.c
src/libsystemd/sd-event/event-source.h
src/libsystemd/sd-journal/sd-journal.c
src/libsystemd/sd-network/sd-network.c
src/timesync/wait-sync.c
src/tty-ask-password-agent/tty-ask-password-agent.c
src/udev/udevd.c

index bf771f2e2fb87a6c1956153dfbfeddc818df3de4..a83f35a4c98d328fc551484364d1ea6ac18ca602 100644 (file)
@@ -682,31 +682,6 @@ int unlink_or_warn(const char *filename) {
         return 0;
 }
 
-int inotify_add_watch_fd(int fd, int what, uint32_t mask) {
-        int wd;
-
-        /* This is like inotify_add_watch(), except that the file to watch is not referenced by a path, but by an fd */
-        wd = inotify_add_watch(fd, FORMAT_PROC_FD_PATH(what), mask);
-        if (wd < 0)
-                return -errno;
-
-        return wd;
-}
-
-int inotify_add_watch_and_warn(int fd, const char *pathname, uint32_t mask) {
-        int wd;
-
-        wd = inotify_add_watch(fd, pathname, mask);
-        if (wd < 0) {
-                if (errno == ENOSPC)
-                        return log_error_errno(errno, "Failed to add a watch for %s: inotify watch limit reached", pathname);
-
-                return log_error_errno(errno, "Failed to add a watch for %s: %m", pathname);
-        }
-
-        return wd;
-}
-
 bool unsafe_transition(const struct stat *a, const struct stat *b) {
         /* Returns true if the transition from a to b is safe, i.e. that we never transition from unprivileged to
          * privileged files or directories. Why bother? So that unprivileged code can't symlink to privileged files
index 7120ecd99db7656ad78ec4375da54a9a3d1fe8e9..61a6a81bf3c0c419de7635ae88c9b6f5366848dc 100644 (file)
@@ -6,7 +6,6 @@
 #include <limits.h>
 #include <stdbool.h>
 #include <stdint.h>
-#include <sys/inotify.h>
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <unistd.h>
@@ -67,21 +66,6 @@ int var_tmp_dir(const char **ret);
 
 int unlink_or_warn(const char *filename);
 
-#define INOTIFY_EVENT_MAX (sizeof(struct inotify_event) + NAME_MAX + 1)
-
-#define FOREACH_INOTIFY_EVENT(e, buffer, sz) \
-        for ((e) = &buffer.ev;                                \
-             (uint8_t*) (e) < (uint8_t*) (buffer.raw) + (sz); \
-             (e) = (struct inotify_event*) ((uint8_t*) (e) + sizeof(struct inotify_event) + (e)->len))
-
-union inotify_event_buffer {
-        struct inotify_event ev;
-        uint8_t raw[INOTIFY_EVENT_MAX];
-};
-
-int inotify_add_watch_fd(int fd, int what, uint32_t mask);
-int inotify_add_watch_and_warn(int fd, const char *pathname, uint32_t mask);
-
 enum {
         CHASE_PREFIX_ROOT = 1 << 0, /* The specified path will be prefixed by the specified root before beginning the iteration */
         CHASE_NONEXISTENT = 1 << 1, /* It's OK if the path doesn't actually exist. */
diff --git a/src/basic/inotify-util.c b/src/basic/inotify-util.c
new file mode 100644 (file)
index 0000000..848f859
--- /dev/null
@@ -0,0 +1,29 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+
+#include "fd-util.h"
+#include "inotify-util.h"
+
+int inotify_add_watch_fd(int fd, int what, uint32_t mask) {
+        int wd;
+
+        /* This is like inotify_add_watch(), except that the file to watch is not referenced by a path, but by an fd */
+        wd = inotify_add_watch(fd, FORMAT_PROC_FD_PATH(what), mask);
+        if (wd < 0)
+                return -errno;
+
+        return wd;
+}
+
+int inotify_add_watch_and_warn(int fd, const char *pathname, uint32_t mask) {
+        int wd;
+
+        wd = inotify_add_watch(fd, pathname, mask);
+        if (wd < 0) {
+                if (errno == ENOSPC)
+                        return log_error_errno(errno, "Failed to add a watch for %s: inotify watch limit reached", pathname);
+
+                return log_error_errno(errno, "Failed to add a watch for %s: %m", pathname);
+        }
+
+        return wd;
+}
diff --git a/src/basic/inotify-util.h b/src/basic/inotify-util.h
new file mode 100644 (file)
index 0000000..88af086
--- /dev/null
@@ -0,0 +1,22 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+#pragma once
+
+#include <inttypes.h>
+#include <limits.h>
+#include <stddef.h>
+#include <sys/inotify.h>
+
+#define INOTIFY_EVENT_MAX (offsetof(struct inotify_event, name) + NAME_MAX + 1)
+
+#define FOREACH_INOTIFY_EVENT(e, buffer, sz) \
+        for ((e) = &buffer.ev;                                \
+             (uint8_t*) (e) < (uint8_t*) (buffer.raw) + (sz); \
+             (e) = (struct inotify_event*) ((uint8_t*) (e) + sizeof(struct inotify_event) + (e)->len))
+
+union inotify_event_buffer {
+        struct inotify_event ev;
+        uint8_t raw[INOTIFY_EVENT_MAX];
+};
+
+int inotify_add_watch_fd(int fd, int what, uint32_t mask);
+int inotify_add_watch_and_warn(int fd, const char *pathname, uint32_t mask);
index ac084ce60a3a79f12a0acdaf9506b716ee85f621..0d8100a391333b76113f2bb6359176cb285de5c9 100644 (file)
@@ -72,6 +72,8 @@ basic_sources = files('''
         hostname-util.h
         in-addr-util.c
         in-addr-util.h
+        inotify-util.c
+        inotify-util.h
         io-util.c
         io-util.h
         khash.c
index d769423d6e904ba5ecc003a6ce595af59aae9162..33743f8c4d2374d76fd1d1387740b9b40b09a015 100644 (file)
@@ -26,6 +26,7 @@
 #include "fd-util.h"
 #include "fileio.h"
 #include "fs-util.h"
+#include "inotify-util.h"
 #include "io-util.h"
 #include "log.h"
 #include "macro.h"
index c19454e8bdd219202223b1d2e32370bb33fe77cd..a5770c0332807b26171bafa12f21e164a6a58932 100644 (file)
@@ -18,8 +18,8 @@
 #include "cgroup.h"
 #include "fd-util.h"
 #include "fileio.h"
-#include "fs-util.h"
 #include "in-addr-prefix-util.h"
+#include "inotify-util.h"
 #include "io-util.h"
 #include "ip-protocol-list.h"
 #include "limits-util.h"
index 2e7db509d1fc647f5b533dc576f4fa6757d71bd6..0b2e29ae148be37e127f027d627cb652e9c0f220 100644 (file)
@@ -44,9 +44,9 @@
 #include "exit-status.h"
 #include "fd-util.h"
 #include "fileio.h"
-#include "fs-util.h"
 #include "generator-setup.h"
 #include "hashmap.h"
+#include "inotify-util.h"
 #include "install.h"
 #include "io-util.h"
 #include "label.h"
index 693636b0ee44fa5f9cade896972152a234ebe651..3dd0206e7a8dcdd2e2e8e69c20a7e86eda0ffedd 100644 (file)
@@ -11,8 +11,8 @@
 #include "dbus-unit.h"
 #include "escape.h"
 #include "fd-util.h"
-#include "fs-util.h"
 #include "glob-util.h"
+#include "inotify-util.h"
 #include "macro.h"
 #include "mkdir.h"
 #include "path.h"
index d2dc21470e94d06cdc4f04c24eeebb261e058751..08b409fef181abe1904ca301312f0ee2ed00cb7c 100644 (file)
@@ -7,8 +7,8 @@
 
 #include "sd-event.h"
 
-#include "fs-util.h"
 #include "hashmap.h"
+#include "inotify-util.h"
 #include "list.h"
 #include "prioq.h"
 #include "ratelimit.h"
index fbd2fb38bbfa33bc0ad4c1780edc48c2045a725f..8b7415f0db47c933824071caee725be3688886af 100644 (file)
@@ -25,6 +25,7 @@
 #include "hashmap.h"
 #include "hostname-util.h"
 #include "id128-util.h"
+#include "inotify-util.h"
 #include "io-util.h"
 #include "journal-def.h"
 #include "journal-file.h"
index ee93dae9e3a79965bc1331b1542285286cc9ad42..dc48e918378ea5b88c6aabdc9db49c9c64cda268 100644 (file)
@@ -10,6 +10,7 @@
 #include "env-file.h"
 #include "fd-util.h"
 #include "fs-util.h"
+#include "inotify-util.h"
 #include "macro.h"
 #include "parse-util.h"
 #include "stdio-util.h"
index 892746d5ee62be3380009fddecc85a0861220c01..606b0160a41ce7ee20511b91acaf026d6cc9399e 100644 (file)
@@ -14,7 +14,7 @@
 #include "sd-event.h"
 
 #include "fd-util.h"
-#include "fs-util.h"
+#include "inotify-util.h"
 #include "main-func.h"
 #include "signal-util.h"
 #include "time-util.h"
index 839df8d6d29566687fc3466b09f109f11b896c05..37cfd8bb72c3785e04e1e5a7d6f2c4ef8b0fb2b4 100644 (file)
@@ -24,8 +24,8 @@
 #include "exit-status.h"
 #include "fd-util.h"
 #include "fileio.h"
-#include "fs-util.h"
 #include "hashmap.h"
+#include "inotify-util.h"
 #include "io-util.h"
 #include "macro.h"
 #include "main-func.h"
index 6df580d629a1f5dcef7bccdcd09489ef83a3c314..b73f4776e70e9128121127076d5d1919d6fc0879 100644 (file)
@@ -40,6 +40,7 @@
 #include "format-util.h"
 #include "fs-util.h"
 #include "hashmap.h"
+#include "inotify-util.h"
 #include "io-util.h"
 #include "limits-util.h"
 #include "list.h"