diff --git a/.github/workflows/build_test.yaml b/.github/workflows/build_test.yaml index 1e6f40bf..78452033 100644 --- a/.github/workflows/build_test.yaml +++ b/.github/workflows/build_test.yaml @@ -5,6 +5,7 @@ on: branches: - main - develop + - feature* pull_request_target: types: @@ -23,7 +24,7 @@ jobs: runs-on: ubuntu-22.04 permissions: read-all container: - image: ghcr.io/aosedge/aos-core-build-base:latest + image: ghcr.io/aosedge/aos-core-build:latest options: "--entrypoint /usr/bin/bash" credentials: username: ${{ github.actor }} @@ -33,10 +34,6 @@ jobs: BUILD_WRAPPER_OUT_DIR: build_wrapper_output_directory steps: - # Apply solution to "HOME is overridden for containers" problem: https://github.com/actions/runner/issues/863 - - name: Preserve $HOME set in the container - run: echo HOME=/root >> "$GITHUB_ENV" - - name: Checkout uses: actions/checkout@v4 with: diff --git a/external/aos_core_common_cpp b/external/aos_core_common_cpp index edeb8c0b..c72bcca6 160000 --- a/external/aos_core_common_cpp +++ b/external/aos_core_common_cpp @@ -1 +1 @@ -Subproject commit edeb8c0bbc278ca8c27ba6a36bd4e7c343a29f41 +Subproject commit c72bcca606e8c4352cbd150600c07ecca62bad79 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3a84c9be..6a326289 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -10,6 +10,8 @@ set(TARGET aos_servicemanager) # Defines # ###################################################################################################################### +add_definitions(-include config.hpp) + # ###################################################################################################################### # Includes # ###################################################################################################################### diff --git a/src/app/aoscore.cpp b/src/app/aoscore.cpp index 640b56b8..98d22bb3 100644 --- a/src/app/aoscore.cpp +++ b/src/app/aoscore.cpp @@ -144,7 +144,7 @@ void AosCore::Init(const std::string& configFile) err = mLauncher.Init(mConfig.mLauncherConfig, mIAMClientPublic, mServiceManager, mLayerManager, mResourceManager, mNetworkManager, mIAMClientPermissions, mRunner, mRuntime, mResourceMonitor, mOCISpec, mSMClient, mSMClient, - mDatabase); + mDatabase, mCryptoProvider); AOS_ERROR_CHECK_AND_THROW(err, "can't initialize launcher"); // Initialize SM client diff --git a/src/config.hpp b/src/config.hpp new file mode 100644 index 00000000..54729a51 --- /dev/null +++ b/src/config.hpp @@ -0,0 +1,15 @@ +/* + * Copyright (C) 2026 EPAM Systems, Inc. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef AOS_CORE_SM_CONFIG_HPP_ +#define AOS_CORE_SM_CONFIG_HPP_ + +/** + * Host device name len. + */ +#define AOS_CONFIG_TYPES_DEVICE_NAME_LEN 128 + +#endif diff --git a/src/launcher/runtime.cpp b/src/launcher/runtime.cpp index a7f3a56f..45045beb 100644 --- a/src/launcher/runtime.cpp +++ b/src/launcher/runtime.cpp @@ -157,7 +157,12 @@ oci::LinuxDevice DeviceFromPath(const fs::path& path) auto devPath = path; if (fs::is_symlink(path)) { - devPath = fs::read_symlink(path); + auto target = fs::read_symlink(path); + if (target.is_relative()) { + devPath = (path.parent_path() / target).lexically_normal(); + } else { + devPath = target; + } } struct stat sb; @@ -185,7 +190,7 @@ oci::LinuxDevice DeviceFromPath(const fs::path& path) } return oci::LinuxDevice { - devPath.c_str(), type, major(sb.st_rdev), minor(sb.st_rdev), sb.st_mode & ~S_IFMT, sb.st_uid, sb.st_gid}; + path.c_str(), type, major(sb.st_rdev), minor(sb.st_rdev), sb.st_mode & ~S_IFMT, sb.st_uid, sb.st_gid}; } } // namespace diff --git a/src/resourcemanager/resourcemanager.cpp b/src/resourcemanager/resourcemanager.cpp index 98146da2..f6f1c56b 100644 --- a/src/resourcemanager/resourcemanager.cpp +++ b/src/resourcemanager/resourcemanager.cpp @@ -41,9 +41,21 @@ Error HostDeviceManager::Init() Error HostDeviceManager::CheckDevice(const String& device) const { - auto it = mDevices.find(device.CStr()); + StaticArray, 2> devices; - return it != mDevices.end() ? ErrorEnum::eNone : ErrorEnum::eNotFound; + if (auto err = device.Split(devices, ':'); !err.IsNone()) { + return AOS_ERROR_WRAP(err); + } + + if (devices.IsEmpty()) { + return AOS_ERROR_WRAP(ErrorEnum::eFailed); + } + + if (mDevices.find(devices[0].CStr()) == mDevices.end()) { + return AOS_ERROR_WRAP(ErrorEnum::eNotFound); + } + + return ErrorEnum::eNone; } Error HostDeviceManager::CheckGroup(const String& group) const diff --git a/tests/launcher/CMakeLists.txt b/tests/launcher/CMakeLists.txt index cacc8563..2bfb1b3a 100644 --- a/tests/launcher/CMakeLists.txt +++ b/tests/launcher/CMakeLists.txt @@ -24,4 +24,4 @@ gtest_discover_tests(${TARGET}) # Libraries # ###################################################################################################################### -target_link_libraries(${TARGET} launcher GTest::gmock_main) +target_link_libraries(${TARGET} launcher aostestutils GTest::gmock_main) diff --git a/tests/launcher/runtime_test.cpp b/tests/launcher/runtime_test.cpp index 08fc2647..18523835 100644 --- a/tests/launcher/runtime_test.cpp +++ b/tests/launcher/runtime_test.cpp @@ -9,6 +9,7 @@ #include #include +#include #include "launcher/runtime.hpp" @@ -78,4 +79,56 @@ TEST_F(LauncherTest, CreateHostFSWhiteouts) } } +TEST_F(LauncherTest, PopulateHostDevices) +{ + const auto cRootDevicePath = fs::path(cTestDirRoot) / "dev"; + const auto cTestDeviceFullPath = cRootDevicePath / "device1"; + + if (!fs::exists(cRootDevicePath)) { + fs::create_directories(cRootDevicePath); + } + + if (auto res = mknod(cTestDeviceFullPath.c_str(), S_IFCHR, 0); res != 0) { + FAIL() << "Can't create test device node: " << strerror(errno); + } + + StaticArray devices; + + auto err = mRuntime.PopulateHostDevices(cTestDeviceFullPath.c_str(), devices); + EXPECT_TRUE(err.IsNone()) << "failed: " << test::ErrorToStr(err); + + EXPECT_EQ(devices.Size(), 1); + EXPECT_STREQ(devices.Front().mPath.CStr(), cTestDeviceFullPath.c_str()); +} + +TEST_F(LauncherTest, PopulateHostDevicesSymlink) +{ + const auto cRootDevicePath = fs::path(cTestDirRoot) / "dev"; + const auto cTestDeviceFullPath = cRootDevicePath / "device1"; + + if (!fs::exists(cRootDevicePath)) { + fs::create_directories(cRootDevicePath); + } + + if (auto res = mknod(cTestDeviceFullPath.c_str(), S_IFCHR, 0); res != 0) { + FAIL() << "Can't create test device node: " << strerror(errno); + } + + const auto currentPath = fs::current_path(); + + fs::current_path(cRootDevicePath); + + fs::create_symlink("device1", "link"); + + fs::current_path(currentPath); + + StaticArray devices; + + auto err = mRuntime.PopulateHostDevices((cRootDevicePath / "link").c_str(), devices); + EXPECT_TRUE(err.IsNone()) << "failed: " << test::ErrorToStr(err); + + EXPECT_EQ(devices.Size(), 1); + EXPECT_STREQ(devices.Front().mPath.CStr(), (cRootDevicePath / "link").c_str()); +} + } // namespace aos::sm::launcher diff --git a/tests/resourcemanager/CMakeLists.txt b/tests/resourcemanager/CMakeLists.txt index 0c74f0dc..bd30fd85 100644 --- a/tests/resourcemanager/CMakeLists.txt +++ b/tests/resourcemanager/CMakeLists.txt @@ -24,4 +24,4 @@ gtest_discover_tests(${TARGET}) # Libraries # ###################################################################################################################### -target_link_libraries(${TARGET} resourcemanager GTest::gmock_main) +target_link_libraries(${TARGET} resourcemanager aostestutils GTest::gmock_main) diff --git a/tests/resourcemanager/resourcemanager_test.cpp b/tests/resourcemanager/resourcemanager_test.cpp index 75bbe2df..39ef982e 100644 --- a/tests/resourcemanager/resourcemanager_test.cpp +++ b/tests/resourcemanager/resourcemanager_test.cpp @@ -7,6 +7,7 @@ #include #include +#include #include "resourcemanager/resourcemanager.hpp" @@ -29,7 +30,11 @@ TEST_F(ResourcemanagerTest, CheckDevice) { ASSERT_TRUE(mHostDeviceManager.Init().IsNone()); - EXPECT_TRUE(mHostDeviceManager.CheckDevice("/dev/null").IsNone()); + auto err = mHostDeviceManager.CheckDevice("/dev/null"); + EXPECT_TRUE(err.IsNone()) << test::ErrorToStr(err); + + err = mHostDeviceManager.CheckDevice("/dev/null:/dev/test"); + EXPECT_TRUE(err.IsNone()) << test::ErrorToStr(err); } TEST_F(ResourcemanagerTest, CheckDeviceReturnsNotFound)