chiark / gitweb /
readahead: fix fd validity check
[elogind.git] / src / readahead / readahead-collect.c
index 45d489a60ef95805f154972defcd8377f8db0efd..5d07f4704af0837a588d0cc1c5293e4ac72b4e3f 100644 (file)
 #include <getopt.h>
 #include <sys/inotify.h>
 
+#ifdef HAVE_FANOTIFY_INIT
+#include <sys/fanotify.h>
+#endif
+
 #include <systemd/sd-daemon.h>
 
 #include "missing.h"
@@ -242,8 +246,7 @@ static int collect(const char *root) {
         assert(root);
 
         if (asprintf(&pack_fn, "%s/.readahead", root) < 0) {
-                log_error("Out of memory.");
-                r = -ENOMEM;
+                r = log_oom();
                 goto finish;
         }
 
@@ -457,7 +460,7 @@ static int collect(const char *root) {
                                 log_warning("readlink(%s) failed: %s", fn, strerror(-k));
 
                 next_iteration:
-                        if (m->fd)
+                        if (m->fd >= 0)
                                 close_nointr_nofail(m->fd);
                 }
         }
@@ -477,8 +480,7 @@ done:
         log_debug("On btrfs: %s", yes_no(on_btrfs));
 
         if (asprintf(&pack_fn_new, "%s/.readahead.new", root) < 0) {
-                log_error("Out of memory.");
-                r = -ENOMEM;
+                r = log_oom();
                 goto finish;
         }
 
@@ -510,8 +512,7 @@ done:
 
                 n = hashmap_size(files);
                 if (!(ordered = new(struct item, n))) {
-                        log_error("Out of memory.");
-                        r = -ENOMEM;
+                        r = log_oom();
                         goto finish;
                 }