]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Remove few lines in unix socket handling
authorPetr Menšík <pemensik@redhat.com>
Tue, 12 Mar 2019 12:20:11 +0000 (13:20 +0100)
committerMark Andrews <marka@isc.org>
Fri, 24 Jul 2020 03:59:17 +0000 (13:59 +1000)
Reuse the same checks two times, make difference minimal.

(cherry picked from commit 72d81c4768a4731a1dd6a7c50a29286193105980)

lib/isc/unix/socket.c

index f204f7e416d83fc0f4ea66deb665c109132a4de5..d250a6f1fd2d797be42526ba191243b65973226a 100644 (file)
@@ -5418,22 +5418,34 @@ isc__socket_cleanunix(isc_sockaddr_t *sockaddr, bool active) {
 #define S_ISSOCK(mode) 0
 #endif
 
-       if (active) {
-               if (stat(sockaddr->type.sunix.sun_path, &sb) < 0) {
+       if (stat(sockaddr->type.sunix.sun_path, &sb) < 0) {
+               switch (errno) {
+               case ENOENT:
+                       if (active) { /* We exited cleanly last time */
+                               break;
+                       }
+                       /* intentional fallthrough */
+               default:
                        isc__strerror(errno, strbuf, sizeof(strbuf));
                        isc_log_write(isc_lctx, ISC_LOGCATEGORY_GENERAL,
-                                     ISC_LOGMODULE_SOCKET, ISC_LOG_ERROR,
+                                     ISC_LOGMODULE_SOCKET,
+                                     active ? ISC_LOG_ERROR : ISC_LOG_WARNING,
                                      "isc_socket_cleanunix: stat(%s): %s",
                                      sockaddr->type.sunix.sun_path, strbuf);
                        return;
                }
+       } else {
                if (!(S_ISSOCK(sb.st_mode) || S_ISFIFO(sb.st_mode))) {
                        isc_log_write(isc_lctx, ISC_LOGCATEGORY_GENERAL,
-                                     ISC_LOGMODULE_SOCKET, ISC_LOG_ERROR,
+                                     ISC_LOGMODULE_SOCKET,
+                                     active ? ISC_LOG_ERROR : ISC_LOG_WARNING,
                                      "isc_socket_cleanunix: %s: not a socket",
                                      sockaddr->type.sunix.sun_path);
                        return;
                }
+       }
+
+       if (active) {
                if (unlink(sockaddr->type.sunix.sun_path) < 0) {
                        isc__strerror(errno, strbuf, sizeof(strbuf));
                        isc_log_write(isc_lctx, ISC_LOGCATEGORY_GENERAL,
@@ -5454,31 +5466,9 @@ isc__socket_cleanunix(isc_sockaddr_t *sockaddr, bool active) {
                return;
        }
 
-       if (stat(sockaddr->type.sunix.sun_path, &sb) < 0) {
-               switch (errno) {
-               case ENOENT:    /* We exited cleanly last time */
-                       break;
-               default:
-                       isc__strerror(errno, strbuf, sizeof(strbuf));
-                       isc_log_write(isc_lctx, ISC_LOGCATEGORY_GENERAL,
-                                     ISC_LOGMODULE_SOCKET, ISC_LOG_WARNING,
-                                     "isc_socket_cleanunix: stat(%s): %s",
-                                     sockaddr->type.sunix.sun_path, strbuf);
-                       break;
-               }
-               goto cleanup;
-       }
-
-       if (!(S_ISSOCK(sb.st_mode) || S_ISFIFO(sb.st_mode))) {
-               isc_log_write(isc_lctx, ISC_LOGCATEGORY_GENERAL,
-                             ISC_LOGMODULE_SOCKET, ISC_LOG_WARNING,
-                             "isc_socket_cleanunix: %s: not a socket",
-                             sockaddr->type.sunix.sun_path);
-               goto cleanup;
-       }
-
-       if (connect(s, (struct sockaddr *)&sockaddr->type.sunix,
-                   sizeof(sockaddr->type.sunix)) < 0) {
+       if (connect(s, (const struct sockaddr *)&sockaddr->type.sunix,
+                   sizeof(sockaddr->type.sunix)) < 0)
+       {
                switch (errno) {
                case ECONNREFUSED:
                case ECONNRESET:
@@ -5502,7 +5492,6 @@ isc__socket_cleanunix(isc_sockaddr_t *sockaddr, bool active) {
                        break;
                }
        }
- cleanup:
        close(s);
 #else
        UNUSED(sockaddr);