diff options
author | whd <7058128+superwhd@users.noreply.github.com> | 2022-05-02 10:16:27 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-01 19:16:27 -0700 |
commit | 1625224b2ae76199ef05c63f8493b518cab0c60a (patch) | |
tree | 8b6f3f0832118f1844c7e25d917fcff577b322ca /src/agent | |
parent | 96f176c9030b83392a009c8e5a983fb610672fc7 (diff) | |
download | ot-br-posix-1625224b2ae76199ef05c63f8493b518cab0c60a.tar.gz |
[platform] de-init application in `otPlatReset` and verify `Publisher` state in public methods (#1339)
When `otPlatReset` is called on `otbr-agent`, it should de-init the
old `otbr::Application` so that the resources will be properly
disposed, otherwise there will be dangling resources. Also,
`otbr::Application` should de-init the TREL module when itself is
de-initing.
One example is that if we call `ot-ctl factoryreset`, the old
`otbr::Application` won't be destructed so that the publisher will
keep the old mDNS service registrations until the process exits. In
such a situation, there will be two different MeshCoP services
published by the same `otbr-agent` process.
Also, this commit adds a verification at `Publisher` public methods to
ensure that `Publisher` is at `kReady` state.
Diffstat (limited to 'src/agent')
-rw-r--r-- | src/agent/main.cpp | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/src/agent/main.cpp b/src/agent/main.cpp index 675679be..c211abdd 100644 --- a/src/agent/main.cpp +++ b/src/agent/main.cpp @@ -68,7 +68,8 @@ enum OTBR_OPT_RADIO_VERSION, }; -static jmp_buf sResetJump; +static jmp_buf sResetJump; +static otbr::Application *gApp = nullptr; void __gcov_flush(); static const struct option kOptions[] = { @@ -211,6 +212,7 @@ static int realmain(int argc, char *argv[]) { otbr::Application app(interfaceName, backboneInterfaceName, radioUrls); + gApp = &app; app.Init(); ret = app.Run(); @@ -230,7 +232,9 @@ void otPlatReset(otInstance *aInstance) gPlatResetReason = OT_PLAT_RESET_REASON_SOFTWARE; - otSysDeinit(); + VerifyOrDie(gApp != nullptr, "gApp is null"); + gApp->Deinit(); + gApp = nullptr; longjmp(sResetJump, 1); assert(false); |