Handle fsck.ext4 returning successfull, but nonzero error code 83/325483/2
authorKarol Lewandowski <k.lewandowsk@samsung.com>
Tue, 10 Jun 2025 17:57:02 +0000 (19:57 +0200)
committerMichal Bloch <m.bloch@samsung.com>
Tue, 10 Jun 2025 19:41:33 +0000 (21:41 +0200)
Change-Id: I3b89f1ab26b7a492b7e686169ca9eb99381543d7

src/service/src/os_ops.cpp
src/service/src/os_ops.hpp

index 6e21c93f7aa69c657636767045330284cb67ecbc..f5a697f2d46ef806afa5ed50c95fbcb9b2111279 100644 (file)
@@ -206,7 +206,8 @@ void OS::do_fsck(const fs::path& fs_path)
 
                _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; } );
        }
 }
 
@@ -265,7 +266,7 @@ void OS::do_mount(const fs::path& image_path, const fs::path& mount_path)
        }
 }
 
-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);
@@ -273,7 +274,7 @@ void OS::throw_if_child_failed(int child_pid, std::string_view message_on_fail)
                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));
 }
 
index 8dc0088738e6474b709cd2e352095c500b64edb7..a0c1b2cd518a727ced2aee7bbf474e84bed424d8 100644 (file)
@@ -30,7 +30,9 @@ namespace OS {
 
        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();