[PATCH v2 10/11] multipathd: exec multipathc in interactive mode

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Martin Wilck <mwilck@xxxxxxxx>

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@xxxxxxxx>
---
 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 19ab2e9..8a56304 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 5a40894..63df643 100644
--- a/multipathd/main.c
+++ b/multipathd/main.c
@@ -3616,7 +3616,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;
@@ -3710,7 +3710,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 571a182..323bd78 100644
--- a/multipathd/multipathc.c
+++ b/multipathd/multipathc.c
@@ -241,14 +241,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

--
dm-devel mailing list
dm-devel@xxxxxxxxxx
https://listman.redhat.com/mailman/listinfo/dm-devel




[Index of Archives]     [DM Crypt]     [Fedora Desktop]     [ATA RAID]     [Fedora Marketing]     [Fedora Packaging]     [Fedora SELinux]     [Yosemite Discussion]     [KDE Users]     [Fedora Docs]

  Powered by Linux