Skip to content

Commit

Permalink
iox-eclipse-iceoryx#404 PoshRuntime sends TERMINATION info to RouDi o…
Browse files Browse the repository at this point in the history
…n destruction

Signed-off-by: Simon Hoinkis <simon.hoinkis@apex.ai>
  • Loading branch information
mossmaurice authored and marthtz committed May 12, 2021
1 parent 40ee566 commit 86fd68a
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ class ProcessManager : public ProcessManagerInterface
const uint64_t sessionId,
const version::VersionInfo& versionInfo) noexcept;

/// @brief Unregisters a process at the ProcessManager
/// @param [in] name of the process which wants to unregister
/// @return true if known process was unregistered, false if process is unknown
bool unregisterProcess(const ProcessName_t& name) noexcept;

/// @brief Kills all registered processes. First try with a SIGTERM and if they have not terminated after
/// processKillDelay they are killed with SIGKILL. If RouDi doesn't have sufficient rights to kill the process, the
/// process is considered killed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ enum class IpcMessageType : int32_t
CREATE_NODE_ACK,
FIND_SERVICE,
KEEPALIVE,
TERMINATION,
ERROR,
APP_WAIT,
WAKEUP_TRIGGER,
Expand Down
39 changes: 26 additions & 13 deletions iceoryx_posh/source/roudi/process_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,19 +279,21 @@ bool ProcessManager::registerProcess(const ProcessName_t& name,
LogWarn()
<< "Received REG from " << name
<< ", but another application with this name is already registered and could not be removed";
return;
}
else
{
LogDebug() << "Removed existing application " << name;
// try registration again, should succeed since removal was successful
addProcess(name,
pid,
segmentInfo.m_memoryManager,
isMonitored,
transmissionTimestamp,
segmentInfo.m_segmentID,
sessionId,
versionInfo);
}

LogDebug() << "Registering already existing application " << name << " - removed existing application";

// try registration again, should succeed since removal was successful
addProcess(name,
pid,
segmentInfo.m_memoryManager,
isMonitored,
transmissionTimestamp,
segmentInfo.m_segmentID,
sessionId,
versionInfo);
}
},
[&]() {
Expand Down Expand Up @@ -353,6 +355,17 @@ bool ProcessManager::addProcess(const ProcessName_t& name,
return true;
}

bool ProcessManager::unregisterProcess(const ProcessName_t& name) noexcept
{
std::lock_guard<std::mutex> g(m_mutex);
if (!removeProcess(name))
{
LogError() << "Application " << name << " could not be unregistered!";
return false;
}
return true;
}

bool ProcessManager::removeProcess(const ProcessName_t& name) noexcept
{
// we need to search for the process (currently linear search)
Expand All @@ -364,7 +377,7 @@ bool ProcessManager::removeProcess(const ProcessName_t& name) noexcept
{
if (removeProcess(it))
{
LogDebug() << "New Registration - removed existing application " << name;
LogDebug() << "Removed existing application " << name;
}
return true; // we can assume there are no other processes with this name
}
Expand Down
13 changes: 13 additions & 0 deletions iceoryx_posh/source/roudi/roudi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,19 @@ void RouDi::processMessage(const runtime::IpcMessage& message,
m_prcMgr.updateLivelinessOfProcess(processName);
break;
}
case runtime::IpcMessageType::TERMINATION:
{
if (message.getNumberOfElements() != 2)
{
LogError() << "Wrong number of parameters for \"IpcMessageType::TERMINATION\" from \"" << processName
<< "\"received!";
}
else
{
DISCARD_RESULT(m_prcMgr.unregisterProcess(processName));
}
break;
}
default:
{
LogError() << "Unknown IPC message command [" << runtime::IpcMessageTypeToString(cmd) << "]";
Expand Down
5 changes: 5 additions & 0 deletions iceoryx_posh/source/runtime/posh_runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ PoshRuntime::PoshRuntime(cxx::optional<const ProcessName_t*> name, const bool do

PoshRuntime::~PoshRuntime() noexcept
{
// Inform RouDi that we're shuting down
IpcMessage shutdown;
shutdown << IpcMessageTypeToString(IpcMessageType::TERMINATION) << m_appName;
m_ipcChannelInterface.sendMessageToRouDi(shutdown);

if (m_applicationPort)
{
m_applicationPort.destroy();
Expand Down
16 changes: 16 additions & 0 deletions iceoryx_posh/test/moduletests/test_roudi_process_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,19 @@ TEST_F(ProcessManager_test, RegisterSameProcessTwiceWithoutMonitoringLeadsToErro
EXPECT_TRUE(result1);
EXPECT_FALSE(result2);
}

TEST_F(ProcessManager_test, UnregisterNonExistentProcessLeadsToError)
{
auto unregisterResult = m_sut->unregisterProcess(m_processname);

EXPECT_FALSE(unregisterResult);
}

TEST_F(ProcessManager_test, RegisterAndUnregisterWorks)
{
auto registerResult = m_sut->registerProcess(m_processname, m_pid, m_user, m_isMonitored, 1U, 1U, m_versionInfo);
auto unregisterResult = m_sut->unregisterProcess(m_processname);

EXPECT_TRUE(registerResult);
EXPECT_TRUE(unregisterResult);
}

0 comments on commit 86fd68a

Please sign in to comment.