summaryrefslogtreecommitdiff
path: root/src/readahead-common.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2010-09-28 21:46:14 +0200
committerLennart Poettering <lennart@poettering.net>2010-09-28 21:46:30 +0200
commitd9c7a87b35289e9a5ba94c097e861640d1357e6d (patch)
treec6851ed4484e0b98acb8992d8924eb9166bc151d /src/readahead-common.c
parentc457e08335e2458821195efdb6b3dd1d106adff2 (diff)
readahead: ignore replay events when collecting
Diffstat (limited to 'src/readahead-common.c')
-rw-r--r--src/readahead-common.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/readahead-common.c b/src/readahead-common.c
index a2f6f173e9..e01ae607c4 100644
--- a/src/readahead-common.c
+++ b/src/readahead-common.c
@@ -25,6 +25,9 @@
#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"
@@ -137,3 +140,30 @@ int open_inotify(void) {
return fd;
}
+
+ReadaheadShared *shared_get(void) {
+ int fd;
+ ReadaheadShared *m = NULL;
+
+ 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;
+}