summaryrefslogtreecommitdiff
path: root/src/readahead-common.c
diff options
context:
space:
mode:
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;
+}