int main(int argc, char *argv[]) {
int ret = EXIT_FAILURE;
- FILE *f = NULL;
+ _cleanup_endmntent_ FILE *f = NULL;
struct mntent* me;
Hashmap *pids = NULL;
f = setmntent("/etc/fstab", "r");
if (!f) {
- if (errno == ENOENT) {
- ret = EXIT_SUCCESS;
- goto finish;
- }
+ if (errno == ENOENT)
+ return EXIT_SUCCESS;
- log_error("Failed to open /etc/fstab: %m");
- goto finish;
+ log_error_errno(errno, "Failed to open /etc/fstab: %m");
+ return EXIT_FAILURE;
}
- pids = hashmap_new(trivial_hash_func, trivial_compare_func);
+ pids = hashmap_new(NULL);
if (!pids) {
log_error("Failed to allocate set");
goto finish;
pid = fork();
if (pid < 0) {
- log_error("Failed to fork: %m");
+ log_error_errno(errno, "Failed to fork: %m");
ret = EXIT_FAILURE;
continue;
}
execv("/bin/mount", (char **) arguments);
- log_error("Failed to execute /bin/mount: %m");
+ log_error_errno(errno, "Failed to execute /bin/mount: %m");
_exit(EXIT_FAILURE);
}
s = strdup(me->mnt_dir);
if (!s) {
- log_error("Out of memory.");
+ log_oom();
ret = EXIT_FAILURE;
continue;
}
k = hashmap_put(pids, UINT_TO_PTR(pid), s);
if (k < 0) {
- log_error("Failed to add PID to set: %s", strerror(-k));
+ log_error_errno(k, "Failed to add PID to set: %m");
ret = EXIT_FAILURE;
continue;
}
}
while (!hashmap_isempty(pids)) {
- siginfo_t si;
+ siginfo_t si = {};
char *s;
- zero(si);
if (waitid(P_ALL, 0, &si, WEXITED) < 0) {
if (errno == EINTR)
continue;
- log_error("waitid() failed: %m");
+ log_error_errno(errno, "waitid() failed: %m");
ret = EXIT_FAILURE;
break;
}
s = hashmap_remove(pids, UINT_TO_PTR(si.si_pid));
if (s) {
- if (!is_clean_exit(si.si_code, si.si_status)) {
+ if (!is_clean_exit(si.si_code, si.si_status, NULL)) {
if (si.si_code == CLD_EXITED)
log_error("/bin/mount for %s exited with exit status %i.", s, si.si_status);
else
if (pids)
hashmap_free_free(pids);
- if (f)
- endmntent(f);
-
return ret;
}