mirror of
https://github.com/espressif/openthread.git
synced 2026-10-15 12:17:41 +00:00
[cli] process exit in ot-ctl (#6605)
The exit command should only exit ot-ctl itself in daemon mode. This commit adds processing exit command in the ot-ctl. This commit also moves the exit command implementation out from core as a user command on simulation and posix cli mode.
This commit is contained in:
@@ -37,6 +37,7 @@
|
|||||||
|
|
||||||
#include "openthread-system.h"
|
#include "openthread-system.h"
|
||||||
#include "cli/cli_config.h"
|
#include "cli/cli_config.h"
|
||||||
|
#include "common/code_utils.hpp"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This function initializes the CLI app.
|
* This function initializes the CLI app.
|
||||||
@@ -76,6 +77,18 @@ void otTaskletsSignalPending(otInstance *aInstance)
|
|||||||
OT_UNUSED_VARIABLE(aInstance);
|
OT_UNUSED_VARIABLE(aInstance);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if OPENTHREAD_POSIX && !defined(FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION)
|
||||||
|
static void ProcessExit(void *aContext, uint8_t aArgsLength, char *aArgs[])
|
||||||
|
{
|
||||||
|
OT_UNUSED_VARIABLE(aContext);
|
||||||
|
OT_UNUSED_VARIABLE(aArgsLength);
|
||||||
|
OT_UNUSED_VARIABLE(aArgs);
|
||||||
|
|
||||||
|
exit(EXIT_SUCCESS);
|
||||||
|
}
|
||||||
|
static const otCliCommand kCommands[] = {{"exit", ProcessExit}};
|
||||||
|
#endif
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
otInstance *instance;
|
otInstance *instance;
|
||||||
@@ -117,6 +130,10 @@ pseudo_reset:
|
|||||||
|
|
||||||
otAppCliInit(instance);
|
otAppCliInit(instance);
|
||||||
|
|
||||||
|
#if OPENTHREAD_POSIX && !defined(FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION)
|
||||||
|
otCliSetUserCommands(kCommands, OT_ARRAY_LENGTH(kCommands), instance);
|
||||||
|
#endif
|
||||||
|
|
||||||
while (!otSysPseudoResetWasRequested())
|
while (!otSysPseudoResetWasRequested())
|
||||||
{
|
{
|
||||||
otTaskletsProcess(instance);
|
otTaskletsProcess(instance);
|
||||||
|
|||||||
@@ -1761,18 +1761,6 @@ exit:
|
|||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if OPENTHREAD_POSIX && !defined(FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION)
|
|
||||||
otError Interpreter::ProcessExit(uint8_t aArgsLength, Arg aArgs[])
|
|
||||||
{
|
|
||||||
OT_UNUSED_VARIABLE(aArgsLength);
|
|
||||||
OT_UNUSED_VARIABLE(aArgs);
|
|
||||||
|
|
||||||
exit(EXIT_SUCCESS);
|
|
||||||
|
|
||||||
return OT_ERROR_NONE;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
otError Interpreter::ProcessLog(uint8_t aArgsLength, Arg aArgs[])
|
otError Interpreter::ProcessLog(uint8_t aArgsLength, Arg aArgs[])
|
||||||
{
|
{
|
||||||
otError error = OT_ERROR_NONE;
|
otError error = OT_ERROR_NONE;
|
||||||
|
|||||||
@@ -702,9 +702,6 @@ private:
|
|||||||
{"eidcache", &Interpreter::ProcessEidCache},
|
{"eidcache", &Interpreter::ProcessEidCache},
|
||||||
#endif
|
#endif
|
||||||
{"eui64", &Interpreter::ProcessEui64},
|
{"eui64", &Interpreter::ProcessEui64},
|
||||||
#if OPENTHREAD_POSIX && !defined(FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION)
|
|
||||||
{"exit", &Interpreter::ProcessExit},
|
|
||||||
#endif
|
|
||||||
{"extaddr", &Interpreter::ProcessExtAddress},
|
{"extaddr", &Interpreter::ProcessExtAddress},
|
||||||
{"extpanid", &Interpreter::ProcessExtPanId},
|
{"extpanid", &Interpreter::ProcessExtPanId},
|
||||||
{"factoryreset", &Interpreter::ProcessFactoryReset},
|
{"factoryreset", &Interpreter::ProcessFactoryReset},
|
||||||
|
|||||||
@@ -81,11 +81,45 @@ static_assert(kLineBufferSize >= sizeof("Error "), "kLineBufferSize is too small
|
|||||||
|
|
||||||
int sSessionFd = -1;
|
int sSessionFd = -1;
|
||||||
|
|
||||||
|
void QuitOnExit(const char *aBuffer)
|
||||||
|
{
|
||||||
|
constexpr char kExit[] = "exit";
|
||||||
|
|
||||||
|
while (*aBuffer == ' ' || *aBuffer == '\t')
|
||||||
|
{
|
||||||
|
++aBuffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
VerifyOrExit(strstr(aBuffer, kExit) == aBuffer);
|
||||||
|
|
||||||
|
aBuffer += sizeof(kExit) - 1;
|
||||||
|
|
||||||
|
while (*aBuffer == ' ' || *aBuffer == '\t')
|
||||||
|
{
|
||||||
|
++aBuffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (*aBuffer)
|
||||||
|
{
|
||||||
|
case '\0':
|
||||||
|
case '\r':
|
||||||
|
case '\n':
|
||||||
|
exit(OT_EXIT_SUCCESS);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
exit:
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
#if OPENTHREAD_USE_READLINE
|
#if OPENTHREAD_USE_READLINE
|
||||||
void InputCallback(char *aLine)
|
void InputCallback(char *aLine)
|
||||||
{
|
{
|
||||||
if (aLine != nullptr)
|
if (aLine != nullptr)
|
||||||
{
|
{
|
||||||
|
QuitOnExit(aLine);
|
||||||
add_history(aLine);
|
add_history(aLine);
|
||||||
dprintf(sSessionFd, "%s\n", aLine);
|
dprintf(sSessionFd, "%s\n", aLine);
|
||||||
free(aLine);
|
free(aLine);
|
||||||
@@ -323,6 +357,7 @@ int main(int argc, char *argv[])
|
|||||||
#else
|
#else
|
||||||
VerifyOrExit(fgets(buffer, sizeof(buffer), stdin) != nullptr, ret = OT_EXIT_FAILURE);
|
VerifyOrExit(fgets(buffer, sizeof(buffer), stdin) != nullptr, ret = OT_EXIT_FAILURE);
|
||||||
|
|
||||||
|
QuitOnExit(buffer);
|
||||||
VerifyOrExit(DoWrite(sSessionFd, buffer, strlen(buffer)), ret = OT_EXIT_FAILURE);
|
VerifyOrExit(DoWrite(sSessionFd, buffer, strlen(buffer)), ret = OT_EXIT_FAILURE);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|||||||
+17
-1
@@ -342,7 +342,23 @@ static void ProcessNetif(void *aContext, uint8_t aArgsLength, char *aArgs[])
|
|||||||
otCliOutputFormat("%s:%u\r\n", otSysGetThreadNetifName(), otSysGetThreadNetifIndex());
|
otCliOutputFormat("%s:%u\r\n", otSysGetThreadNetifName(), otSysGetThreadNetifIndex());
|
||||||
}
|
}
|
||||||
|
|
||||||
static const otCliCommand kCommands[] = {{"netif", ProcessNetif}};
|
#if !OPENTHREAD_POSIX_CONFIG_DAEMON_ENABLE
|
||||||
|
static void ProcessExit(void *aContext, uint8_t aArgsLength, char *aArgs[])
|
||||||
|
{
|
||||||
|
OT_UNUSED_VARIABLE(aContext);
|
||||||
|
OT_UNUSED_VARIABLE(aArgsLength);
|
||||||
|
OT_UNUSED_VARIABLE(aArgs);
|
||||||
|
|
||||||
|
exit(EXIT_SUCCESS);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static const otCliCommand kCommands[] = {
|
||||||
|
#if !OPENTHREAD_POSIX_CONFIG_DAEMON_ENABLE
|
||||||
|
{"exit", ProcessExit},
|
||||||
|
#endif
|
||||||
|
{"netif", ProcessNetif},
|
||||||
|
};
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user