X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Freadahead-collect.c;h=ca8227135e06336e8be082a2c197c6afa8b67702;hp=5c09f7a9e1df140b29f61585506476cacf7bbc19;hb=b925e72633bf98438f56a140520e07ec8c959e46;hpb=d9c7a87b35289e9a5ba94c097e861640d1357e6d diff --git a/src/readahead-collect.c b/src/readahead-collect.c index 5c09f7a9e..ca8227135 100644 --- a/src/readahead-collect.c +++ b/src/readahead-collect.c @@ -92,6 +92,13 @@ static int pack_file(FILE *pack, const char *fn, bool on_btrfs) { assert(fn); if ((fd = open(fn, O_RDONLY|O_CLOEXEC|O_NOATIME|O_NOCTTY|O_NOFOLLOW)) < 0) { + + if (errno == ENOENT) + return 0; + + if (errno == EPERM || errno == EACCES) + return 0; + log_warning("open(%s) failed: %m", fn); r = -errno; goto finish; @@ -282,13 +289,13 @@ static int collect(const char *root) { log_debug("Collecting..."); - if (access("/dev/.systemd/readahead/cancel", F_OK) >= 0) { + if (access("/dev/.run/systemd/readahead/cancel", F_OK) >= 0) { log_debug("Collection canceled"); r = -ECANCELED; goto finish; } - if (access("/dev/.systemd/readahead/done", F_OK) >= 0) { + if (access("/dev/.run/systemd/readahead/done", F_OK) >= 0) { log_debug("Got termination request"); goto done; } @@ -398,8 +405,8 @@ static int collect(const char *root) { char_array_0(fn); if ((k = readlink_malloc(fn, &p)) >= 0) { - if (startswith(p, "/tmp") || + endswith(p, " (deleted)") || hashmap_get(files, p)) /* Not interesting, or * already read */ @@ -435,7 +442,7 @@ done: on_ssd = fs_on_ssd(root) > 0; log_debug("On SSD: %s", yes_no(on_ssd)); - on_btrfs = statfs(root, &sfs) >= 0 && sfs.f_type == BTRFS_SUPER_MAGIC; + on_btrfs = statfs(root, &sfs) >= 0 && (long) sfs.f_type == (long) BTRFS_SUPER_MAGIC; log_debug("On btrfs: %s", yes_no(on_btrfs)); asprintf(&pack_fn, "%s/.readahead", root); @@ -632,6 +639,7 @@ static int parse_argv(int argc, char *argv[]) { int main(int argc, char *argv[]) { int r; + const char *root; log_set_target(LOG_TARGET_SYSLOG_OR_KMSG); log_parse_environment(); @@ -640,18 +648,30 @@ int main(int argc, char *argv[]) { if ((r = parse_argv(argc, argv)) <= 0) return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS; + root = optind < argc ? argv[optind] : "/"; + + if (fs_on_read_only(root) > 0) { + log_info("Disabling readahead collector due to read-only media."); + return 0; + } + if (!enough_ram()) { log_info("Disabling readahead collector due to low memory."); return 0; } + if (detect_virtualization(NULL) > 0) { + log_info("Disabling readahead collector due to execution in virtualized environment."); + return 0; + } + if (!(shared = shared_get())) return 1; shared->collect = getpid(); __sync_synchronize(); - if (collect(optind < argc ? argv[optind] : "/") < 0) + if (collect(root) < 0) return 1; return 0;