device-mapper-multipath/0138-libmpathcmd-honor-MULTIPATH_SOCKET_NAME-environment-.patch
Benjamin Marzinski ddfd11c918 device-mapper-multipath-0.8.7-36
Add 0128-multipath-tools-move-DEFAULT_SOCKET-definition-into-.patch
Add 0129-multipath-tools-add-helper-mpath_fill_sockaddr__.patch
Add 0130-libmpathutil-add-support-for-Unix-pathname-sockets.patch
Add 0131-libmpathutil-move-systemd_listen_fds-support-into-mu.patch
Add 0132-multipathd-move-uxsock_trigger-to-uxlsnr.c.patch
Add 0133-multipathd-uxlsnr-use-symbolic-values-for-pollfd-ind.patch
Add 0134-multipathd-make-uxsock_listen-take-a-pointer-to-fd.patch
Add 0135-multipathd-allow-receiving-two-socket-fds-from-syste.patch
Add 0136-multipathd-listen-on-pathname-and-abstract-socket-by.patch
Add 0137-libmpathcmd-try-both-abstract-and-pathname-sockets.patch
Add 0138-libmpathcmd-honor-MULTIPATH_SOCKET_NAME-environment-.patch
Add 0139-multipathd-honor-MULTIPATH_SOCKET_NAME-environment-v.patch
  * Fixes RHEL-78758 ("RFE: Enable multipathd to communicate with a
    process in another network namespace")
Resolves: RHEL-78758
2025-03-05 00:15:17 -05:00

54 lines
1.7 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Martin Wilck <mwilck@suse.com>
Date: Wed, 12 Feb 2025 21:17:41 +0100
Subject: [PATCH] libmpathcmd: honor MULTIPATH_SOCKET_NAME environment variable
In systemd installments, users can already override the socket names
that systemd listens on. With this patch, clients using libmpathcmd
can be customized to use a non-standard socket by setting an environment
variable.
Signed-off-by: Martin Wilck <mwilck@suse.com>
Reviewed-by: Benjamin Marzinski <bmarzins@redhat.com>
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
---
libmpathcmd/mpath_cmd.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/libmpathcmd/mpath_cmd.c b/libmpathcmd/mpath_cmd.c
index 267e3dd7..7f805abb 100644
--- a/libmpathcmd/mpath_cmd.c
+++ b/libmpathcmd/mpath_cmd.c
@@ -20,6 +20,7 @@
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
+#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
@@ -104,6 +105,7 @@ int __mpath_connect(int nonblocking)
int flags = 0;
const char *const names[2] = {PATHNAME_SOCKET, ABSTRACT_SOCKET};
int name_idx = 0;
+ const char *env_name = getenv("MULTIPATH_SOCKET_NAME"), *name;
retry:
fd = socket(AF_LOCAL, SOCK_STREAM, 0);
@@ -116,12 +118,13 @@ retry:
(void)fcntl(fd, F_SETFL, flags|O_NONBLOCK);
}
- len = mpath_fill_sockaddr__(&addr, names[name_idx]);
+ name = env_name ? env_name : names[name_idx];
+ len = mpath_fill_sockaddr__(&addr, name);
if (connect(fd, (struct sockaddr *)&addr, len) == -1) {
int err = errno;
close(fd);
- if (++name_idx == 1)
+ if (name != env_name && ++name_idx == 1)
goto retry;
else {
errno = err;