summaryrefslogtreecommitdiff
path: root/src/basic/socket-util.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2021-03-05 18:46:31 +0100
committerLennart Poettering <lennart@poettering.net>2021-03-05 20:51:43 +0100
commit571ec995fe035557d4166ae310f627bdf307714b (patch)
tree2fa808f6badc8d3a3539e1424849e079d88346ad /src/basic/socket-util.c
parentb0ffd2760c16bb3f188a8fedc459e9f99692efae (diff)
downloadsystemd-571ec995fe035557d4166ae310f627bdf307714b.tar.gz
socket-util: cache result of socket_ipv6_is_supported()
And while we are at it, log about unexpected errors.
Diffstat (limited to 'src/basic/socket-util.c')
-rw-r--r--src/basic/socket-util.c19
1 files changed, 16 insertions, 3 deletions
diff --git a/src/basic/socket-util.c b/src/basic/socket-util.c
index 8267988ad9..315a99c3fa 100644
--- a/src/basic/socket-util.c
+++ b/src/basic/socket-util.c
@@ -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) {