chiark / gitweb /
modules-load: use /etc/modules-load.d/?*.conf
[elogind.git] / src / readahead-common.c
index 88441dbe1c913e35ae1e21245a760650347485af..a2f6f173e9a1a9aa32dad7c30076207de14f6265 100644 (file)
 #include <stdlib.h>
 #include <string.h>
 #include <sys/sysinfo.h>
+#include <sys/inotify.h>
 
 #include "log.h"
 #include "readahead-common.h"
 #include "util.h"
 
-int file_verify(int fd, const char *fn, struct stat *st) {
+int file_verify(int fd, const char *fn, off_t file_size_max, struct stat *st) {
         assert(fd >= 0);
         assert(fn);
         assert(st);
@@ -44,7 +45,7 @@ int file_verify(int fd, const char *fn, struct stat *st) {
                 return 0;
         }
 
-        if (st->st_size <= 0 || st->st_size > READAHEAD_FILE_SIZE_MAX) {
+        if (st->st_size <= 0 || st->st_size > file_size_max) {
                 log_debug("Not preloading file %s with size out of bounds %zi", fn, st->st_size);
                 return 0;
         }
@@ -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;
+}