From be06d7c29aec9ce1a8a163cc1db755d273e2dfc9 Mon Sep 17 00:00:00 2001 From: Handa Wang <7058128+superwhd@users.noreply.github.com> Date: Wed, 13 Mar 2024 00:29:52 +0800 Subject: [PATCH] [daemon] always initialize the OT CLI when setting up the daemon (#9919) Previously the OT CLI won't be reiniitalized when it finds there's already a listening socket. It's actually necessary to do the initialize, considering this scenario: 1. Run `otSysDeinit()` and `otSysInit()` to reset the OT application. 1. Note that the OT instance is replaced by a new one in `otSysInit()`. We need to call `otCliInit()` in `Daemon` to initialize the CLI with the new instance. However, this step has been skipped in `Daemon` because the listening socket is not cleared. --- src/posix/platform/daemon.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/posix/platform/daemon.cpp b/src/posix/platform/daemon.cpp index cffe0b14a..14c40cf8a 100644 --- a/src/posix/platform/daemon.cpp +++ b/src/posix/platform/daemon.cpp @@ -184,6 +184,7 @@ void Daemon::createListenSocketOrDie(void) // This returns the init-managed stream socket which is already bind to // /dev/socket/ot-daemon/.sock mListenSocket = android_get_control_socket(socketFile); + if (mListenSocket == -1) { DieNowWithMessage("android_get_control_socket", OT_EXIT_ERROR_ERRNO); @@ -284,13 +285,13 @@ void Daemon::SetUp(void) DieNowWithMessage("listen", OT_EXIT_ERROR_ERRNO); } +exit: #if OPENTHREAD_POSIX_CONFIG_DAEMON_CLI_ENABLE otSysCliInitUsingDaemon(gInstance); #endif Mainloop::Manager::Get().Add(*this); -exit: return; }