When connecting to the multipathd socket, try the pathname socket
first, then the abstract socket. Fail only if both connection attempts
fail.

Signed-off-by: Martin Wilck <mwi...@suse.com>
---
 libmpathcmd/mpath_cmd.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/libmpathcmd/mpath_cmd.c b/libmpathcmd/mpath_cmd.c
index c7cf954..ba5bb31 100644
--- a/libmpathcmd/mpath_cmd.c
+++ b/libmpathcmd/mpath_cmd.c
@@ -102,7 +102,10 @@ int mpath_connect__(int nonblocking)
        size_t len;
        struct sockaddr_un addr;
        int flags = 0;
+       const char *names[2] = {PATHNAME_SOCKET, ABSTRACT_SOCKET};
+       int name_idx = 0;
 
+retry:
        fd = socket(AF_LOCAL, SOCK_STREAM, 0);
        if (fd == -1)
                return -1;
@@ -113,13 +116,17 @@ int mpath_connect__(int nonblocking)
                        (void)fcntl(fd, F_SETFL, flags|O_NONBLOCK);
        }
 
-       len = mpath_fill_sockaddr__(&addr, ABSTRACT_SOCKET);
+       len = mpath_fill_sockaddr__(&addr, names[name_idx]);
        if (connect(fd, (struct sockaddr *)&addr, len) == -1) {
                int err = errno;
 
                close(fd);
-               errno = err;
-               return -1;
+               if (err == ECONNREFUSED && ++name_idx == 1)
+                       goto retry;
+               else {
+                       errno = err;
+                       return -1;
+               }
        }
 
        if (nonblocking && flags != -1)
-- 
2.48.1


Reply via email to