]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
socket-util: cache result of socket_ipv6_is_supported()
authorLennart Poettering <lennart@poettering.net>
Fri, 5 Mar 2021 17:46:31 +0000 (18:46 +0100)
committerLennart Poettering <lennart@poettering.net>
Fri, 5 Mar 2021 19:51:43 +0000 (20:51 +0100)
And while we are at it, log about unexpected errors.

src/basic/socket-util.c

index 8267988ad9c7f469d7761507099dd53e4e801313..315a99c3fa49f6f5fd19f719b03eda44ef64b556 100644 (file)
@@ -277,10 +277,23 @@ const char* socket_address_get_path(const SocketAddress *a) {
 }
 
 bool socket_ipv6_is_supported(void) {
-        if (access("/proc/net/if_inet6", F_OK) != 0)
-                return false;
+        static int cached = -1;
 
-        return true;
+        if (cached < 0) {
+
+                if (access("/proc/net/if_inet6", F_OK) < 0) {
+
+                        if (errno != ENOENT) {
+                                log_debug_errno(errno, "Unexpected error when checking whether /proc/net/if_inet6 exists: %m");
+                                return false;
+                        }
+
+                        cached = false;
+                } else
+                        cached = true;
+        }
+
+        return cached;
 }
 
 bool socket_address_matches_fd(const SocketAddress *a, int fd) {