add non-blocking shell cmd executor
All checks were successful
EIVE/eive-obsw/pipeline/pr-develop This commit looks good

This commit is contained in:
Robin Müller 2023-04-14 00:21:28 +02:00
parent f645b97ba3
commit e17b8d2ec4
No known key found for this signature in database
GPG Key ID: 71B58F8A3CDFA9AC
3 changed files with 14 additions and 2 deletions

View File

@ -313,7 +313,7 @@ ReturnValue_t CoreController::executeAction(ActionId_t actionId, MessageQueueId_
}
core::SystemctlCmd cmdType = static_cast<core::SystemctlCmd>(data[0]);
std::string unitName = std::string(reinterpret_cast<const char *>(data + 1), size - 1);
std::ostringstream oss("systemctl ");
std::ostringstream oss("systemctl ", std::ostringstream::ate);
switch (cmdType) {
case (core::SystemctlCmd::START): {
oss << "start ";
@ -327,6 +327,9 @@ ReturnValue_t CoreController::executeAction(ActionId_t actionId, MessageQueueId_
oss << "restart ";
break;
}
default: {
return HasActionsIF::INVALID_PARAMETERS;
}
}
oss << unitName;
int result = std::system(oss.str().c_str());
@ -366,6 +369,14 @@ ReturnValue_t CoreController::executeAction(ActionId_t actionId, MessageQueueId_
return actionReboot(data, size);
}
case (EXECUTE_SHELL_CMD_BLOCKING): {
std::string cmd = std::string(cmd, size);
int result = std::system(cmd.c_str());
if (result != 0) {
return returnvalue::FAILED;
}
return EXECUTION_FINISHED;
}
case (EXECUTE_SHELL_CMD_NON_BLOCKING): {
std::string cmd = std::string(cmd, size);
if (cmdExecutor.getCurrentState() == CommandExecutor::States::PENDING or
shellCmdIsExecuting) {

View File

@ -56,6 +56,7 @@ static constexpr ActionId_t MOUNT_OTHER_COPY = 33;
static constexpr ActionId_t REBOOT_OBC = 34;
static constexpr ActionId_t EXECUTE_SHELL_CMD_BLOCKING = 40;
static constexpr ActionId_t EXECUTE_SHELL_CMD_NON_BLOCKING = 41;
static constexpr ActionId_t SYSTEMCTL_CMD_EXECUTOR = 42;
static constexpr uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::CORE;

2
tmtc

@ -1 +1 @@
Subproject commit 8993ccdf66c54765fc2a10c26b9c340b7e6b9ffd
Subproject commit 005e15b21bdb58109b90ffbe4be9fc76e85ca38f