diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/fastd.c | 16 | ||||
-rw-r--r-- | src/fastd.h | 3 | ||||
-rw-r--r-- | src/poll.c | 1 | ||||
-rw-r--r-- | src/resolve.c | 5 | ||||
-rw-r--r-- | src/verify.c | 5 |
5 files changed, 16 insertions, 14 deletions
diff --git a/src/fastd.c b/src/fastd.c index 1841c42..b5cc758 100644 --- a/src/fastd.c +++ b/src/fastd.c @@ -40,7 +40,6 @@ #include <fastd_version.h> #include <grp.h> -#include <pthread.h> #include <signal.h> #include <syslog.h> #include <sys/resource.h> @@ -539,6 +538,15 @@ static inline void init(int argc, char *argv[]) { ctx.next_maintenance = fastd_in_seconds(MAINTENANCE_INTERVAL); ctx.unknown_handshakes[0].timeout = ctx.now; + VECTOR_ALLOC(ctx.eth_addrs, 0); + VECTOR_ALLOC(ctx.peers, 0); + VECTOR_ALLOC(ctx.async_pids, 0); + + if (pthread_attr_init(&ctx.detached_thread)) + exit_errno("pthread_attr_init"); + if (pthread_attr_setdetachstate(&ctx.detached_thread, PTHREAD_CREATE_DETACHED)) + exit_errno("pthread_attr_setdetachstate"); + pr_info("fastd " FASTD_VERSION " starting"); fastd_cap_init(); @@ -558,10 +566,6 @@ static inline void init(int argc, char *argv[]) { set_groups(); write_pid(); - VECTOR_ALLOC(ctx.eth_addrs, 0); - VECTOR_ALLOC(ctx.peers, 0); - VECTOR_ALLOC(ctx.async_pids, 0); - fastd_peer_hashtable_init(); #ifdef ENABLE_SYSTEMD @@ -681,6 +685,8 @@ static inline void cleanup(void) { fastd_peer_hashtable_free(); + pthread_attr_destroy(&ctx.detached_thread); + VECTOR_FREE(ctx.async_pids); VECTOR_FREE(ctx.peers); VECTOR_FREE(ctx.eth_addrs); diff --git a/src/fastd.h b/src/fastd.h index f69f2f8..19660db 100644 --- a/src/fastd.h +++ b/src/fastd.h @@ -41,6 +41,7 @@ #include <errno.h> #include <fcntl.h> +#include <pthread.h> #include <poll.h> #include <stdarg.h> #include <stdio.h> @@ -258,6 +259,8 @@ struct fastd_context { int async_rfd; /**< The read side of the pipe used to send data from other thread to the main thread */ int async_wfd; /**< The write side of the pipe used to send data from other thread to the main thread */ + pthread_attr_t detached_thread; /**< pthread_attr_t for creating detached threads */ + int tunfd; /**< The file descriptor of the tunnel interface */ size_t n_socks; /**< The number of sockets in socks */ @@ -34,7 +34,6 @@ #include "async.h" #include "peer.h" -#include <pthread.h> #include <signal.h> diff --git a/src/resolve.c b/src/resolve.c index b37cef6..1020253 100644 --- a/src/resolve.c +++ b/src/resolve.c @@ -34,7 +34,6 @@ #include "async.h" #include <netdb.h> -#include <pthread.h> /** The argument given to the resolver thread */ @@ -134,7 +133,7 @@ void fastd_resolve_peer(fastd_peer_t *peer, fastd_remote_t *remote) { arg->constraints = remote->config->address; pthread_t thread; - if ((errno = pthread_create(&thread, NULL, resolve_peer, arg)) != 0) { + if ((errno = pthread_create(&thread, &ctx.detached_thread, resolve_peer, arg)) != 0) { pr_error_errno("unable to create resolver thread"); free(arg->hostname); @@ -142,6 +141,4 @@ void fastd_resolve_peer(fastd_peer_t *peer, fastd_remote_t *remote) { return; } - - pthread_detach(thread); } diff --git a/src/verify.c b/src/verify.c index 4cf0c67..d875a34 100644 --- a/src/verify.c +++ b/src/verify.c @@ -38,8 +38,6 @@ #include "async.h" #include "shell.h" -#include <pthread.h> - /** Calls the on-verify command and returns the result @@ -120,7 +118,7 @@ fastd_tristate_t fastd_verify_peer(fastd_peer_t *peer, fastd_socket_t *sock, con memcpy(arg->ret.protocol_data, data, data_len); pthread_t thread; - if ((errno = pthread_create(&thread, NULL, do_verify_thread, arg)) != 0) { + if ((errno = pthread_create(&thread, &ctx.detached_thread, do_verify_thread, arg)) != 0) { pr_error_errno("unable to create verify thread"); fastd_shell_env_free(env); @@ -129,7 +127,6 @@ fastd_tristate_t fastd_verify_peer(fastd_peer_t *peer, fastd_socket_t *sock, con return fastd_tristate_false; } - pthread_detach(thread); return fastd_tristate_undef; } } |