Code

email plugin: Refactor the accept() loop.
authorFlorian Forster <octo@collectd.org>
Tue, 8 Dec 2015 11:51:29 +0000 (12:51 +0100)
committerFlorian Forster <octo@collectd.org>
Tue, 8 Dec 2015 11:51:32 +0000 (12:51 +0100)
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

src/email.c

index 7493cc6d6967bc07255d7fb91a12bb5a6039974b..6a1350f9edab96782d504409a2958263b59839a1 100644 (file)
@@ -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)