From e42d635195d0f17af156ee30146dfa8159134886 Mon Sep 17 00:00:00 2001 From: Jfreegman Date: Thu, 9 Oct 2014 16:39:01 -0400 Subject: [PATCH] non-critical thread failures shouldn't be fatal --- src/dns.c | 23 +++++++++++++++++------ src/groupchat.c | 20 ++++++++++++++------ 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/src/dns.c b/src/dns.c index fde57d9..2776742 100644 --- a/src/dns.c +++ b/src/dns.c @@ -407,12 +407,23 @@ void dns3_lookup(ToxWindow *self, Tox *m, const char *id_bin, const char *addr, t_data.m = m; t_data.busy = 1; - if (pthread_attr_init(&dns_thread.attr) != 0) - exit_toxic_err("failed in dns3_lookup", FATALERR_THREAD_ATTR); + if (pthread_attr_init(&dns_thread.attr) != 0) { + line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, RED, "Error: DNS thread attr failed to init"); + memset(&t_data, 0, sizeof(struct thread_data)); + return; + } - if (pthread_attr_setdetachstate(&dns_thread.attr, PTHREAD_CREATE_DETACHED) != 0) - exit_toxic_err("failed in dns3_lookup", FATALERR_THREAD_ATTR); + if (pthread_attr_setdetachstate(&dns_thread.attr, PTHREAD_CREATE_DETACHED) != 0) { + line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, RED, "Error: DNS thread attr failed to set"); + pthread_attr_destroy(&dns_thread.attr); + memset(&t_data, 0, sizeof(struct thread_data)); + return; + } - if (pthread_create(&dns_thread.tid, &dns_thread.attr, dns3_lookup_thread, NULL) != 0) - exit_toxic_err("failed in dns3_lookup", FATALERR_THREAD_CREATE); + if (pthread_create(&dns_thread.tid, &dns_thread.attr, dns3_lookup_thread, NULL) != 0) { + line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, RED, "Error: DNS thread failed to init"); + pthread_attr_destroy(&dns_thread.attr); + memset(&t_data, 0, sizeof(struct thread_data)); + return; + } } diff --git a/src/groupchat.c b/src/groupchat.c index 0c2b0b3..a0b2e26 100644 --- a/src/groupchat.c +++ b/src/groupchat.c @@ -396,14 +396,22 @@ static void groupchat_onGroupNamelistChange(ToxWindow *self, Tox *m, int groupnu thrd->self = self; thrd->timestamp = get_unix_time(); - if (pthread_attr_init(&thrd->attr) != 0) - exit_toxic_err("failed in groupchat_onGroupNamelistChange", FATALERR_THREAD_ATTR); + if (pthread_attr_init(&thrd->attr) != 0) { + free(thrd); + return; + } - if (pthread_attr_setdetachstate(&thrd->attr, PTHREAD_CREATE_DETACHED) != 0) - exit_toxic_err("failed in groupchat_onGroupNamelistChange", FATALERR_THREAD_ATTR); + if (pthread_attr_setdetachstate(&thrd->attr, PTHREAD_CREATE_DETACHED) != 0) { + pthread_attr_destroy(&thrd->attr); + free(thrd); + return; + } - if (pthread_create(&thrd->tid, &thrd->attr, group_add_wait, (void *) thrd) != 0) - exit_toxic_err("failed in groupchat_onGroupNamelistChange", FATALERR_THREAD_CREATE); + if (pthread_create(&thrd->tid, &thrd->attr, group_add_wait, (void *) thrd) != 0) { + pthread_attr_destroy(&thrd->attr); + free(thrd); + return; + } break;