X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Freadahead%2Freadahead-collect.c;h=822a803a41dde0f12fe78ce64c4f1c1718ace899;hb=e7eb49db071f9aab2a9bad0660962f2aa4d0c7d1;hp=58b77bdcf73065944f06c8e5b6e87c52756634b7;hpb=b47d419c25ecc735615a1088060c1ec8bef1e41f;p=elogind.git diff --git a/src/readahead/readahead-collect.c b/src/readahead/readahead-collect.c index 58b77bdcf..822a803a4 100644 --- a/src/readahead/readahead-collect.c +++ b/src/readahead/readahead-collect.c @@ -52,7 +52,7 @@ #include #endif -#include +#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); - memset(vec, 0, 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);