From: Mehdi Abaakouk Date: Sun, 5 Mar 2017 20:01:48 +0000 (+0100) Subject: getdnsdomainname: cancel getaddrinfo_a if needed X-Git-Tag: neomutt-20170306~4 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a581f26e513aabdb0154ee653743c52be5c4edc5;p=neomutt getdnsdomainname: cancel getaddrinfo_a if needed if getaddrinfo_a() is not finish on time we must call gai_cancel() and wait getaddrinfo_a() to finish. Closes #453 --- diff --git a/getdomain.c b/getdomain.c index e93954709..3d89cf00e 100644 --- a/getdomain.c +++ b/getdomain.c @@ -52,16 +52,31 @@ int getdnsdomainname (char *d, size_t len) * If it takes longer, the system is mis-configured and the network is not * working properly, so... */ + int status; struct timespec timeout = {0, 100000000}; struct gaicb *reqs[1]; reqs[0] = safe_calloc(1, sizeof(*reqs[0])); reqs[0]->ar_name = node; reqs[0]->ar_request = &hints; - if ((getaddrinfo_a(GAI_NOWAIT, reqs, 1, NULL) == 0) && - (gai_suspend((const struct gaicb * const *) reqs, 1, &timeout) == 0) && - (gai_error(reqs[0]) == 0)) + if (getaddrinfo_a(GAI_NOWAIT, reqs, 1, NULL) == 0) { - h = reqs[0]->ar_result; + gai_suspend((const struct gaicb * const *) reqs, 1, &timeout); + status = gai_error(reqs[0]); + if (status == 0) + h = reqs[0]->ar_result; + else if (status == EAI_INPROGRESS) + { + mutt_debug(1, "getdnsdomainname timeout\n"); + /* request is not finish, cancel it to free it safely */ + if (gai_cancel(reqs[0]) == EAI_NOTCANCELED) + { + while (gai_suspend ((const struct gaicb * const *) reqs, 1, NULL) != 0) + continue; + } + } + else + mutt_debug(1, "getdnsdomainname fail: (%d) %s\n", + status, gai_strerror(status)); } FREE(&reqs[0]);