chiark / gitweb /
readahead: add interface to sd-daemon.[ch] to control readahead
[elogind.git] / src / readahead-common.c
index a1016a3ede88c5e695a85affc8963ae7095e441c..a2f6f173e9a1a9aa32dad7c30076207de14f6265 100644 (file)
@@ -24,6 +24,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <sys/sysinfo.h>
+#include <sys/inotify.h>
 
 #include "log.h"
 #include "readahead-common.h"
@@ -116,3 +117,23 @@ bool enough_ram(void) {
                                                * with at least 128MB
                                                * memory */
 }
+
+int open_inotify(void) {
+        int fd;
+
+        if ((fd = inotify_init1(IN_CLOEXEC|IN_NONBLOCK)) < 0) {
+                log_error("Failed to create inotify handle: %m");
+                return -errno;
+        }
+
+        mkdir("/dev/.systemd", 0755);
+        mkdir("/dev/.systemd/readahead", 0755);
+
+        if (inotify_add_watch(fd, "/dev/.systemd/readahead", IN_CREATE) < 0) {
+                log_error("Failed to watch /dev/.systemd/readahead: %m");
+                close_nointr_nofail(fd);
+                return -errno;
+        }
+
+        return fd;
+}