Skip to content

Commit 8aea118

Browse files
committed
bluetoothHandler: fix segfault with early starting
This commit is trying to fix an early segfault. If the bluetooth stack is not ready, then the `Powered` value is null. Calling the `set_value` in this stage is causing `Segmentation fault`. This was leading to problems with automatic AA start on the Pi, so it was often necessary to start it manually afterwards: `/etc/init.d/S93aawgd start` (the process was not running)
1 parent 84ca61d commit 8aea118

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

aa_wireless_dongle/package/aawg/src/bluetoothHandler.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include <stdio.h>
2+
#include <unistd.h>
23

34
#include "common.h"
45
#include "bluetoothHandler.h"
@@ -99,6 +100,12 @@ void BluetoothHandler::setPower(bool on) {
99100
return;
100101
}
101102

103+
// wait up to 10 seconds if BT stack is not ready
104+
int i = 10;
105+
while (i-- && !m_adapter->powered->value()) {
106+
sleep(1);
107+
}
108+
102109
m_adapter->powered->set_value(on);
103110
Logger::instance()->info("Bluetooth adapter was powered %s\n", on ? "on" : "off");
104111
}

0 commit comments

Comments
 (0)