]> git.meshlink.io Git - meshlink/commitdiff
Make repeated calls to meshlink_start() without meshlink_stop() safe.
authorGuus Sliepen <guus@meshlink.io>
Fri, 13 Nov 2015 08:51:39 +0000 (08:51 +0000)
committerGuus Sliepen <guus@meshlink.io>
Sun, 25 Jun 2017 08:50:26 +0000 (10:50 +0200)
src/meshlink.c

index b3b18074b171c9d93b3217fcbde533b7a4a80326..446bc522df9cb13556ede9d946965fb91d9c959a 100644 (file)
@@ -941,10 +941,17 @@ bool meshlink_start(meshlink_handle_t *mesh) {
                meshlink_errno = MESHLINK_EINVAL;
                return false;
        }
-       pthread_mutex_lock(&(mesh->mesh_mutex));
        
        logger(mesh, MESHLINK_DEBUG, "meshlink_start called\n");
 
+       pthread_mutex_lock(&(mesh->mesh_mutex));
+
+       if(mesh->threadstarted) {
+               logger(mesh, MESHLINK_DEBUG, "thread was already running\n");
+               pthread_mutex_unlock(&(mesh->mesh_mutex));
+               return true;
+       }
+
        if(mesh->listen_socket[0].tcp.fd < 0) {
                logger(mesh, MESHLINK_ERROR, "Listening socket not open\n");
                meshlink_errno = MESHLINK_ENETWORK;