Blame SOURCES/0336-myhostname-fix-timeout-if-ipv6-is-disabled.patch

17b0f1
From 6e5117b83af5998359916f276a9b32f755c0e6f4 Mon Sep 17 00:00:00 2001
17b0f1
From: Jan Synacek <jsynacek@redhat.com>
17b0f1
Date: Fri, 20 May 2016 12:33:48 +0200
17b0f1
Subject: [PATCH] myhostname: fix timeout if ipv6 is disabled
17b0f1
17b0f1
rhel-only
17b0f1
Resolves: #1330973
17b0f1
---
17b0f1
 src/nss-myhostname/nss-myhostname.c |  9 +++++++--
17b0f1
 src/shared/socket-util.c            | 10 ++++++++++
17b0f1
 2 files changed, 17 insertions(+), 2 deletions(-)
17b0f1
17b0f1
diff --git a/src/nss-myhostname/nss-myhostname.c b/src/nss-myhostname/nss-myhostname.c
17b0f1
index a939bb267c..e197cc752d 100644
17b0f1
--- a/src/nss-myhostname/nss-myhostname.c
17b0f1
+++ b/src/nss-myhostname/nss-myhostname.c
17b0f1
@@ -33,6 +33,7 @@
17b0f1
 #include "local-addresses.h"
17b0f1
 #include "macro.h"
17b0f1
 #include "nss-util.h"
17b0f1
+#include "socket-util.h"
17b0f1
 #include "util.h"
17b0f1
 
17b0f1
 /* We use 127.0.0.2 as IPv4 address. This has the advantage over
17b0f1
@@ -380,9 +381,13 @@ enum nss_status _nss_myhostname_gethostbyname3_r(
17b0f1
                         return NSS_STATUS_NOTFOUND;
17b0f1
                 }
17b0f1
 
17b0f1
-                n_addresses = local_addresses(NULL, 0, af, &addresses);
17b0f1
-                if (n_addresses < 0)
17b0f1
+                if (af == AF_INET6 && !socket_ipv6_is_supported()) {
17b0f1
                         n_addresses = 0;
17b0f1
+                } else {
17b0f1
+                        n_addresses = local_addresses(NULL, 0, af, &addresses);
17b0f1
+                        if (n_addresses < 0)
17b0f1
+                                n_addresses = 0;
17b0f1
+                }
17b0f1
 
17b0f1
                 canonical = hn;
17b0f1
                 additional = n_addresses <= 0 && af == AF_INET6 ? "localhost" : NULL;
17b0f1
diff --git a/src/shared/socket-util.c b/src/shared/socket-util.c
17b0f1
index a212510146..79d1582d49 100644
17b0f1
--- a/src/shared/socket-util.c
17b0f1
+++ b/src/shared/socket-util.c
17b0f1
@@ -435,6 +435,16 @@ bool socket_ipv6_is_supported(void) {
17b0f1
                 return true;
17b0f1
 
17b0f1
         /* If module was loaded with disable=1 no IPv6 available */
17b0f1
+        if (l[0] == '1')
17b0f1
+                return false;
17b0f1
+
17b0f1
+        free(l);
17b0f1
+        l = NULL;
17b0f1
+
17b0f1
+        if (read_one_line_file("/proc/sys/net/ipv6/conf/all/disable_ipv6", &l) < 0)
17b0f1
+                return true;
17b0f1
+
17b0f1
+        /* If IPv6 was disabled via sysctl during runtime */
17b0f1
         return l[0] == '0';
17b0f1
 }
17b0f1