_exit(1);
} else {
- OS::throw_if_child_failed(child_pid, "fsck.ext4 failed!");
+ // according to fsck.ext4(8) man page, error codes up to 2 are ok for us
+ OS::throw_if_child_failed(child_pid, "fsck.ext4 failed!", [](int status) -> bool { return !WIFEXITED(status) || WEXITSTATUS(status) > 2; } );
}
}
}
}
-void OS::throw_if_child_failed(int child_pid, std::string_view message_on_fail)
+void OS::throw_if_child_failed(int child_pid, std::string_view message_on_fail, OS::child_check_fn checkfn)
{
int status;
const int ret = waitpid(child_pid, &status, 0);
const auto err = errno;
throw std::system_error (err, std::generic_category (), "waitpid() failed!");
}
- if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
+ if ((checkfn && checkfn(status)) || !checkfn && (!WIFEXITED(status) || WEXITSTATUS(status) != 0))
throw std::runtime_error (std::string(message_on_fail));
}
void do_umount(const fs::path& path);
- void throw_if_child_failed(int child_pid, std::string_view message_on_fail);
+ using child_check_fn = bool (*)(int child_status);
+
+ void throw_if_child_failed(int child_pid, std::string_view message_on_fail, child_check_fn checkfn = 0);
std::vector <std::pair <int, std::string>> get_all_users();