summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
3e80394)
Starting multiple Avahi threads in one process will fail with one of the
threads triggering an assert(), thus killing the process. It's not
critical that Avahi runs, so make sure we only start one.
#define MSG_NOSIGNAL 0
#endif
#define MSG_NOSIGNAL 0
#endif
+static pthread_mutex_t global_mutex;
+static bool discovery_started;
+
__thread meshlink_errno_t meshlink_errno;
//TODO: this can go away completely
__thread meshlink_errno_t meshlink_errno;
//TODO: this can go away completely
mesh->threadstarted=true;
// Start discovery
mesh->threadstarted=true;
// Start discovery
- if(!discovery_start(mesh))
- return false;
+ // Since only one Avahi instance can run in one program at the moment, make sure we only start one, ignore it otherwise.
+
+ bool discovery_on = false;
+ pthread_mutex_lock(&global_mutex);
+ if(!discovery_started)
+ discovery_on = discovery_started = true;
+ pthread_mutex_unlock(&global_mutex);
+
+ if(discovery_on)
+ discovery_start(mesh);
+
+ bool discovery_on = mesh->discovery_threadstarted;
+ if(discovery_on) {
+ pthread_mutex_lock(&global_mutex);
+ discovery_started = false;
+ pthread_mutex_unlock(&global_mutex);
+ }
// Shut down a listening socket to signal the main thread to shut down
// Shut down a listening socket to signal the main thread to shut down
append_config_file(mesh, node->name, "Address", full_addr_str);
fail:
append_config_file(mesh, node->name, "Address", full_addr_str);
fail:
free(addr_str);
free(port_str);
free(full_addr_str);
free(addr_str);
free(port_str);
free(full_addr_str);