The path of UNIX server connections should be sent as an argument to
the external-check command, to mimic how it behaves with IPv4 and v6
server connections, and UNIX proxy listeners. The port is set to an
empty string (existing behavior) instead of "NOT_USED" (to mimic
the proxy_port argument) to keep current functionality in that case.

Due to the minimal nature of this change, it is likely trivially
backported to stable versions which would allow users of the stable
versions to use external-check with UNIX socket server connections.
---
 doc/configuration.txt |  5 +++++
 src/checks.c          | 19 +++++++++++++++++--
 2 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/doc/configuration.txt b/doc/configuration.txt
index 0da753a6..5da748b9 100644
--- a/doc/configuration.txt
+++ b/doc/configuration.txt
@@ -7466,6 +7466,11 @@ external-check command <command>
   possible to determine a listener, and both <proxy_address> and <proxy_port>
   will have the string value "NOT_USED".
 
+  The <server_address> and <server_port> correspond to the configured server
+  address and port in the "backend" section. In the case of a UNIX socket
+  server connection, the <server_address> will be the path of the socket and
+  the <server_port> will be empty.
+
   Some values are also provided through environment variables.
 
   Environment variables :
diff --git a/src/checks.c b/src/checks.c
index 308b4b72..80266535 100644
--- a/src/checks.c
+++ b/src/checks.c
@@ -1891,8 +1891,23 @@ static int prepare_external_check(struct check *check)
                goto err;
        }
 
-       addr_to_str(&s->addr, buf, sizeof(buf));
-       check->argv[3] = strdup(buf);
+       // Make sure to send the unix socket address for the server to the 
external check command
+       if (s->addr.ss_family == AF_INET || s->addr.ss_family == AF_INET6) {
+               addr_to_str(&s->addr, buf, sizeof(buf));
+               check->argv[3] = strdup(buf);
+       }
+       else if (s->addr.ss_family == AF_UNIX) {
+               const struct sockaddr_un *un;
+
+               un = (struct sockaddr_un *)&s->addr;
+               check->argv[3] = strdup(un->sun_path);
+               // Fall through to setting the port to "" to keep old 
functionality
+               // instead of setting it to "NOT_USED" to mimic proxy_port.
+       }
+       else {
+               ha_alert("Starting [%s:%s] check: unsupported server address 
family.\n", px->id, s->id);
+               goto err;
+       }
 
        if (s->addr.ss_family == AF_INET || s->addr.ss_family == AF_INET6)
                snprintf(buf, sizeof(buf), "%u", s->svc_port);
-- 
2.21.0


Reply via email to