]> git.meshlink.io Git - meshlink/blobdiff - src/meshlink.c
Fix __warn_unused_result__, add more of it and fix the resulting warnings.
[meshlink] / src / meshlink.c
index e6aea4dd3f708a644e482ee8de504414fd4c3e1d..75458fe6940ed221059e39b29035a2f84de6ccc8 100644 (file)
@@ -1361,7 +1361,11 @@ meshlink_handle_t *meshlink_open_ex(const meshlink_open_params_t *params) {
        }
 
        add_local_addresses(mesh);
-       node_write_config(mesh, mesh->self);
+
+       if(!node_write_config(mesh, mesh->self)) {
+               logger(NULL, MESHLINK_ERROR, "Cannot update configuration\n");
+               return NULL;
+       }
 
        idle_set(&mesh->loop, idle, mesh);
 
@@ -1550,12 +1554,11 @@ void meshlink_stop(meshlink_handle_t *mesh) {
 
        exit_outgoings(mesh);
 
-       // Write out any changed node config files
+       // Try to write out any changed node config files, ignore errors at this point.
        if(mesh->nodes) {
                for splay_each(node_t, n, mesh->nodes) {
                        if(n->status.dirty) {
-                               node_write_config(mesh, n);
-                               n->status.dirty = false;
+                               n->status.dirty = !node_write_config(mesh, n);
                        }
                }
        }
@@ -2169,11 +2172,15 @@ bool meshlink_set_canonical_address(meshlink_handle_t *mesh, meshlink_node_t *no
        node_t *n = (node_t *)node;
        free(n->canonical_address);
        n->canonical_address = canonical_address;
-       node_write_config(mesh, n);
+
+       if(!node_write_config(mesh, n)) {
+               pthread_mutex_unlock(&mesh->mutex);
+               return false;
+       }
 
        pthread_mutex_unlock(&mesh->mutex);
 
-       return true;
+       return config_sync(mesh, "current");
 }
 
 bool meshlink_add_address(meshlink_handle_t *mesh, const char *address) {
@@ -2805,7 +2812,11 @@ bool meshlink_import(meshlink_handle_t *mesh, const char *data) {
                        break;
                }
 
-               config_write(mesh, "current", n->name, &config, mesh->config_key);
+               if(!config_write(mesh, "current", n->name, &config, mesh->config_key)) {
+                       free_node(n);
+                       return false;
+               }
+
                node_add(mesh, n);
        }
 
@@ -2826,10 +2837,10 @@ bool meshlink_import(meshlink_handle_t *mesh, const char *data) {
        return true;
 }
 
-void meshlink_blacklist(meshlink_handle_t *mesh, meshlink_node_t *node) {
+bool meshlink_blacklist(meshlink_handle_t *mesh, meshlink_node_t *node) {
        if(!mesh || !node) {
                meshlink_errno = MESHLINK_EINVAL;
-               return;
+               return false;
        }
 
        pthread_mutex_lock(&mesh->mutex);
@@ -2841,20 +2852,16 @@ void meshlink_blacklist(meshlink_handle_t *mesh, meshlink_node_t *node) {
                logger(mesh, MESHLINK_ERROR, "%s blacklisting itself?\n", node->name);
                meshlink_errno = MESHLINK_EINVAL;
                pthread_mutex_unlock(&mesh->mutex);
-               return;
+               return false;
        }
 
        if(n->status.blacklisted) {
                logger(mesh, MESHLINK_DEBUG, "Node %s already blacklisted\n", node->name);
                pthread_mutex_unlock(&mesh->mutex);
-               return;
+               return true;
        }
 
        n->status.blacklisted = true;
-       node_write_config(mesh, n);
-       config_sync(mesh, "current");
-
-       logger(mesh, MESHLINK_DEBUG, "Blacklisted %s.\n", node->name);
 
        /* Immediately shut down any connections we have with the blacklisted node.
         * We can't call terminate_connection(), because we might be called from a callback function.
@@ -2873,13 +2880,22 @@ void meshlink_blacklist(meshlink_handle_t *mesh, meshlink_node_t *node) {
        n->mtuprobes = 0;
        n->status.udp_confirmed = false;
 
+       if(!node_write_config(mesh, n)) {
+               pthread_mutex_unlock(&mesh->mutex);
+               return false;
+       }
+
+       logger(mesh, MESHLINK_DEBUG, "Blacklisted %s.\n", node->name);
+
        pthread_mutex_unlock(&mesh->mutex);
+
+       return config_sync(mesh, "current");
 }
 
-void meshlink_whitelist(meshlink_handle_t *mesh, meshlink_node_t *node) {
+bool meshlink_whitelist(meshlink_handle_t *mesh, meshlink_node_t *node) {
        if(!mesh || !node) {
                meshlink_errno = MESHLINK_EINVAL;
-               return;
+               return false;
        }
 
        pthread_mutex_lock(&mesh->mutex);
@@ -2890,27 +2906,31 @@ void meshlink_whitelist(meshlink_handle_t *mesh, meshlink_node_t *node) {
                logger(mesh, MESHLINK_ERROR, "%s whitelisting itself?\n", node->name);
                meshlink_errno = MESHLINK_EINVAL;
                pthread_mutex_unlock(&mesh->mutex);
-               return;
+               return false;
        }
 
        if(!n->status.blacklisted) {
                logger(mesh, MESHLINK_DEBUG, "Node %s was already whitelisted\n", node->name);
                pthread_mutex_unlock(&mesh->mutex);
-               return;
+               return true;
        }
 
        n->status.blacklisted = false;
-       node_write_config(mesh, n);
-       config_sync(mesh, "current");
 
        if(n->status.reachable) {
                update_node_status(mesh, n);
        }
 
+       if(!node_write_config(mesh, n)) {
+               pthread_mutex_unlock(&mesh->mutex);
+               return false;
+       }
+
        logger(mesh, MESHLINK_DEBUG, "Whitelisted %s.\n", node->name);
 
        pthread_mutex_unlock(&mesh->mutex);
-       return;
+
+       return config_sync(mesh, "current");
 }
 
 void meshlink_set_default_blacklist(meshlink_handle_t *mesh, bool blacklist) {
@@ -2931,7 +2951,10 @@ void meshlink_hint_address(meshlink_handle_t *mesh, meshlink_node_t *node, const
        node_t *n = (node_t *)node;
        memmove(n->recent + 1, n->recent, 4 * sizeof(*n->recent));
        memcpy(n->recent, addr, SALEN(*addr));
-       node_write_config(mesh, n);
+
+       if(!node_write_config(mesh, n)) {
+               logger(mesh, MESHLINK_DEBUG, "Could not update %s\n", n->name);
+       }
 
        pthread_mutex_unlock(&mesh->mutex);
        // @TODO do we want to fire off a connection attempt right away?