[dm-devel] [RFC PATCH 9/9] multipathd: exec multipathc in interactive mode

mwilck at suse.com mwilck at suse.com
Fri Aug 19 23:12:22 UTC 2022


From: Martin Wilck <mwilck at suse.com>

A previous patch disabled interactive mode in multipathd, because
uxclnt() would return immediately without an input command

With this patch, we reinstate interactive mode for "multipath -k",
by just exec()ing the multipathc client.

Signed-off-by: Martin Wilck <mwilck at suse.com>
---
 multipathd/Makefile     |  3 ++-
 multipathd/main.c       | 15 +++++++++++++--
 multipathd/multipathc.c | 25 +++++++++++++++++++++----
 3 files changed, 36 insertions(+), 7 deletions(-)

diff --git a/multipathd/Makefile b/multipathd/Makefile
index 6f4bc59..22fbe22 100644
--- a/multipathd/Makefile
+++ b/multipathd/Makefile
@@ -17,7 +17,8 @@ endif
 
 CPPFLAGS += -I$(multipathdir) -I$(mpathutildir) -I$(mpathpersistdir) -I$(mpathcmddir) -I$(thirdpartydir) \
 	$(shell $(PKGCONFIG) --modversion liburcu 2>/dev/null | \
-		awk -F. '{ printf("-DURCU_VERSION=0x%06x", 256 * ( 256 * $$1 + $$2) + $$3); }')
+		awk -F. '{ printf("-DURCU_VERSION=0x%06x", 256 * ( 256 * $$1 + $$2) + $$3); }') \
+	-DBINDIR='"$(bindir)"'
 CFLAGS += $(BIN_CFLAGS)
 LDFLAGS += $(BIN_LDFLAGS)
 
diff --git a/multipathd/main.c b/multipathd/main.c
index 7d127db..9c318fd 100644
--- a/multipathd/main.c
+++ b/multipathd/main.c
@@ -3575,7 +3575,7 @@ main (int argc, char *argv[])
 	extern char *optarg;
 	extern int optind;
 	int arg;
-	int err;
+	int err = 0;
 	int foreground = 0;
 	struct config *conf;
 	char *opt_k_arg = NULL;
@@ -3669,7 +3669,18 @@ main (int argc, char *argv[])
 			}
 			c += snprintf(c, s + CMDSIZE - c, "\n");
 		}
-		err = uxclnt(s, uxsock_timeout + 100);
+		if (!s) {
+			char tmo_buf[16];
+
+			snprintf(tmo_buf, sizeof(tmo_buf), "%d",
+				 uxsock_timeout + 100);
+			if (execl(BINDIR "/multipathc", "multipathc",
+				  tmo_buf, NULL) == -1) {
+				condlog(0, "ERROR: failed to execute multipathc");
+				err = 1;
+			}
+		} else
+			err = uxclnt(s, uxsock_timeout + 100);
 		free_config(conf);
 		return err;
 	}
diff --git a/multipathd/multipathc.c b/multipathd/multipathc.c
index bd5684b..1e211a9 100644
--- a/multipathd/multipathc.c
+++ b/multipathd/multipathc.c
@@ -237,14 +237,31 @@ static void process(int fd, unsigned int timeout)
 	}
 }
 
-int main (void)
+int main (int argc, const char * const argv[])
 {
-	int fd = mpath_connect();
+	int fd;
+	int tmo = DEFAULT_REPLY_TIMEOUT + 100;
+	char *ep;
 
-	if (fd == -1)
+	if (argc > 2) {
+		fprintf(stderr, "Usage: %s [timeout]\n", argv[0]);
 		return 1;
+	}
+	if (argc == 2) {
+		tmo = strtol(argv[1], &ep, 10);
+		if (*argv[1] == '\0' || *ep != '\0') {
+			fprintf(stderr, "ERROR: invalid timeout value\n");
+			return 1;
+		}
+	}
 
-	process(fd, DEFAULT_REPLY_TIMEOUT + 100);
+	fd = mpath_connect();
+	if (fd == -1) {
+		fprintf(stderr, "ERROR: failed to connect to multipathd\n");
+		return 1;
+	}
+
+	process(fd, tmo);
 	mpath_disconnect(fd);
 	return 0;
 }
-- 
2.37.1



More information about the dm-devel mailing list