%license LICENSE.MIT
%{_bindir}/test_*
%{_bindir}/sessiond-integration-tests.sh
+%{_bindir}/sessiond-integration-test-regenerate-skel.sh
%files -n subsession-client-example
%manifest sessiond.manifest
sessiond_SRCS
src/main.cpp
src/main_restore.cpp
+ src/main_skel.cpp
src/fs_helpers.cpp
src/os_ops.cpp
src/plugin.cpp
}
// Create `$HOME/subsession` directory if it doesn't exist
-static void create_main_subdirectory(const int session_uid, const fs::path& main_dir)
+void create_main_subdirectory(const int session_uid, const fs::path& main_dir)
{
if (fs::exists(main_dir))
return;
std::filesystem::path get_main_dir_by_user_id(const int uid);
std::filesystem::path get_last_subsession_path_by_user_id(const int uid);
+void create_main_subdirectory(const int session_uid, const fs::path& main_dir);
bool subsession_exists(const int session_uid, const std::string_view subsession_id);
void add_user_subsession(const int session_uid, const std::string_view subsession_id, const DirBackendAdd& backend);
void add_user_subsession_inner(const std::filesystem::path &main_path, const int session_uid, const std::string_view subsession_id, const DirBackendAdd& backend, bool force);
#include "main_context.hpp"
#include "main_restore.hpp"
+#include "main_skel.hpp"
#include <stdexcept>
std::unique_ptr <sessiond_context> g_sessiond_context;
return std::string_view(argv[1]) == "--restore-only";
}
+
+bool isGenSkel(int argc, char **argv)
+{
+ if (argc < 2)
+ return false;
+
+ return std::string_view(argv[1]) == "--regenerate-skel";
+}
+
+
int main(int argc, char **argv) try {
if (isRestoreOnly(argc, argv)) {
restore_all_user_sessions();
+ } else if (isGenSkel(argc, argv)) {
+ regenerate_skel();
} else {
g_sessiond_context = std::make_unique <sessiond_context> ();
restore_all_user_sessions();
--- /dev/null
+/* MIT License
+ *
+ * Copyright (c) 2025 Samsung Electronics Co., Ltd.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is furnished
+ * to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE. */
+
+#include <filesystem>
+#include <iostream>
+
+#undef LOG_TAG
+#define LOG_TAG "SESSIOND_REGENERATE_SKEL"
+#include <dlog.h>
+
+#include "fs_helpers.hpp"
+#include "os_ops.hpp"
+#include "dir_backend_fixed_size.hpp"
+
+namespace fs = std::filesystem;
+
+constexpr auto TEMPLATE_IMAGE_SIZE_KB = 10240;
+
+int regenerate_skel()
+{
+ try {
+ fs::current_path("/opt/usr/home");
+ } catch (const std::exception& ex) {
+ std::cerr << "Can not regenerate skel template, unable to chdir to HOME:" << ex.what() << std::endl;
+ throw;
+ }
+
+ for (auto const& entry : fs::directory_iterator(".")) {
+ if (!fs::is_directory(entry.status()))
+ continue;
+
+ const auto &username = entry.path().filename();
+ int username_uid = -1;
+ try {
+ username_uid = OS::get_uid_from_name(username.string());
+ const auto main_path = get_main_dir_by_user_id(username_uid);
+ create_main_subdirectory(username_uid, main_path);
+ add_user_subsession_inner(main_path, username_uid, ".template", DirBackendAddFixedSize {TEMPLATE_IMAGE_SIZE_KB}, true);
+ } catch (const std::exception& ex) {
+ LOGW("Unable to generate skel template for username %s (uid %d): %s", username.c_str(), username_uid, ex.what());
+ continue;
+ }
+ }
+
+ return 0;
+}
--- /dev/null
+#pragma once
+
+void regenerate_skel();
-install(FILES sessiond-integration-tests.sh
+install(FILES sessiond-integration-tests.sh sessiond-integration-test-regenerate-skel.sh
DESTINATION bin
PERMISSIONS OWNER_READ OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
--- /dev/null
+#!/bin/bash
+
+
+echo "Testing \`sessiond --regenerate-skel\` for non-existent user..."
+rm -r /opt/usr/home/emmanuel_goldstein
+mkdir /opt/usr/home/emmanuel_goldstein
+sessiond --regenerate-skel &> /dev/null
+if [ "$?" -ne 0 ]; then
+ echo "Execution failed, bailing out"
+ exit 1
+fi
+# Won't actually create anything inside since it's not a real user, so nothing more to check
+rm -r /opt/usr/home/emmanuel_goldstein
+
+
+echo "Testing \`sessiond --regenerate-skel\` for missing subsessions dir..."
+rm -r /opt/usr/home/owner/subsession
+sessiond --regenerate-skel &> /dev/null
+if [ "$?" -ne 0 ]; then
+ echo "Execution failed, bailing out"
+ exit 1
+fi
+if [ ! -d "/opt/usr/home/owner/subsession" ]; then
+ echo "Failed to create subsession dir (/opt/usr/home/owner/subsession), bailing out"
+ exit 1
+fi
+
+
+exit 0
#!/bin/bash
+sessiond-integration-test-regenerate-skel.sh \
+ && echo "[OK] Skel template regeneration tests passed" \
+ || echo "[FAIL] Skel template regeneration tests failed"
+
readonly TESTUSER=owner
readonly TEST_SUBSESSIONS=("TestSuite_sub1" "TestSuite_sub2" "TestSuite_sub3")
readonly TEST_SUBSESSIONS_FIXED=("TestSuite_sub4" "TestSuite_sub5" "TestSuite_sub6")