X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Freadahead-collect.c;h=20881b3944673c4fb33b9a2ec6a34492d5e8fe43;hp=ea07b3ff4978bfddff78a4033856e95a1355a101;hb=ddd88763921a1534081ed28e36f6712a85449005;hpb=a76fad090a6a1388fbaa609e8ca37e82223d2bd7 diff --git a/src/readahead-collect.c b/src/readahead-collect.c index ea07b3ff4..20881b394 100644 --- a/src/readahead-collect.c +++ b/src/readahead-collect.c @@ -119,9 +119,10 @@ static int pack_file(FILE *pack, const char *fn, bool on_btrfs) { goto finish; } - pages = l / PAGE_SIZE; + pages = l / page_size(); vec = alloca(pages); + memset(vec, 0, pages); if (mincore(start, l, vec) < 0) { log_warning("mincore(%s) failed: %m", fn); r = -errno; @@ -289,13 +290,13 @@ static int collect(const char *root) { log_debug("Collecting..."); - if (access("/dev/.systemd/readahead/cancel", F_OK) >= 0) { + if (access("/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("/run/systemd/readahead/done", F_OK) >= 0) { log_debug("Got termination request"); goto done; } @@ -382,6 +383,16 @@ static int collect(const char *root) { if (errno == EINTR || errno == EAGAIN) continue; + /* fanotify sometimes returns EACCES on read() + * where it shouldn't. For now let's just + * ignore it here (which is safe), but + * eventually this should be + * dropped when the kernel is fixed. + * + * https://bugzilla.redhat.com/show_bug.cgi?id=707577 */ + if (errno == EACCES) + continue; + log_error("Failed to read event: %m"); r = -errno; goto finish; @@ -639,6 +650,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(); @@ -647,13 +659,20 @@ 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 (running_in_vm()) { - log_info("Disabling readahead collector due to execution in virtual machine."); + if (detect_virtualization(NULL) > 0) { + log_info("Disabling readahead collector due to execution in virtualized environment."); return 0; } @@ -663,7 +682,7 @@ int main(int argc, char *argv[]) { shared->collect = getpid(); __sync_synchronize(); - if (collect(optind < argc ? argv[optind] : "/") < 0) + if (collect(root) < 0) return 1; return 0;