chiark / gitweb /
readahead: fix printf format string
[elogind.git] / src / readahead-common.c
index a2f6f173e9a1a9aa32dad7c30076207de14f6265..d76188b71f4c09de305f2a6556059f39b7d98d72 100644 (file)
@@ -25,6 +25,9 @@
 #include <string.h>
 #include <sys/sysinfo.h>
 #include <sys/inotify.h>
 #include <string.h>
 #include <sys/sysinfo.h>
 #include <sys/inotify.h>
+#include <fcntl.h>
+#include <sys/mman.h>
+#include <unistd.h>
 
 #include "log.h"
 #include "readahead-common.h"
 
 #include "log.h"
 #include "readahead-common.h"
@@ -46,7 +49,7 @@ int file_verify(int fd, const char *fn, off_t file_size_max, struct stat *st) {
         }
 
         if (st->st_size <= 0 || st->st_size > 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);
+                log_debug("Not preloading file %s with size out of bounds %llu", fn, (unsigned long long) st->st_size);
                 return 0;
         }
 
                 return 0;
         }
 
@@ -137,3 +140,33 @@ int open_inotify(void) {
 
         return fd;
 }
 
         return fd;
 }
+
+ReadaheadShared *shared_get(void) {
+        int fd;
+        ReadaheadShared *m = NULL;
+
+        mkdir("/dev/.systemd", 0755);
+        mkdir("/dev/.systemd/readahead", 0755);
+
+        if ((fd = open("/dev/.systemd/readahead/shared", O_CREAT|O_RDWR|O_CLOEXEC, 0644)) < 0) {
+                log_error("Failed to create shared memory segment: %m");
+                goto finish;
+        }
+
+        if (ftruncate(fd, sizeof(ReadaheadShared)) < 0) {
+                log_error("Failed to truncate shared memory segment: %m");
+                goto finish;
+        }
+
+        if ((m = mmap(NULL, sizeof(ReadaheadShared), PROT_WRITE|PROT_READ, MAP_SHARED, fd, 0)) == MAP_FAILED) {
+                log_error("Failed to mmap shared memory segment: %m");
+                m = NULL;
+                goto finish;
+        }
+
+finish:
+        if (fd >= 0)
+                close_nointr_nofail(fd);
+
+        return m;
+}