From: Florian Forster Date: Tue, 8 Dec 2015 11:51:29 +0000 (+0100) Subject: email plugin: Refactor the accept() loop. X-Git-Tag: collectd-5.5.1~13^2~13 X-Git-Url: https://git.octo.it/?a=commitdiff_plain;h=0672b1d3b0c914d54191a7ca203d02061792a9bd;p=collectd.git email plugin: Refactor the accept() loop. This removes the assumption that accept() returning a socket (success) implies that errno is not equal to EINTR. This is probably a reasonable assumption, but trips up Coverity may be a bit hard to read. CID: 38009 --- diff --git a/src/email.c b/src/email.c index 7493cc6d..6a1350f9 100644 --- a/src/email.c +++ b/src/email.c @@ -505,20 +505,27 @@ static void *open_connection (void __attribute__((unused)) *arg) pthread_mutex_unlock (&available_mutex); - do { + while (42) { errno = 0; - if (-1 == (remote = accept (connector_socket, NULL, NULL))) { - if (EINTR != errno) { - char errbuf[1024]; - disabled = 1; - close (connector_socket); - connector_socket = -1; - log_err ("accept() failed: %s", - sstrerror (errno, errbuf, sizeof (errbuf))); - pthread_exit ((void *)1); - } + + remote = accept (connector_socket, NULL, NULL); + if (remote == -1) { + char errbuf[1024]; + + if (errno == EINTR) + continue; + + disabled = 1; + close (connector_socket); + connector_socket = -1; + log_err ("accept() failed: %s", + sstrerror (errno, errbuf, sizeof (errbuf))); + pthread_exit ((void *)1); } - } while (EINTR == errno); + + /* access() succeeded. */ + break; + } connection = malloc (sizeof (*connection)); if (connection != NULL)