Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6429a73a authored by Yun-Hao Chung's avatar Yun-Hao Chung Committed by Yun-hao Chung
Browse files

Floss: Explicitly use topstack runtime to spawn cleanup tasks

It is observed that in handling SIGTERM, the tokio::spawn could panic
because of no Tokio runtime at the time.

This explicitly uses topstack runtime to avoid the panic.

Bug: 359055353
Tag: #floss
Test: mmm packages/modules/Bluetooth
Test: rmmod btusb & modprobe multiple times to ensure no crash
Flag: EXEMPT, Floss-only changes
Change-Id: I7acd03030c49b46f7873c0fb6358490d13a032d1
parent b713c243
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -282,7 +282,7 @@ extern "C" fn handle_sigterm(_signum: i32) {
    if let Some((tx, notifier)) = guard.as_ref() {
        log::debug!("Handling SIGTERM by disabling the adapter!");
        let txl = tx.clone();
        tokio::spawn(async move {
        topstack::get_runtime().spawn(async move {
            // Send the shutdown message here.
            let _ = txl.send(Message::InterfaceShutdown).await;
        });
@@ -295,7 +295,7 @@ extern "C" fn handle_sigterm(_signum: i32) {

        log::debug!("SIGTERM cleaning up the stack.");
        let txl = tx.clone();
        tokio::spawn(async move {
        topstack::get_runtime().spawn(async move {
            // Clean up the profiles first as some of them might require main thread to clean up.
            let _ = txl.send(Message::CleanupProfiles).await;
            // Currently there is no good way to know when the profile is cleaned.