@@ -123,6 +123,12 @@ static void disconnect_callback(void *user_data)
l_main_quit();
}
+static void kill_to(struct l_timeout *timeout, void *user_data)
+{
+ l_timeout_remove(timeout);
+ l_main_quit();
+}
+
static void signal_handler(uint32_t signo, void *user_data)
{
static bool terminated;
@@ -131,13 +137,38 @@ static void signal_handler(uint32_t signo, void *user_data)
return;
l_info("Terminating");
- l_main_quit();
+ mesh_cleanup(true);
+ l_timeout_create(1, kill_to, NULL, NULL);
terminated = true;
}
static bool parse_io(const char *optarg, enum mesh_io_type *type, void **opts)
{
- if (strstr(optarg, "generic") == optarg) {
+ if (strstr(optarg, "auto") == optarg) {
+ int *index = l_new(int, 1);
+
+ *type = MESH_IO_TYPE_AUTO;
+ *opts = index;
+
+ optarg += strlen("auto");
+ if (!*optarg) {
+ *index = MGMT_INDEX_NONE;
+ return true;
+ }
+
+ if (*optarg != ':')
+ return false;
+
+ optarg++;
+
+ if (sscanf(optarg, "hci%d", index) == 1)
+ return true;
+
+ if (sscanf(optarg, "%d", index) == 1)
+ return true;
+
+ return false;
+ } else if (strstr(optarg, "generic") == optarg) {
int *index = l_new(int, 1);
*type = MESH_IO_TYPE_GENERIC;
@@ -251,7 +282,7 @@ int main(int argc, char *argv[])
}
if (!io)
- io = l_strdup_printf("generic");
+ io = l_strdup_printf("auto");
if (!parse_io(io, &io_type, &io_opts)) {
l_error("Invalid io: %s", io);
@@ -295,7 +326,7 @@ done:
l_free(io);
l_free(io_opts);
- mesh_cleanup();
+ mesh_cleanup(false);
l_dbus_destroy(dbus);
l_main_exit();
@@ -324,11 +324,15 @@ static void free_pending_join_call(bool failed)
join_pending = NULL;
}
-void mesh_cleanup(void)
+void mesh_cleanup(bool signaled)
{
struct l_dbus_message *reply;
mesh_io_destroy(mesh.io);
+ mesh.io = NULL;
+
+ if (signaled)
+ return;
if (join_pending) {
@@ -28,7 +28,7 @@ typedef void (*prov_rx_cb_t)(void *user_data, const uint8_t *data,
bool mesh_init(const char *config_dir, const char *mesh_conf_fname,
enum mesh_io_type type, void *opts,
mesh_ready_func_t cb, void *user_data);
-void mesh_cleanup(void);
+void mesh_cleanup(bool signaled);
bool mesh_dbus_init(struct l_dbus *dbus);
const char *mesh_status_str(uint8_t err);