daandemeyer / rpms / systemd

Forked from rpms/systemd 2 years ago
Clone
923a60
From b2dfc6d1b697da2e649b04ad0b8c3aef7a7d4d88 Mon Sep 17 00:00:00 2001
923a60
From: Lennart Poettering <lennart@poettering.net>
923a60
Date: Fri, 15 May 2015 20:15:59 +0200
923a60
Subject: [PATCH] socket-util: socket_address_parse() should not log errors on
923a60
 its own
923a60
923a60
Given that socket_address_parse() is mostly a "library" call it
923a60
shouldn't log on its own, but leave that to its caller.
923a60
923a60
This patch removes logging from the call in case IPv6 is not available
923a60
but and IPv6 address shall be parsed. Instead a new call
923a60
socket_address_parse_and_warn() is introduced which first invokes
923a60
socket_address_parse() and then logs if necessary.
923a60
923a60
This should fix "make check" on ipv6-less kernels:
923a60
923a60
http://lists.freedesktop.org/archives/systemd-devel/2015-April/031385.html
923a60
(cherry picked from commit 7693146dee53a2b0f524e977188347166bf454ca)
923a60
923a60
Related: #1497639
923a60
---
923a60
 src/core/load-fragment.c |  2 +-
923a60
 src/shared/socket-util.c | 29 +++++++++++++++++++----------
923a60
 src/shared/socket-util.h |  1 +
923a60
 3 files changed, 21 insertions(+), 11 deletions(-)
923a60
923a60
diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c
923a60
index 58e44b89b2..0c0fa0f506 100644
923a60
--- a/src/core/load-fragment.c
923a60
+++ b/src/core/load-fragment.c
923a60
@@ -365,7 +365,7 @@ int config_parse_socket_listen(const char *unit,
923a60
                         log_syntax(unit, LOG_ERR, filename, line, -r,
923a60
                                    "Failed to resolve unit specifiers on %s, ignoring: %s", rvalue, strerror(-r));
923a60
 
923a60
-                r = socket_address_parse(&p->address, k ? k : rvalue);
923a60
+                r = socket_address_parse_and_warn(&p->address, k ? k : rvalue);
923a60
                 if (r < 0) {
923a60
                         if (r != -EAFNOSUPPORT)
923a60
                                 log_syntax(unit, LOG_ERR, filename, line, -r,
923a60
diff --git a/src/shared/socket-util.c b/src/shared/socket-util.c
923a60
index baab6353e1..b14e368176 100644
923a60
--- a/src/shared/socket-util.c
923a60
+++ b/src/shared/socket-util.c
923a60
@@ -55,11 +55,6 @@ int socket_address_parse(SocketAddress *a, const char *s) {
923a60
         if (*s == '[') {
923a60
                 /* IPv6 in [x:.....:z]:p notation */
923a60
 
923a60
-                if (!socket_ipv6_is_supported()) {
923a60
-                        log_warning("Binding to IPv6 address not available since kernel does not support IPv6.");
923a60
-                        return -EAFNOSUPPORT;
923a60
-                }
923a60
-
923a60
                 e = strchr(s+1, ']');
923a60
                 if (!e)
923a60
                         return -EINVAL;
923a60
@@ -144,11 +139,6 @@ int socket_address_parse(SocketAddress *a, const char *s) {
923a60
                                 if (idx == 0)
923a60
                                         return -EINVAL;
923a60
 
923a60
-                                if (!socket_ipv6_is_supported()) {
923a60
-                                        log_warning("Binding to interface is not available since kernel does not support IPv6.");
923a60
-                                        return -EAFNOSUPPORT;
923a60
-                                }
923a60
-
923a60
                                 a->sockaddr.in6.sin6_family = AF_INET6;
923a60
                                 a->sockaddr.in6.sin6_port = htons((uint16_t) u);
923a60
                                 a->sockaddr.in6.sin6_scope_id = idx;
923a60
@@ -182,6 +172,25 @@ int socket_address_parse(SocketAddress *a, const char *s) {
923a60
         return 0;
923a60
 }
923a60
 
923a60
+int socket_address_parse_and_warn(SocketAddress *a, const char *s) {
923a60
+        SocketAddress b;
923a60
+        int r;
923a60
+
923a60
+        /* Similar to socket_address_parse() but warns for IPv6 sockets when we don't support them. */
923a60
+
923a60
+        r = socket_address_parse(&b, s);
923a60
+        if (r < 0)
923a60
+                return r;
923a60
+
923a60
+        if (!socket_ipv6_is_supported() && b.sockaddr.sa.sa_family == AF_INET6) {
923a60
+                log_warning("Binding to IPv6 address not available since kernel does not support IPv6.");
923a60
+                return -EAFNOSUPPORT;
923a60
+        }
923a60
+
923a60
+        *a = b;
923a60
+        return 0;
923a60
+}
923a60
+
923a60
 int socket_address_parse_netlink(SocketAddress *a, const char *s) {
923a60
         int family;
923a60
         unsigned group = 0;
923a60
diff --git a/src/shared/socket-util.h b/src/shared/socket-util.h
923a60
index 6bfb677fb5..9200ce8822 100644
923a60
--- a/src/shared/socket-util.h
923a60
+++ b/src/shared/socket-util.h
923a60
@@ -67,6 +67,7 @@ typedef enum SocketAddressBindIPv6Only {
923a60
 #define socket_address_family(a) ((a)->sockaddr.sa.sa_family)
923a60
 
923a60
 int socket_address_parse(SocketAddress *a, const char *s);
923a60
+int socket_address_parse_and_warn(SocketAddress *a, const char *s);
923a60
 int socket_address_parse_netlink(SocketAddress *a, const char *s);
923a60
 int socket_address_print(const SocketAddress *a, char **p);
923a60
 int socket_address_verify(const SocketAddress *a) _pure_;