Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ using ReadyCondition = std::variant<ProcessState, FileState>;
struct ComponentProperties
{
std::string binary_name;
ApplicationProfile application_profile;
ApplicationProfile application_profile{};
std::vector<std::string> depends_on;
std::vector<std::string> process_arguments;

Expand Down Expand Up @@ -104,15 +104,15 @@ struct DeploymentConfig
std::optional<RestartAction> ready_recovery_action;
// Currently only SwitchRunTargetAction is supported here, RestartAction to be added in the future
std::optional<SwitchRunTargetAction> recovery_action;
Sandbox sandbox;
Sandbox sandbox{};
};

struct ComponentConfig
{
std::string name;
std::string description;
ComponentProperties component_properties;
DeploymentConfig deployment_config;
ComponentProperties component_properties{};
DeploymentConfig deployment_config{};
};

} // namespace score::mw::lifecycle::internal::configuration
Expand Down
5 changes: 0 additions & 5 deletions score/launch_manager/src/daemon/src/osal/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ cc_library(
name = "semaphore",
srcs = ["details/posix/semaphore.cpp"],
hdrs = [
"return_types.hpp",
"semaphore.hpp",
],
include_prefix = "score/mw/launch_manager/osal",
Expand All @@ -38,7 +37,6 @@ cc_library(
name = "wait_for_file",
srcs = ["details/posix/wait_for_file.cpp"],
hdrs = [
"return_types.hpp",
"wait_for_file.hpp",
],
include_prefix = "score/mw/launch_manager/osal",
Expand Down Expand Up @@ -73,7 +71,6 @@ cc_library(
name = "ifile_waiter",
hdrs = [
"ifile_waiter.hpp",
"return_types.hpp",
],
include_prefix = "score/mw/launch_manager/osal",
strip_include_prefix = "/score/launch_manager/src/daemon/src/osal",
Expand Down Expand Up @@ -165,8 +162,6 @@ cc_library(
name = "ipc_comms",
hdrs = [
"ipc_comms.hpp",
"return_types.hpp",
"semaphore.hpp",
],
include_prefix = "score/mw/launch_manager/osal",
strip_include_prefix = "/score/launch_manager/src/daemon/src/osal",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include "score/mw/launch_manager/configuration/component_config.hpp"
#include <chrono>

#include "return_types.hpp"
#include "score/mw/launch_manager/osal/return_types.hpp"

namespace score::mw::lifecycle::internal::osal
{
Expand Down
49 changes: 48 additions & 1 deletion score/launch_manager/src/daemon/src/osal/ipc_comms.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include <memory>

#include "score/mw/launch_manager/common/log.hpp"
#include "semaphore.hpp"
#include "score/mw/launch_manager/osal/semaphore.hpp"

namespace score::mw::lifecycle::internal::osal
{
Expand Down Expand Up @@ -99,6 +99,53 @@ struct IpcCommsSync final
return ret;
}

/// @brief Initializes semaphores within a given shared memory block.
/// @param[in] block Pointer to the shared memory block where semaphores will be initialized.
/// @return True if semaphore initialization is successful, false otherwise.
/// @details This is static instead of a member function because, even though not needed currently, any vtable
/// lookups would be UB.
static bool initializeSemaphores(IpcCommsP shared_block)
{
bool result = true;

if (osal::OsalReturnType::kFail == shared_block->send_sync_.init(0U, true) ||
osal::OsalReturnType::kFail == shared_block->reply_sync_.init(0U, true))
{
result = false;
LM_LOG_ERROR() << "Semaphore init failed: Unable to initialize send_sync or reply_sync semaphore.";
}

return result;
}

/// @brief Deinitializes semaphores within a given shared memory block.
/// @param[in] block Pointer to the shared memory block.
/// @details This is static instead of a member function because, even though not needed currently, any vtable
/// lookups would be UB.
static void deinit(IpcCommsP shared_block)
{
// We are not interested in the result of msync, just whether it worked or not.
// If it did not work, the child process has probably crashed and corrupted the shared memory
// so we should not try to deinitialize the semaphores.
// mincore would be more appropriate here, but is not available on QNX
if (msync(shared_block.get(), sizeof(IpcCommsSync), MS_ASYNC) == 0)
{
if (shared_block->send_sync_.deinit() != OsalReturnType::kSuccess)
{
LM_LOG_WARN() << "Failed to deinitialize send_sync semaphore.";
}
if (shared_block->reply_sync_.deinit() != OsalReturnType::kSuccess)
{
LM_LOG_WARN() << "Failed to deinitialize reply_sync semaphore.";
}
}
else
{
LM_LOG_WARN() << "Skipping semaphore deinitialization - shared memory region appears invalid:"
<< errno_message(errno);
}
}

private:
/// @brief Deleter to release IpcCommsSync object
/// This is passed to the constructor of a shared pointer
Expand Down
2 changes: 1 addition & 1 deletion score/launch_manager/src/daemon/src/osal/semaphore.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include <semaphore.h>
#include <chrono>

#include "return_types.hpp"
#include "score/mw/launch_manager/osal/return_types.hpp"

namespace score::mw::lifecycle::internal::osal
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include <chrono>
#include <cstdint>

#include "return_types.hpp"
#include "score/mw/launch_manager/osal/return_types.hpp"

namespace score::mw::lifecycle::internal::osal
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,54 @@ cc_library(
],
)

cc_library(
name = "mock_proc_launch_syscalls",
testonly = True,
hdrs = ["mock_proc_launch_syscalls.hpp"],
include_prefix = "score/mw/launch_manager/process_group_manager/details",
strip_include_prefix = "/score/launch_manager/src/daemon/src/process_group_manager/details",
visibility = ["//score/launch_manager/src/daemon/src/process_group_manager:__pkg__"],
deps = [
"@googletest//:gtest_main",
],
)

lm_cc_test(
name = "process_launcher_UT",
srcs = ["process_launcher_UT.cpp"],
linkopts = [
"-Wl,--wrap=fork",
"-Wl,--wrap=execve",
"-Wl,--wrap=kill",
"-Wl,--wrap=wait",
"-Wl,--wrap=access",
"-Wl,--wrap=shm_open",
"-Wl,--wrap=ftruncate",
"-Wl,--wrap=shm_unlink",
"-Wl,--wrap=mmap",
"-Wl,--wrap=munmap",
"-Wl,--wrap=setpgid",
"-Wl,--wrap=setgid",
"-Wl,--wrap=setuid",
"-Wl,--wrap=sched_setscheduler",
"-Wl,--wrap=chdir",
"-Wl,--wrap=setrlimit",
"-Wl,--wrap=getpid",
"-Wl,--wrap=fcntl",
"-Wl,--wrap=sem_init",
"-Wl,--wrap=sem_destroy",
"-Wl,--wrap=sem_trywait",
"-Wl,--wrap=sem_post",
"-Wl,--wrap=msync",
],
linkstatic = True,
deps = [
":mock_proc_launch_syscalls",
":process_launcher",
"@googletest//:gtest_main",
],
)

cc_library(
name = "dependency_graph",
hdrs = [
Expand Down
Loading
Loading