summaryrefslogtreecommitdiff
path: root/src/sd-daemon.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2010-09-26 15:50:14 +0200
committerLennart Poettering <lennart@poettering.net>2010-09-26 15:50:14 +0200
commit6624768c9c39ab409edebe07cb06ecd93cc6f3ed (patch)
tree977498358b71fcf0bd9c3f8623e9c42d58d72d72 /src/sd-daemon.c
parentf0cf061eda90f60730dbb222675e48d11e8cf757 (diff)
readahead: add interface to sd-daemon.[ch] to control readahead
Diffstat (limited to 'src/sd-daemon.c')
-rw-r--r--src/sd-daemon.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/sd-daemon.c b/src/sd-daemon.c
index 9c23b917f9..316fccc50a 100644
--- a/src/sd-daemon.c
+++ b/src/sd-daemon.c
@@ -433,3 +433,41 @@ int sd_booted(void) {
return a.st_dev != b.st_dev;
#endif
}
+
+static int touch(const char *path) {
+
+#if !defined(DISABLE_SYSTEMD) && defined(__linux__)
+ int fd;
+
+ mkdir("/dev/.systemd", 0755);
+ mkdir("/dev/.systemd/readahead", 0755);
+
+ if ((fd = open(path, O_WRONLY|O_CREAT|O_CLOEXEC|O_NOCTTY, 0666)) < 0)
+ return -errno;
+
+ for (;;) {
+ if (close(fd) >= 0)
+ break;
+
+ if (errno != -EINTR)
+ return -errno;
+ }
+
+#endif
+ return 0;
+}
+
+int sd_readahead(const char *action) {
+
+ if (!action)
+ return -EINVAL;
+
+ if (strcmp(action, "cancel") == 0)
+ return touch("/dev/.systemd/readahead/cancel");
+ else if (strcmp(action, "done") == 0)
+ return touch("/dev/.systemd/readahead/done");
+ else if (strcmp(action, "noreplay") == 0)
+ return touch("/dev/.systemd/readahead/noreplay");
+
+ return -EINVAL;
+}