diff options
Diffstat (limited to 'tdutils.c')
-rw-r--r-- | tdutils.c | 7 |
1 files changed, 6 insertions, 1 deletions
@@ -44,6 +44,7 @@ static atomic_llong last_req_id = 0; */ bool closing = false; +static bool sighandler_setup = false; static pthread_t thread_sighandler; /** @@ -88,11 +89,15 @@ static void sighandler_init() { if ((r = pthread_create(&thread_sighandler, NULL, &main_sighandler, NULL))) { LOGFEV("pthread_create", r, strerror(r)); } + sighandler_setup = true; } static int sighandler_close() { + if (!sighandler_setup) return 0; pthread_cancel(thread_sighandler); - return pthread_join(thread_sighandler, NULL); + int r = pthread_join(thread_sighandler, NULL); + if (!r) sighandler_setup = false; + return r; } static int tdcb_push(long long request_id, void (*cb)(bool, struct TdObject *, struct TdError *, void *), void *cb_arg) { |