From: Karol Lewandowski Date: Thu, 29 May 2025 23:13:40 +0000 (+0200) Subject: service: Ensure fsck is called for templated user add (image) X-Git-Tag: accepted/tizen/unified/20250603.182350~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7822035dd848d1f49c5584b677b4640cb07f4509;p=platform%2Fcore%2Fsystem%2Fsessiond.git service: Ensure fsck is called for templated user add (image) Change-Id: I238fd4925f842519e29b5c49304f885df6ff0abe --- diff --git a/packaging/sessiond.spec b/packaging/sessiond.spec index 6bceb37..efd367f 100644 --- a/packaging/sessiond.spec +++ b/packaging/sessiond.spec @@ -21,6 +21,7 @@ BuildRequires: pkgconfig(dlog) BuildRequires: pkgconfig(libsyscommon-plugin-api-sessiond) Requires: /usr/sbin/mkfs.ext4 +Requires: /usr/sbin/fsck.ext4 %if %{with resize2fs} Requires: /usr/sbin/resize2fs %endif diff --git a/src/service/src/dir_backend_fixed_size.cpp b/src/service/src/dir_backend_fixed_size.cpp index 7399a33..5d64e2c 100644 --- a/src/service/src/dir_backend_fixed_size.cpp +++ b/src/service/src/dir_backend_fixed_size.cpp @@ -130,6 +130,7 @@ bool DirBackendAddFixedSize::AddSubsessionPrepareFromTemplate (const std::string OS::do_mount(template_img, template_dir); try { + OS::do_fsck(subsession_img); OS::do_resize2fs(subsession_img, size_kB); OS::change_owner_and_group(subsession_img, uid, gid); fs::create_directory(subsession_dir); diff --git a/src/service/src/os_ops.cpp b/src/service/src/os_ops.cpp index f6a0b65..5f0f6ae 100644 --- a/src/service/src/os_ops.cpp +++ b/src/service/src/os_ops.cpp @@ -192,6 +192,31 @@ void OS::do_resize2fs(const fs::path& fs_path, uint64_t size_kB) } } +void OS::do_fsck(const fs::path& fs_path) +{ + const auto child_pid = OS::throwing_fork(); + if (child_pid == 0) { + const auto cmd = "/usr/sbin/fsck.ext4"sv; + + const auto r = execl + ( cmd.data(), cmd.data() /* argv[0] convention */ + , fs_path.c_str() + , "-fp" + , (char *) NULL + ); + + LOGE("Failed to execute `%s -fp %s`: %m" + , cmd.data() + , fs_path.c_str() + ); + assert(r == -1); + + _exit(1); + } else { + OS::throw_if_child_failed(child_pid, "fsck.ext4 failed!"); + } +} + void OS::do_umount(const fs::path& path) { const auto child_pid = OS::throwing_fork(); diff --git a/src/service/src/os_ops.hpp b/src/service/src/os_ops.hpp index 30a1e83..e40f547 100644 --- a/src/service/src/os_ops.hpp +++ b/src/service/src/os_ops.hpp @@ -22,6 +22,8 @@ namespace OS { void do_resize2fs(const fs::path& fs_path, uint64_t size_kB); + void do_fsck(const fs::path& fs_path); + void do_mount(const fs::path& image_path, const fs::path& mount_path); void do_umount(const fs::path& path);