This was done to debug the code, but it fails when MeshLink is compiled with
-DNDEBUG. Remove all assert()s from calls to pthread functions, and instead
add explicit checks to only those functions that can fail.
- assert(pthread_cond_signal(&mesh->adns_cond) == 0);
+ pthread_cond_signal(&mesh->adns_cond);
pthread_join(mesh->adns_thread, NULL);
meshlink_queue_exit(&mesh->adns_queue);
pthread_join(mesh->adns_thread, NULL);
meshlink_queue_exit(&mesh->adns_queue);
- assert(pthread_cond_signal(&mesh->adns_cond) == 0);
+ pthread_cond_signal(&mesh->adns_cond);
}
struct adns_blocking_info {
}
struct adns_blocking_info {
- assert(pthread_mutex_lock(&info->mutex) == 0);
+ if(pthread_mutex_lock(&info->mutex) != 0) {
+ abort();
+ }
bool cleanup = info->done;
if(!info->done) {
info->done = true;
bool cleanup = info->done;
if(!info->done) {
info->done = true;
- assert(pthread_cond_signal(&info->cond) == 0);
+ pthread_cond_signal(&info->cond);
- assert(pthread_mutex_unlock(&info->mutex) == 0);
+ pthread_mutex_unlock(&info->mutex);
if(cleanup) {
free(info->host);
if(cleanup) {
free(info->host);
info->host = host;
info->serv = serv;
info->socktype = socktype;
info->host = host;
info->serv = serv;
info->socktype = socktype;
- assert(pthread_mutex_init(&info->mutex, NULL) == 0);
- assert(pthread_cond_init(&info->cond, NULL) == 0);
+ pthread_mutex_init(&info->mutex, NULL);
+ pthread_cond_init(&info->cond, NULL);
struct timespec deadline;
clock_gettime(CLOCK_REALTIME, &deadline);
struct timespec deadline;
clock_gettime(CLOCK_REALTIME, &deadline);
free(info);
return NULL;
} else {
free(info);
return NULL;
} else {
- assert(pthread_detach(thread) == 0);
+ pthread_detach(thread);
+ }
+
+ if(pthread_mutex_lock(&info->mutex) != 0) {
+ abort();
- assert(pthread_mutex_lock(&info->mutex) == 0);
- assert(pthread_cond_timedwait(&info->cond, &info->mutex, &deadline) == 0);
+ pthread_cond_timedwait(&info->cond, &info->mutex, &deadline);
struct addrinfo *result = NULL;
bool cleanup = info->done;
struct addrinfo *result = NULL;
bool cleanup = info->done;
- assert(pthread_mutex_unlock(&info->mutex) == 0);
+ pthread_mutex_unlock(&info->mutex);
if(cleanup) {
free(info->host);
if(cleanup) {
free(info->host);
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
devtool_edge_t *result = NULL;
unsigned int result_size = 0;
devtool_edge_t *result = NULL;
unsigned int result_size = 0;
meshlink_errno = MESHLINK_ENOMEM;
}
meshlink_errno = MESHLINK_ENOMEM;
}
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
// export edges and nodes
size_t node_count = 0;
// export edges and nodes
size_t node_count = 0;
free(nodes);
free(edges);
free(nodes);
free(edges);
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
node_t *internal = (node_t *)node;
node_t *internal = (node_t *)node;
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
memcpy(&status->status, &internal->status, sizeof status->status);
memcpy(&status->address, &internal->address, sizeof status->address);
memcpy(&status->status, &internal->status, sizeof status->status);
memcpy(&status->address, &internal->address, sizeof status->address);
status->udp_status = DEVTOOL_UDP_UNKNOWN;
}
status->udp_status = DEVTOOL_UDP_UNKNOWN;
}
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
}
meshlink_submesh_t **devtool_get_all_submeshes(meshlink_handle_t *mesh, meshlink_submesh_t **submeshes, size_t *nmemb) {
}
meshlink_submesh_t **devtool_get_all_submeshes(meshlink_handle_t *mesh, meshlink_submesh_t **submeshes, size_t *nmemb) {
meshlink_submesh_t **result;
//lock mesh->nodes
meshlink_submesh_t **result;
//lock mesh->nodes
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
*nmemb = mesh->submeshes->count;
result = realloc(submeshes, *nmemb * sizeof(*submeshes));
*nmemb = mesh->submeshes->count;
result = realloc(submeshes, *nmemb * sizeof(*submeshes));
meshlink_errno = MESHLINK_ENOMEM;
}
meshlink_errno = MESHLINK_ENOMEM;
}
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
switch(state) {
case CATTA_SERVER_RUNNING:
switch(state) {
case CATTA_SERVER_RUNNING:
/* The serve has startup successfully and registered its host
* name on the network, so it's time to create our services */
/* The serve has startup successfully and registered its host
* name on the network, so it's time to create our services */
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
if(!mesh->catta_group) {
discovery_create_services(mesh);
}
if(!mesh->catta_group) {
discovery_create_services(mesh);
}
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
char hostname[17];
generate_rand_string(mesh, hostname, sizeof(hostname));
char hostname[17];
generate_rand_string(mesh, hostname, sizeof(hostname));
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
assert(mesh->catta_server);
assert(mesh->catta_poll);
assert(mesh->catta_server);
assert(mesh->catta_poll);
catta_simple_poll_quit(mesh->catta_poll);
}
catta_simple_poll_quit(mesh->catta_poll);
}
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
}
break;
case CATTA_SERVER_REGISTERING:
}
break;
case CATTA_SERVER_REGISTERING:
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
/* Let's drop our registered services. When the server is back
* in CATTA_SERVER_RUNNING state we will register them
/* Let's drop our registered services. When the server is back
* in CATTA_SERVER_RUNNING state we will register them
mesh->catta_group = NULL;
}
mesh->catta_group = NULL;
}
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
break;
case CATTA_SERVER_FAILURE:
break;
case CATTA_SERVER_FAILURE:
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
assert(mesh->catta_server);
assert(mesh->catta_poll);
assert(mesh->catta_server);
assert(mesh->catta_poll);
/* Terminate on failure */
catta_simple_poll_quit(mesh->catta_poll);
/* Terminate on failure */
catta_simple_poll_quit(mesh->catta_poll);
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
break;
case CATTA_SERVER_INVALID:
break;
case CATTA_SERVER_INVALID:
char *node_fp = (char *)catta_string_list_get_text(node_fp_li) + strlen(MESHLINK_MDNS_FINGERPRINT_KEY);
if(node_name[0] == '=' && node_fp[0] == '=') {
char *node_fp = (char *)catta_string_list_get_text(node_fp_li) + strlen(MESHLINK_MDNS_FINGERPRINT_KEY);
if(node_name[0] == '=' && node_fp[0] == '=') {
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
logger(mesh, MESHLINK_WARNING, "Node %s is not part of the mesh network.\n", node_name);
}
logger(mesh, MESHLINK_WARNING, "Node %s is not part of the mesh network.\n", node_name);
}
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
/* Called whenever a new services becomes available on the LAN or is removed from the LAN */
switch(event) {
case CATTA_BROWSER_FAILURE:
/* Called whenever a new services becomes available on the LAN or is removed from the LAN */
switch(event) {
case CATTA_BROWSER_FAILURE:
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
+
catta_simple_poll_quit(mesh->catta_poll);
catta_simple_poll_quit(mesh->catta_poll);
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
break;
case CATTA_BROWSER_NEW:
break;
case CATTA_BROWSER_NEW:
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
+
catta_s_service_resolver_new(mesh->catta_server, interface_, protocol, name, type, domain, CATTA_PROTO_UNSPEC, 0, discovery_resolve_callback, mesh);
handle_network_change(mesh, ++mesh->catta_interfaces);
catta_s_service_resolver_new(mesh->catta_server, interface_, protocol, name, type, domain, CATTA_PROTO_UNSPEC, 0, discovery_resolve_callback, mesh);
handle_network_change(mesh, ++mesh->catta_interfaces);
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
break;
case CATTA_BROWSER_REMOVE:
break;
case CATTA_BROWSER_REMOVE:
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
+
handle_network_change(mesh, --mesh->catta_interfaces);
handle_network_change(mesh, --mesh->catta_interfaces);
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
break;
case CATTA_BROWSER_ALL_FOR_NOW:
break;
case CATTA_BROWSER_ALL_FOR_NOW:
meshlink_handle_t *mesh = userdata;
assert(mesh);
meshlink_handle_t *mesh = userdata;
assert(mesh);
- assert(pthread_mutex_lock(&mesh->discovery_mutex) == 0);
+ if(pthread_mutex_lock(&mesh->discovery_mutex) != 0) {
+ abort();
+ }
// handle catta logs
catta_set_log_function(discovery_log_cb);
// handle catta logs
catta_set_log_function(discovery_log_cb);
- assert(pthread_cond_broadcast(&mesh->discovery_cond) == 0);
- assert(pthread_mutex_unlock(&mesh->discovery_mutex) == 0);
+ pthread_cond_broadcast(&mesh->discovery_cond);
+ pthread_mutex_unlock(&mesh->discovery_mutex);
if(status) {
catta_simple_poll_loop(mesh->catta_poll);
if(status) {
catta_simple_poll_loop(mesh->catta_poll);
assert(!mesh->discovery_threadstarted);
assert(!mesh->catta_servicetype);
assert(!mesh->discovery_threadstarted);
assert(!mesh->catta_servicetype);
- assert(pthread_mutex_lock(&mesh->discovery_mutex) == 0);
+ if(pthread_mutex_lock(&mesh->discovery_mutex) != 0) {
+ abort();
+ }
// Start the discovery thread
if(pthread_create(&mesh->discovery_thread, NULL, discovery_loop, mesh) != 0) {
// Start the discovery thread
if(pthread_create(&mesh->discovery_thread, NULL, discovery_loop, mesh) != 0) {
- assert(pthread_mutex_unlock(&mesh->discovery_mutex) == 0);
+ pthread_mutex_unlock(&mesh->discovery_mutex);
logger(mesh, MESHLINK_ERROR, "Could not start discovery thread: %s\n", strerror(errno));
memset(&mesh->discovery_thread, 0, sizeof(mesh)->discovery_thread);
return false;
}
logger(mesh, MESHLINK_ERROR, "Could not start discovery thread: %s\n", strerror(errno));
memset(&mesh->discovery_thread, 0, sizeof(mesh)->discovery_thread);
return false;
}
- assert(pthread_cond_wait(&mesh->discovery_cond, &mesh->discovery_mutex) == 0);
- assert(pthread_mutex_unlock(&mesh->discovery_mutex) == 0);
+ pthread_cond_wait(&mesh->discovery_cond, &mesh->discovery_mutex);
+ pthread_mutex_unlock(&mesh->discovery_mutex);
mesh->discovery_threadstarted = true;
mesh->discovery_threadstarted = true;
// Wait for the discovery thread to finish
if(mesh->discovery_threadstarted == true) {
// Wait for the discovery thread to finish
if(mesh->discovery_threadstarted == true) {
- assert(pthread_join(mesh->discovery_thread, NULL) == 0);
+ if(pthread_join(mesh->discovery_thread, NULL) != 0) {
+ abort();
+ }
+
mesh->discovery_threadstarted = false;
}
mesh->discovery_threadstarted = false;
}
}
// release mesh mutex during select
}
// release mesh mutex during select
- assert(pthread_mutex_unlock(mutex) == 0);
+ pthread_mutex_unlock(mutex);
#ifdef HAVE_PSELECT
int n = pselect(fds, &readable, &writable, NULL, &ts, NULL);
#ifdef HAVE_PSELECT
int n = pselect(fds, &readable, &writable, NULL, &ts, NULL);
int n = select(fds, &readable, &writable, NULL, (struct timeval *)&tv);
#endif
int n = select(fds, &readable, &writable, NULL, (struct timeval *)&tv);
#endif
- assert(pthread_mutex_lock(mutex) == 0);
+ if(pthread_mutex_lock(mutex) != 0) {
+ abort();
+ }
clock_gettime(EVENT_CLOCK, &loop->now);
clock_gettime(EVENT_CLOCK, &loop->now);
pthread_t thr;
if(pthread_create(&thr, NULL, socket_in_netns_thread, ¶ms) == 0) {
pthread_t thr;
if(pthread_create(&thr, NULL, socket_in_netns_thread, ¶ms) == 0) {
- assert(pthread_join(thr, NULL) == 0);
+ if(pthread_join(thr, NULL) != 0) {
+ abort();
+ }
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
// Create hash for the new key
void *new_config_key;
// Create hash for the new key
void *new_config_key;
if(!prf(new_key, new_keylen, "MeshLink configuration key", 26, new_config_key, CHACHA_POLY1305_KEYLEN)) {
logger(mesh, MESHLINK_ERROR, "Error creating new configuration key!\n");
meshlink_errno = MESHLINK_EINTERNAL;
if(!prf(new_key, new_keylen, "MeshLink configuration key", 26, new_config_key, CHACHA_POLY1305_KEYLEN)) {
logger(mesh, MESHLINK_ERROR, "Error creating new configuration key!\n");
meshlink_errno = MESHLINK_EINTERNAL;
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
if(!config_copy(mesh, "current", mesh->config_key, "new", new_config_key)) {
logger(mesh, MESHLINK_ERROR, "Could not set up configuration in %s/old: %s\n", mesh->confbase, strerror(errno));
meshlink_errno = MESHLINK_ESTORAGE;
if(!config_copy(mesh, "current", mesh->config_key, "new", new_config_key)) {
logger(mesh, MESHLINK_ERROR, "Could not set up configuration in %s/old: %s\n", mesh->confbase, strerror(errno));
meshlink_errno = MESHLINK_ESTORAGE;
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
if(!config_rename(mesh, "current", "old")) {
logger(mesh, MESHLINK_ERROR, "Cannot rename %s/current to %s/old\n", mesh->confbase, mesh->confbase);
meshlink_errno = MESHLINK_ESTORAGE;
if(!config_rename(mesh, "current", "old")) {
logger(mesh, MESHLINK_ERROR, "Cannot rename %s/current to %s/old\n", mesh->confbase, mesh->confbase);
meshlink_errno = MESHLINK_ESTORAGE;
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
if(!config_rename(mesh, "new", "current")) {
logger(mesh, MESHLINK_ERROR, "Cannot rename %s/new to %s/current\n", mesh->confbase, mesh->confbase);
meshlink_errno = MESHLINK_ESTORAGE;
if(!config_rename(mesh, "new", "current")) {
logger(mesh, MESHLINK_ERROR, "Cannot rename %s/new to %s/current\n", mesh->confbase, mesh->confbase);
meshlink_errno = MESHLINK_ESTORAGE;
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
// Cleanup the "old" confbase sub-directory
if(!config_destroy(mesh->confbase, "old")) {
// Cleanup the "old" confbase sub-directory
if(!config_destroy(mesh->confbase, "old")) {
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
free(mesh->config_key);
mesh->config_key = new_config_key;
free(mesh->config_key);
mesh->config_key = new_config_key;
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
// initialize mutexes and conds
pthread_mutexattr_t attr;
// initialize mutexes and conds
pthread_mutexattr_t attr;
- assert(pthread_mutexattr_init(&attr) == 0);
- assert(pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE) == 0);
- assert(pthread_mutex_init(&mesh->mutex, &attr) == 0);
- assert(pthread_cond_init(&mesh->cond, NULL) == 0);
+ pthread_mutexattr_init(&attr);
+
+ if(pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE) != 0) {
+ abort();
+ }
+
+ pthread_mutex_init(&mesh->mutex, &attr);
+ pthread_cond_init(&mesh->cond, NULL);
- assert(pthread_mutex_init(&mesh->discovery_mutex, NULL) == 0);
- assert(pthread_cond_init(&mesh->discovery_cond, NULL) == 0);
+ pthread_mutex_init(&mesh->discovery_mutex, NULL);
+ pthread_cond_init(&mesh->discovery_cond, NULL);
- assert(pthread_cond_init(&mesh->adns_cond, NULL) == 0);
+ pthread_cond_init(&mesh->adns_cond, NULL);
mesh->threadstarted = false;
event_loop_init(&mesh->loop);
mesh->threadstarted = false;
event_loop_init(&mesh->loop);
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
s = (meshlink_submesh_t *)create_submesh(mesh, submesh);
s = (meshlink_submesh_t *)create_submesh(mesh, submesh);
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
#ifdef HAVE_SETNS
if(setns(mesh->netns, CLONE_NEWNET) != 0) {
#ifdef HAVE_SETNS
if(setns(mesh->netns, CLONE_NEWNET) != 0) {
- assert(pthread_cond_signal(&mesh->cond) == 0);
+ pthread_cond_signal(&mesh->cond);
- assert(pthread_cond_signal(&mesh->cond) == 0);
+ pthread_cond_signal(&mesh->cond);
return NULL;
#endif // HAVE_SETNS
}
return NULL;
#endif // HAVE_SETNS
}
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
logger(mesh, MESHLINK_DEBUG, "Starting main_loop...\n");
logger(mesh, MESHLINK_DEBUG, "Starting main_loop...\n");
- assert(pthread_cond_broadcast(&mesh->cond) == 0);
+ pthread_cond_broadcast(&mesh->cond);
main_loop(mesh);
logger(mesh, MESHLINK_DEBUG, "main_loop returned.\n");
main_loop(mesh);
logger(mesh, MESHLINK_DEBUG, "main_loop returned.\n");
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
logger(mesh, MESHLINK_DEBUG, "meshlink_start called\n");
logger(mesh, MESHLINK_DEBUG, "meshlink_start called\n");
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
assert(mesh->self);
assert(mesh->private_key);
assert(mesh->self);
assert(mesh->private_key);
if(mesh->threadstarted) {
logger(mesh, MESHLINK_DEBUG, "thread was already running\n");
if(mesh->threadstarted) {
logger(mesh, MESHLINK_DEBUG, "thread was already running\n");
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
if(!mesh->name) {
logger(mesh, MESHLINK_DEBUG, "No name given!\n");
meshlink_errno = MESHLINK_EINVAL;
if(!mesh->name) {
logger(mesh, MESHLINK_DEBUG, "No name given!\n");
meshlink_errno = MESHLINK_EINVAL;
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
// Ensure we have a decent amount of stack space. Musl's default of 80 kB is too small.
pthread_attr_t attr;
// Ensure we have a decent amount of stack space. Musl's default of 80 kB is too small.
pthread_attr_t attr;
- assert(pthread_attr_init(&attr) == 0);
- assert(pthread_attr_setstacksize(&attr, 1024 * 1024) == 0);
+ pthread_attr_init(&attr);
+ pthread_attr_setstacksize(&attr, 1024 * 1024);
if(pthread_create(&mesh->thread, &attr, meshlink_main_loop, mesh) != 0) {
logger(mesh, MESHLINK_DEBUG, "Could not start thread: %s\n", strerror(errno));
memset(&mesh->thread, 0, sizeof(mesh)->thread);
meshlink_errno = MESHLINK_EINTERNAL;
event_loop_stop(&mesh->loop);
if(pthread_create(&mesh->thread, &attr, meshlink_main_loop, mesh) != 0) {
logger(mesh, MESHLINK_DEBUG, "Could not start thread: %s\n", strerror(errno));
memset(&mesh->thread, 0, sizeof(mesh)->thread);
meshlink_errno = MESHLINK_EINTERNAL;
event_loop_stop(&mesh->loop);
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
- assert(pthread_cond_wait(&mesh->cond, &mesh->mutex) == 0);
+ pthread_cond_wait(&mesh->cond, &mesh->mutex);
mesh->threadstarted = true;
// Ensure we are considered reachable
graph(mesh);
mesh->threadstarted = true;
// Ensure we are considered reachable
graph(mesh);
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
+
logger(mesh, MESHLINK_DEBUG, "meshlink_stop called\n");
// Shut down the main thread
logger(mesh, MESHLINK_DEBUG, "meshlink_stop called\n");
// Shut down the main thread
if(mesh->threadstarted) {
// Wait for the main thread to finish
if(mesh->threadstarted) {
// Wait for the main thread to finish
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
- assert(pthread_join(mesh->thread, NULL) == 0);
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
+
+ if(pthread_join(mesh->thread, NULL) != 0) {
+ abort();
+ }
+
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
mesh->threadstarted = false;
}
mesh->threadstarted = false;
}
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
}
void meshlink_close(meshlink_handle_t *mesh) {
}
void meshlink_close(meshlink_handle_t *mesh) {
meshlink_stop(mesh);
// lock is not released after this
meshlink_stop(mesh);
// lock is not released after this
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
// Close and free all resources used.
// Close and free all resources used.
main_config_unlock(mesh);
main_config_unlock(mesh);
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
- assert(pthread_mutex_destroy(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
+ pthread_mutex_destroy(&mesh->mutex);
memset(mesh, 0, sizeof(*mesh));
memset(mesh, 0, sizeof(*mesh));
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
+
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
}
void meshlink_set_connection_try_cb(meshlink_handle_t *mesh, meshlink_connection_try_cb_t cb) {
}
void meshlink_set_connection_try_cb(meshlink_handle_t *mesh, meshlink_connection_try_cb_t cb) {
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
+
mesh->connection_try_cb = cb;
mesh->connection_try_cb = cb;
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
}
void meshlink_set_node_status_cb(meshlink_handle_t *mesh, meshlink_node_status_cb_t cb) {
}
void meshlink_set_node_status_cb(meshlink_handle_t *mesh, meshlink_node_status_cb_t cb) {
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
+
mesh->node_status_cb = cb;
mesh->node_status_cb = cb;
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
}
void meshlink_set_node_pmtu_cb(meshlink_handle_t *mesh, meshlink_node_pmtu_cb_t cb) {
}
void meshlink_set_node_pmtu_cb(meshlink_handle_t *mesh, meshlink_node_pmtu_cb_t cb) {
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
+
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
}
void meshlink_set_node_duplicate_cb(meshlink_handle_t *mesh, meshlink_node_duplicate_cb_t cb) {
}
void meshlink_set_node_duplicate_cb(meshlink_handle_t *mesh, meshlink_node_duplicate_cb_t cb) {
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
+
mesh->node_duplicate_cb = cb;
mesh->node_duplicate_cb = cb;
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
}
void meshlink_set_log_cb(meshlink_handle_t *mesh, meshlink_log_level_t level, meshlink_log_cb_t cb) {
if(mesh) {
}
void meshlink_set_log_cb(meshlink_handle_t *mesh, meshlink_log_level_t level, meshlink_log_cb_t cb) {
if(mesh) {
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
+
mesh->log_cb = cb;
mesh->log_level = cb ? level : 0;
mesh->log_cb = cb;
mesh->log_level = cb ? level : 0;
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
} else {
global_log_cb = cb;
global_log_level = cb ? level : 0;
} else {
global_log_cb = cb;
global_log_level = cb ? level : 0;
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
+
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
}
static bool prepare_packet(meshlink_handle_t *mesh, meshlink_node_t *destination, const void *data, size_t len, vpn_packet_t *packet) {
}
static bool prepare_packet(meshlink_handle_t *mesh, meshlink_node_t *destination, const void *data, size_t len, vpn_packet_t *packet) {
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
node_t *n = (node_t *)destination;
if(!n->status.reachable) {
node_t *n = (node_t *)destination;
if(!n->status.reachable) {
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
return 0;
} else if(n->mtuprobes > 30 && n->minmtu) {
return 0;
} else if(n->mtuprobes > 30 && n->minmtu) {
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
return n->minmtu;
} else {
return n->minmtu;
} else {
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
node_t *n = (node_t *)node;
if(!node_read_public_key(mesh, n) || !n->ecdsa) {
meshlink_errno = MESHLINK_EINTERNAL;
node_t *n = (node_t *)node;
if(!node_read_public_key(mesh, n) || !n->ecdsa) {
meshlink_errno = MESHLINK_EINTERNAL;
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
meshlink_errno = MESHLINK_EINTERNAL;
}
meshlink_errno = MESHLINK_EINTERNAL;
}
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
+
n = lookup_node(mesh, (char *)name); // TODO: make lookup_node() use const
n = lookup_node(mesh, (char *)name); // TODO: make lookup_node() use const
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
if(!n) {
meshlink_errno = MESHLINK_ENOENT;
if(!n) {
meshlink_errno = MESHLINK_ENOENT;
meshlink_submesh_t *submesh = NULL;
meshlink_submesh_t *submesh = NULL;
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
+
submesh = (meshlink_submesh_t *)lookup_submesh(mesh, name);
submesh = (meshlink_submesh_t *)lookup_submesh(mesh, name);
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
if(!submesh) {
meshlink_errno = MESHLINK_ENOENT;
if(!submesh) {
meshlink_errno = MESHLINK_ENOENT;
meshlink_node_t **result;
//lock mesh->nodes
meshlink_node_t **result;
//lock mesh->nodes
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
*nmemb = mesh->nodes->count;
result = realloc(nodes, *nmemb * sizeof(*nodes));
*nmemb = mesh->nodes->count;
result = realloc(nodes, *nmemb * sizeof(*nodes));
meshlink_errno = MESHLINK_ENOMEM;
}
meshlink_errno = MESHLINK_ENOMEM;
}
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
static meshlink_node_t **meshlink_get_all_nodes_by_condition(meshlink_handle_t *mesh, const void *condition, meshlink_node_t **nodes, size_t *nmemb, search_node_by_condition_t search_node) {
meshlink_node_t **result;
static meshlink_node_t **meshlink_get_all_nodes_by_condition(meshlink_handle_t *mesh, const void *condition, meshlink_node_t **nodes, size_t *nmemb, search_node_by_condition_t search_node) {
meshlink_node_t **result;
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
if(*nmemb == 0) {
free(nodes);
if(*nmemb == 0) {
free(nodes);
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
meshlink_errno = MESHLINK_ENOMEM;
}
meshlink_errno = MESHLINK_ENOMEM;
}
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
devclass = ((node_t *)node)->devclass;
devclass = ((node_t *)node)->devclass;
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
node_t *n = (node_t *)node;
bool reachable;
node_t *n = (node_t *)node;
bool reachable;
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
+
reachable = n->status.reachable && !n->status.blacklisted;
if(last_reachable) {
reachable = n->status.reachable && !n->status.blacklisted;
if(last_reachable) {
*last_unreachable = n->last_unreachable;
}
*last_unreachable = n->last_unreachable;
}
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
if(!ecdsa_sign(mesh->private_key, data, len, signature)) {
meshlink_errno = MESHLINK_EINTERNAL;
if(!ecdsa_sign(mesh->private_key, data, len, signature)) {
meshlink_errno = MESHLINK_EINTERNAL;
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
return false;
}
*siglen = MESHLINK_SIGLEN;
return false;
}
*siglen = MESHLINK_SIGLEN;
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
rval = ecdsa_verify(((struct node_t *)source)->ecdsa, data, len, signature);
}
rval = ecdsa_verify(((struct node_t *)source)->ecdsa, data, len, signature);
}
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
return rval;
}
static bool refresh_invitation_key(meshlink_handle_t *mesh) {
return rval;
}
static bool refresh_invitation_key(meshlink_handle_t *mesh) {
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
size_t count = invitation_purge_old(mesh, time(NULL) - mesh->invitation_timeout);
size_t count = invitation_purge_old(mesh, time(NULL) - mesh->invitation_timeout);
// TODO: Update invitation key if necessary?
}
// TODO: Update invitation key if necessary?
}
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
return mesh->invitation_key;
}
return mesh->invitation_key;
}
canonical_address = xstrdup(address);
}
canonical_address = xstrdup(address);
}
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
node_t *n = (node_t *)node;
free(n->canonical_address);
n->canonical_address = canonical_address;
if(!node_write_config(mesh, n)) {
node_t *n = (node_t *)node;
free(n->canonical_address);
n->canonical_address = canonical_address;
if(!node_write_config(mesh, n)) {
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
return config_sync(mesh, "current");
}
return config_sync(mesh, "current");
}
combo = xstrdup(address);
}
combo = xstrdup(address);
}
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
if(!mesh->invitation_addresses) {
mesh->invitation_addresses = list_alloc((list_action_t)free);
}
list_insert_tail(mesh->invitation_addresses, combo);
if(!mesh->invitation_addresses) {
mesh->invitation_addresses = list_alloc((list_action_t)free);
}
list_insert_tail(mesh->invitation_addresses, combo);
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
if(mesh->invitation_addresses) {
list_delete_list(mesh->invitation_addresses);
mesh->invitation_addresses = NULL;
}
if(mesh->invitation_addresses) {
list_delete_list(mesh->invitation_addresses);
mesh->invitation_addresses = NULL;
}
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
}
bool meshlink_add_address(meshlink_handle_t *mesh, const char *address) {
}
bool meshlink_add_address(meshlink_handle_t *mesh, const char *address) {
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
+
port = atoi(mesh->myport);
port = atoi(mesh->myport);
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
if(mesh->threadstarted) {
meshlink_errno = MESHLINK_EINVAL;
if(mesh->threadstarted) {
meshlink_errno = MESHLINK_EINVAL;
rval = config_sync(mesh, "current");
done:
rval = config_sync(mesh, "current");
done:
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
return rval && meshlink_get_port(mesh) == port;
}
return rval && meshlink_get_port(mesh) == port;
}
s = (meshlink_submesh_t *)mesh->self->submesh;
}
s = (meshlink_submesh_t *)mesh->self->submesh;
}
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
// Check validity of the new node's name
if(!check_id(name)) {
logger(mesh, MESHLINK_ERROR, "Invalid name for node.\n");
meshlink_errno = MESHLINK_EINVAL;
// Check validity of the new node's name
if(!check_id(name)) {
logger(mesh, MESHLINK_ERROR, "Invalid name for node.\n");
meshlink_errno = MESHLINK_EINVAL;
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
if(config_exists(mesh, "current", name)) {
logger(mesh, MESHLINK_ERROR, "A host config file for %s already exists!\n", name);
meshlink_errno = MESHLINK_EEXIST;
if(config_exists(mesh, "current", name)) {
logger(mesh, MESHLINK_ERROR, "A host config file for %s already exists!\n", name);
meshlink_errno = MESHLINK_EEXIST;
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
if(lookup_node(mesh, name)) {
logger(mesh, MESHLINK_ERROR, "A node with name %s is already known!\n", name);
meshlink_errno = MESHLINK_EEXIST;
if(lookup_node(mesh, name)) {
logger(mesh, MESHLINK_ERROR, "A node with name %s is already known!\n", name);
meshlink_errno = MESHLINK_EEXIST;
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
if(!address) {
logger(mesh, MESHLINK_ERROR, "No Address known for ourselves!\n");
meshlink_errno = MESHLINK_ERESOLV;
if(!address) {
logger(mesh, MESHLINK_ERROR, "No Address known for ourselves!\n");
meshlink_errno = MESHLINK_ERESOLV;
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
return NULL;
}
if(!refresh_invitation_key(mesh)) {
meshlink_errno = MESHLINK_EINTERNAL;
return NULL;
}
if(!refresh_invitation_key(mesh)) {
meshlink_errno = MESHLINK_EINTERNAL;
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
if(mesh->self->status.dirty) {
if(!node_write_config(mesh, mesh->self)) {
logger(mesh, MESHLINK_ERROR, "Could not write our own host config file!\n");
if(mesh->self->status.dirty) {
if(!node_write_config(mesh, mesh->self)) {
logger(mesh, MESHLINK_ERROR, "Could not write our own host config file!\n");
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
if(!invitation_write(mesh, "current", cookiehash, &config, mesh->config_key)) {
logger(mesh, MESHLINK_DEBUG, "Could not create invitation file %s: %s\n", cookiehash, strerror(errno));
meshlink_errno = MESHLINK_ESTORAGE;
if(!invitation_write(mesh, "current", cookiehash, &config, mesh->config_key)) {
logger(mesh, MESHLINK_DEBUG, "Could not create invitation file %s: %s\n", cookiehash, strerror(errno));
meshlink_errno = MESHLINK_ESTORAGE;
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
xasprintf(&url, "%s/%s%s", address, hash, cookie);
free(address);
xasprintf(&url, "%s/%s%s", address, hash, cookie);
free(address);
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
//TODO: think of a better name for this variable, or of a different way to tokenize the invitation URL.
char copy[strlen(invitation) + 1];
//TODO: think of a better name for this variable, or of a different way to tokenize the invitation URL.
char copy[strlen(invitation) + 1];
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
//Before doing meshlink_join make sure we are not connected to another mesh
if(mesh->threadstarted) {
//Before doing meshlink_join make sure we are not connected to another mesh
if(mesh->threadstarted) {
ecdsa_free(key);
closesocket(state.sock);
ecdsa_free(key);
closesocket(state.sock);
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
closesocket(state.sock);
}
closesocket(state.sock);
}
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
packmsg_add_str(&out, mesh->name);
packmsg_add_str(&out, CORE_MESH);
packmsg_add_str(&out, mesh->name);
packmsg_add_str(&out, CORE_MESH);
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
packmsg_add_int32(&out, mesh->self->devclass);
packmsg_add_bool(&out, mesh->self->status.blacklisted);
packmsg_add_int32(&out, mesh->self->devclass);
packmsg_add_bool(&out, mesh->self->status.blacklisted);
packmsg_add_int64(&out, 0);
packmsg_add_int64(&out, 0);
packmsg_add_int64(&out, 0);
packmsg_add_int64(&out, 0);
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
if(!packmsg_output_ok(&out)) {
logger(mesh, MESHLINK_DEBUG, "Error creating export data\n");
if(!packmsg_output_ok(&out)) {
logger(mesh, MESHLINK_DEBUG, "Error creating export data\n");
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
while(count--) {
const void *data2;
while(count--) {
const void *data2;
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
if(!blacklist(mesh, (node_t *)node)) {
if(!blacklist(mesh, (node_t *)node)) {
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
logger(mesh, MESHLINK_DEBUG, "Blacklisted %s.\n", node->name);
return true;
logger(mesh, MESHLINK_DEBUG, "Blacklisted %s.\n", node->name);
return true;
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
node_t *n = lookup_node(mesh, (char *)name);
node_t *n = lookup_node(mesh, (char *)name);
}
if(!blacklist(mesh, (node_t *)n)) {
}
if(!blacklist(mesh, (node_t *)n)) {
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
logger(mesh, MESHLINK_DEBUG, "Blacklisted %s.\n", name);
return true;
logger(mesh, MESHLINK_DEBUG, "Blacklisted %s.\n", name);
return true;
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
if(!whitelist(mesh, (node_t *)node)) {
if(!whitelist(mesh, (node_t *)node)) {
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
logger(mesh, MESHLINK_DEBUG, "Whitelisted %s.\n", node->name);
return true;
logger(mesh, MESHLINK_DEBUG, "Whitelisted %s.\n", node->name);
return true;
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
node_t *n = lookup_node(mesh, (char *)name);
node_t *n = lookup_node(mesh, (char *)name);
}
if(!whitelist(mesh, (node_t *)n)) {
}
if(!whitelist(mesh, (node_t *)n)) {
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
logger(mesh, MESHLINK_DEBUG, "Whitelisted %s.\n", name);
return true;
logger(mesh, MESHLINK_DEBUG, "Whitelisted %s.\n", name);
return true;
node_t *n = (node_t *)node;
node_t *n = (node_t *)node;
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
/* Check that the node is not reachable */
if(n->status.reachable || n->connection) {
/* Check that the node is not reachable */
if(n->status.reachable || n->connection) {
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
logger(mesh, MESHLINK_WARNING, "Could not forget %s: still reachable", n->name);
return false;
}
/* Check that we don't have any active UTCP connections */
if(n->utcp && utcp_is_active(n->utcp)) {
logger(mesh, MESHLINK_WARNING, "Could not forget %s: still reachable", n->name);
return false;
}
/* Check that we don't have any active UTCP connections */
if(n->utcp && utcp_is_active(n->utcp)) {
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
logger(mesh, MESHLINK_WARNING, "Could not forget %s: active UTCP connections", n->name);
return false;
}
logger(mesh, MESHLINK_WARNING, "Could not forget %s: active UTCP connections", n->name);
return false;
}
/* Check that we have no active connections to this node */
for list_each(connection_t, c, mesh->connections) {
if(c->node == n) {
/* Check that we have no active connections to this node */
for list_each(connection_t, c, mesh->connections) {
if(c->node == n) {
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
logger(mesh, MESHLINK_WARNING, "Could not forget %s: active connection", n->name);
return false;
}
logger(mesh, MESHLINK_WARNING, "Could not forget %s: active connection", n->name);
return false;
}
/* Delete the config file for this node */
if(!config_delete(mesh, "current", n->name)) {
/* Delete the config file for this node */
if(!config_delete(mesh, "current", n->name)) {
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
return false;
}
/* Delete the node struct and any remaining edges referencing this node */
node_del(mesh, n);
return false;
}
/* Delete the node struct and any remaining edges referencing this node */
node_del(mesh, n);
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
return config_sync(mesh, "current");
}
return config_sync(mesh, "current");
}
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
node_t *n = (node_t *)node;
node_t *n = (node_t *)node;
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
// @TODO do we want to fire off a connection attempt right away?
}
// @TODO do we want to fire off a connection attempt right away?
}
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
+
channel->poll_cb = cb;
utcp_set_poll_cb(channel->c, (cb || channel->aio_send) ? channel_poll : NULL);
channel->poll_cb = cb;
utcp_set_poll_cb(channel->c, (cb || channel->aio_send) ? channel_poll : NULL);
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
}
void meshlink_set_channel_accept_cb(meshlink_handle_t *mesh, meshlink_channel_accept_cb_t cb) {
}
void meshlink_set_channel_accept_cb(meshlink_handle_t *mesh, meshlink_channel_accept_cb_t cb) {
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
+
mesh->channel_accept_cb = cb;
mesh->receive_cb = channel_receive;
mesh->channel_accept_cb = cb;
mesh->receive_cb = channel_receive;
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
}
void meshlink_set_channel_sndbuf(meshlink_handle_t *mesh, meshlink_channel_t *channel, size_t size) {
}
void meshlink_set_channel_sndbuf(meshlink_handle_t *mesh, meshlink_channel_t *channel, size_t size) {
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
+
utcp_set_sndbuf(channel->c, size);
utcp_set_sndbuf(channel->c, size);
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
}
void meshlink_set_channel_rcvbuf(meshlink_handle_t *mesh, meshlink_channel_t *channel, size_t size) {
}
void meshlink_set_channel_rcvbuf(meshlink_handle_t *mesh, meshlink_channel_t *channel, size_t size) {
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
+
utcp_set_rcvbuf(channel->c, size);
utcp_set_rcvbuf(channel->c, size);
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
}
meshlink_channel_t *meshlink_channel_open_ex(meshlink_handle_t *mesh, meshlink_node_t *node, uint16_t port, meshlink_channel_receive_cb_t cb, const void *data, size_t len, uint32_t flags) {
}
meshlink_channel_t *meshlink_channel_open_ex(meshlink_handle_t *mesh, meshlink_node_t *node, uint16_t port, meshlink_channel_receive_cb_t cb, const void *data, size_t len, uint32_t flags) {
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
node_t *n = (node_t *)node;
node_t *n = (node_t *)node;
if(!n->utcp) {
meshlink_errno = errno == ENOMEM ? MESHLINK_ENOMEM : MESHLINK_EINTERNAL;
if(!n->utcp) {
meshlink_errno = errno == ENOMEM ? MESHLINK_ENOMEM : MESHLINK_EINTERNAL;
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
if(n->status.blacklisted) {
logger(mesh, MESHLINK_ERROR, "Cannot open a channel with blacklisted node\n");
meshlink_errno = MESHLINK_EBLACKLISTED;
if(n->status.blacklisted) {
logger(mesh, MESHLINK_ERROR, "Cannot open a channel with blacklisted node\n");
meshlink_errno = MESHLINK_EBLACKLISTED;
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
channel->c = utcp_connect_ex(n->utcp, port, channel_recv, channel, flags);
channel->c = utcp_connect_ex(n->utcp, port, channel_recv, channel, flags);
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
if(!channel->c) {
meshlink_errno = errno == ENOMEM ? MESHLINK_ENOMEM : MESHLINK_EINTERNAL;
if(!channel->c) {
meshlink_errno = errno == ENOMEM ? MESHLINK_ENOMEM : MESHLINK_EINTERNAL;
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
+
utcp_shutdown(channel->c, direction);
utcp_shutdown(channel->c, direction);
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
}
void meshlink_channel_close(meshlink_handle_t *mesh, meshlink_channel_t *channel) {
}
void meshlink_channel_close(meshlink_handle_t *mesh, meshlink_channel_t *channel) {
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
if(channel->c) {
utcp_close(channel->c);
if(channel->c) {
utcp_close(channel->c);
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
}
ssize_t meshlink_channel_send(meshlink_handle_t *mesh, meshlink_channel_t *channel, const void *data, size_t len) {
}
ssize_t meshlink_channel_send(meshlink_handle_t *mesh, meshlink_channel_t *channel, const void *data, size_t len) {
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
/* Disallow direct calls to utcp_send() while we still have AIO active. */
if(channel->aio_send) {
/* Disallow direct calls to utcp_send() while we still have AIO active. */
if(channel->aio_send) {
retval = utcp_send(channel->c, data, len);
}
retval = utcp_send(channel->c, data, len);
}
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
if(retval < 0) {
meshlink_errno = MESHLINK_ENETWORK;
if(retval < 0) {
meshlink_errno = MESHLINK_ENETWORK;
aio->cb.buffer = cb;
aio->priv = priv;
aio->cb.buffer = cb;
aio->priv = priv;
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
/* Append the AIO buffer descriptor to the end of the chain */
meshlink_aio_buffer_t **p = &channel->aio_send;
/* Append the AIO buffer descriptor to the end of the chain */
meshlink_aio_buffer_t **p = &channel->aio_send;
channel_poll(channel->c, todo);
}
channel_poll(channel->c, todo);
}
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
aio->cb.fd = cb;
aio->priv = priv;
aio->cb.fd = cb;
aio->priv = priv;
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
/* Append the AIO buffer descriptor to the end of the chain */
meshlink_aio_buffer_t **p = &channel->aio_send;
/* Append the AIO buffer descriptor to the end of the chain */
meshlink_aio_buffer_t **p = &channel->aio_send;
channel_poll(channel->c, left);
}
channel_poll(channel->c, left);
}
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
aio->cb.buffer = cb;
aio->priv = priv;
aio->cb.buffer = cb;
aio->priv = priv;
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
/* Append the AIO buffer descriptor to the end of the chain */
meshlink_aio_buffer_t **p = &channel->aio_receive;
/* Append the AIO buffer descriptor to the end of the chain */
meshlink_aio_buffer_t **p = &channel->aio_receive;
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
aio->cb.fd = cb;
aio->priv = priv;
aio->cb.fd = cb;
aio->priv = priv;
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
/* Append the AIO buffer descriptor to the end of the chain */
meshlink_aio_buffer_t **p = &channel->aio_receive;
/* Append the AIO buffer descriptor to the end of the chain */
meshlink_aio_buffer_t **p = &channel->aio_receive;
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
node_t *n = (node_t *)node;
node_t *n = (node_t *)node;
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
if(!n->utcp) {
n->utcp = utcp_init(channel_accept, channel_pre_accept, channel_send, n);
if(!n->utcp) {
n->utcp = utcp_init(channel_accept, channel_pre_accept, channel_send, n);
utcp_set_user_timeout(n->utcp, timeout);
utcp_set_user_timeout(n->utcp, timeout);
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
}
void update_node_status(meshlink_handle_t *mesh, node_t *n) {
}
void update_node_status(meshlink_handle_t *mesh, node_t *n) {
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
if(mesh->discovery == enable) {
goto end;
if(mesh->discovery == enable) {
goto end;
mesh->discovery = enable;
end:
mesh->discovery = enable;
end:
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
#else
(void)mesh;
(void)enable;
#else
(void)mesh;
(void)enable;
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
+
mesh->dev_class_traits[devclass].pinginterval = pinginterval;
mesh->dev_class_traits[devclass].pingtimeout = pingtimeout;
mesh->dev_class_traits[devclass].pinginterval = pinginterval;
mesh->dev_class_traits[devclass].pingtimeout = pingtimeout;
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
}
void meshlink_set_dev_class_fast_retry_period(meshlink_handle_t *mesh, dev_class_t devclass, int fast_retry_period) {
}
void meshlink_set_dev_class_fast_retry_period(meshlink_handle_t *mesh, dev_class_t devclass, int fast_retry_period) {
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
+
mesh->dev_class_traits[devclass].fast_retry_period = fast_retry_period;
mesh->dev_class_traits[devclass].fast_retry_period = fast_retry_period;
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
}
void meshlink_set_dev_class_maxtimeout(struct meshlink_handle *mesh, dev_class_t devclass, int maxtimeout) {
}
void meshlink_set_dev_class_maxtimeout(struct meshlink_handle *mesh, dev_class_t devclass, int maxtimeout) {
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
+
mesh->dev_class_traits[devclass].maxtimeout = maxtimeout;
mesh->dev_class_traits[devclass].maxtimeout = maxtimeout;
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
}
extern void meshlink_set_inviter_commits_first(struct meshlink_handle *mesh, bool inviter_commits_first) {
}
extern void meshlink_set_inviter_commits_first(struct meshlink_handle *mesh, bool inviter_commits_first) {
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
+
mesh->inviter_commits_first = inviter_commits_first;
mesh->inviter_commits_first = inviter_commits_first;
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
}
void meshlink_set_external_address_discovery_url(struct meshlink_handle *mesh, const char *url) {
}
void meshlink_set_external_address_discovery_url(struct meshlink_handle *mesh, const char *url) {
- assert(pthread_mutex_lock(&mesh->mutex) == 0);
+ if(pthread_mutex_lock(&mesh->mutex) != 0) {
+ abort();
+ }
+
free(mesh->external_address_url);
mesh->external_address_url = url ? xstrdup(url) : NULL;
free(mesh->external_address_url);
mesh->external_address_url = url ? xstrdup(url) : NULL;
- assert(pthread_mutex_unlock(&mesh->mutex) == 0);
+ pthread_mutex_unlock(&mesh->mutex);
}
void meshlink_set_scheduling_granularity(struct meshlink_handle *mesh, long granularity) {
}
void meshlink_set_scheduling_granularity(struct meshlink_handle *mesh, long granularity) {
static inline void meshlink_queue_init(meshlink_queue_t *queue) {
queue->head = NULL;
queue->tail = NULL;
static inline void meshlink_queue_init(meshlink_queue_t *queue) {
queue->head = NULL;
queue->tail = NULL;
- pthread_mutexattr_t attr;
- assert(pthread_mutexattr_init(&attr) == 0);
- assert(pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_DEFAULT) == 0);
- assert(pthread_mutex_init(&queue->mutex, &attr) == 0);
+ pthread_mutex_init(&queue->mutex, NULL);
}
static inline void meshlink_queue_exit(meshlink_queue_t *queue) {
}
static inline void meshlink_queue_exit(meshlink_queue_t *queue) {
- assert(pthread_mutex_destroy(&queue->mutex) == 0);
+ pthread_mutex_destroy(&queue->mutex);
}
static inline __attribute__((__warn_unused_result__)) bool meshlink_queue_push(meshlink_queue_t *queue, void *data) {
}
static inline __attribute__((__warn_unused_result__)) bool meshlink_queue_push(meshlink_queue_t *queue, void *data) {
item->data = data;
item->next = NULL;
item->data = data;
item->next = NULL;
- assert(pthread_mutex_lock(&queue->mutex) == 0);
+
+ if(pthread_mutex_lock(&queue->mutex) != 0) {
+ abort();
+ }
if(!queue->tail) {
queue->head = queue->tail = item;
if(!queue->tail) {
queue->head = queue->tail = item;
queue->tail = queue->tail->next = item;
}
queue->tail = queue->tail->next = item;
}
- assert(pthread_mutex_unlock(&queue->mutex) == 0);
+ pthread_mutex_unlock(&queue->mutex);
return true;
}
static inline __attribute__((__warn_unused_result__)) void *meshlink_queue_pop(meshlink_queue_t *queue) {
meshlink_queue_item_t *item;
return true;
}
static inline __attribute__((__warn_unused_result__)) void *meshlink_queue_pop(meshlink_queue_t *queue) {
meshlink_queue_item_t *item;
- assert(pthread_mutex_lock(&queue->mutex) == 0);
+ if(pthread_mutex_lock(&queue->mutex) != 0) {
+ abort();
+ }
if((item = queue->head)) {
queue->head = item->next;
if((item = queue->head)) {
queue->head = item->next;
- assert(pthread_mutex_unlock(&queue->mutex) == 0);
+ pthread_mutex_unlock(&queue->mutex);
void *data = item ? item->data : NULL;
free(item);
void *data = item ? item->data : NULL;
free(item);
static inline __attribute__((__warn_unused_result__)) void *meshlink_queue_pop_cond(meshlink_queue_t *queue, pthread_cond_t *cond) {
meshlink_queue_item_t *item;
static inline __attribute__((__warn_unused_result__)) void *meshlink_queue_pop_cond(meshlink_queue_t *queue, pthread_cond_t *cond) {
meshlink_queue_item_t *item;
- assert(pthread_mutex_lock(&queue->mutex) == 0);
+ if(pthread_mutex_lock(&queue->mutex) != 0) {
+ abort();
+ }
- assert(pthread_cond_wait(cond, &queue->mutex) == 0);
+ pthread_cond_wait(cond, &queue->mutex);
- assert(pthread_mutex_unlock(&queue->mutex) == 0);
+ pthread_mutex_unlock(&queue->mutex);
void *data = item->data;
free(item);
void *data = item->data;
free(item);