chiark / gitweb /
hashmap: introduce hash_ops to make struct Hashmap smaller
[elogind.git] / src / readahead / readahead-collect.c
index 211ef957d98d78c903e0e226b472a8d8c2ddf211..822a803a41dde0f12fe78ce64c4f1c1718ace899 100644 (file)
@@ -52,7 +52,7 @@
 #include <sys/fanotify.h>
 #endif
 
-#include <systemd/sd-daemon.h>
+#include "systemd/sd-daemon.h"
 
 #include "missing.h"
 #include "util.h"
@@ -129,8 +129,7 @@ static int pack_file(FILE *pack, const char *fn, bool on_btrfs) {
         }
 
         pages = l / page_size();
-        vec = alloca(pages);
-        memzero(vec, pages);
+        vec = alloca0(pages);
         if (mincore(start, l, vec) < 0) {
                 log_warning("mincore(%s) failed: %m", fn);
                 r = -errno;
@@ -177,8 +176,7 @@ finish:
         if (start != MAP_FAILED)
                 munmap(start, l);
 
-        if (fd >= 0)
-                close_nointr_nofail(fd);
+        safe_close(fd);
 
         return r;
 }
@@ -284,7 +282,7 @@ static int collect(const char *root) {
                 goto finish;
         }
 
-        files = hashmap_new(string_hash_func, string_compare_func);
+        files = hashmap_new(&string_hash_ops);
         if (!files) {
                 log_error("Failed to allocate set.");
                 r = -ENOMEM;
@@ -494,16 +492,12 @@ static int collect(const char *root) {
                                 log_warning("readlink(%s) failed: %s", fn, strerror(-k));
 
                 next_iteration:
-                        if (m->fd >= 0)
-                                close_nointr_nofail(m->fd);
+                        safe_close(m->fd);
                 }
         }
 
 done:
-        if (fanotify_fd >= 0) {
-                close_nointr_nofail(fanotify_fd);
-                fanotify_fd = -1;
-        }
+        fanotify_fd = safe_close(fanotify_fd);
 
         log_debug("Writing Pack File...");
 
@@ -593,14 +587,9 @@ done:
         log_debug("Done.");
 
 finish:
-        if (fanotify_fd >= 0)
-                close_nointr_nofail(fanotify_fd);
-
-        if (signal_fd >= 0)
-                close_nointr_nofail(signal_fd);
-
-        if (inotify_fd >= 0)
-                close_nointr_nofail(inotify_fd);
+        safe_close(fanotify_fd);
+        safe_close(signal_fd);
+        safe_close(inotify_fd);
 
         if (pack) {
                 fclose(pack);