1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
4 Copyright 2010 Lennart Poettering
6 Permission is hereby granted, free of charge, to any person
7 obtaining a copy of this software and associated documentation files
8 (the "Software"), to deal in the Software without restriction,
9 including without limitation the rights to use, copy, modify, merge,
10 publish, distribute, sublicense, and/or sell copies of the Software,
11 and to permit persons to whom the Software is furnished to do so,
12 subject to the following conditions:
14 The above copyright notice and this permission notice shall be
15 included in all copies or substantial portions of the Software.
17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
21 BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
22 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
34 #include <sys/types.h>
38 #include "sd-readahead.h"
41 # ifdef SD_EXPORT_SYMBOLS
43 # define _sd_export_ __attribute__ ((visibility("default")))
45 /* Don't export the symbols */
46 # define _sd_export_ __attribute__ ((visibility("hidden")))
52 static int touch(const char *path) {
54 #if !defined(DISABLE_SYSTEMD) && defined(__linux__)
57 mkdir("/run/systemd", 0755);
58 mkdir("/run/systemd/readahead", 0755);
60 fd = open(path, O_WRONLY|O_CREAT|O_CLOEXEC|O_NOCTTY, 0666);
76 _sd_export_ int sd_readahead(const char *action) {
81 if (strcmp(action, "cancel") == 0)
82 return touch("/run/systemd/readahead/cancel");
83 else if (strcmp(action, "done") == 0)
84 return touch("/run/systemd/readahead/done");
85 else if (strcmp(action, "noreplay") == 0)
86 return touch("/run/systemd/readahead/noreplay");