systemctl helper
This commit is contained in:
@ -9,7 +9,6 @@
|
||||
#include "fsfw/serviceinterface/ServiceInterface.h"
|
||||
#include "fsfw/timemanager/Stopwatch.h"
|
||||
#include "fsfw/version.h"
|
||||
#include "mission/sysDefs.h"
|
||||
#include "watchdog/definitions.h"
|
||||
#if OBSW_ADD_TMTC_UDP_SERVER == 1
|
||||
#include "fsfw/osal/common/UdpTmTcBridge.h"
|
||||
@ -118,7 +117,7 @@ void CoreController::performControlOperation() {
|
||||
bool replyReceived = false;
|
||||
// TODO: We could read the data in the ring buffer and send it as an action data reply.
|
||||
if (cmdExecutor.check(replyReceived) == CommandExecutor::EXECUTION_FINISHED) {
|
||||
actionHelper.finish(true, successRecipient, core::EXECUTE_SHELL_CMD);
|
||||
actionHelper.finish(true, successRecipient, core::EXECUTE_SHELL_CMD_BLOCKING);
|
||||
shellCmdIsExecuting = false;
|
||||
cmdReplyBuf.clear();
|
||||
while (not cmdRepliesSizes.empty()) {
|
||||
@ -304,6 +303,38 @@ ReturnValue_t CoreController::executeAction(ActionId_t actionId, MessageQueueId_
|
||||
// Completion will be reported by SD card state machine
|
||||
return returnvalue::OK;
|
||||
}
|
||||
case (SYSTEMCTL_CMD_EXECUTOR): {
|
||||
// Expect one byte systemctl command type and a unit name with at least one byte as minimum.
|
||||
if (size < 2) {
|
||||
return HasActionsIF::INVALID_PARAMETERS;
|
||||
}
|
||||
if (data[0] >= core::SystemctlCmd::NUM_CMDS) {
|
||||
return HasActionsIF::INVALID_PARAMETERS;
|
||||
}
|
||||
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 ");
|
||||
switch (cmdType) {
|
||||
case (core::SystemctlCmd::START): {
|
||||
oss << "start ";
|
||||
break;
|
||||
}
|
||||
case (core::SystemctlCmd::STOP): {
|
||||
oss << "stop ";
|
||||
break;
|
||||
}
|
||||
case (core::SystemctlCmd::RESTART): {
|
||||
oss << "restart ";
|
||||
break;
|
||||
}
|
||||
}
|
||||
oss << unitName;
|
||||
int result = std::system(oss.str().c_str());
|
||||
if (result != 0) {
|
||||
return returnvalue::FAILED;
|
||||
}
|
||||
return EXECUTION_FINISHED;
|
||||
}
|
||||
case (SWITCH_IMG_LOCK): {
|
||||
if (size != 3) {
|
||||
return HasActionsIF::INVALID_PARAMETERS;
|
||||
@ -334,7 +365,7 @@ ReturnValue_t CoreController::executeAction(ActionId_t actionId, MessageQueueId_
|
||||
// Warning: This function will never return, because it reboots the system
|
||||
return actionReboot(data, size);
|
||||
}
|
||||
case (EXECUTE_SHELL_CMD): {
|
||||
case (EXECUTE_SHELL_CMD_BLOCKING): {
|
||||
std::string cmd = std::string(cmd, size);
|
||||
if (cmdExecutor.getCurrentState() == CommandExecutor::States::PENDING or
|
||||
shellCmdIsExecuting) {
|
||||
|
Reference in New Issue
Block a user