[dm-devel] [PATCH 3/4] multipath-tools: fix compilation errors on 32-bit musl

mwilck at suse.com mwilck at suse.com
Thu Feb 11 23:46:49 UTC 2021


From: Martin Wilck <mwilck at suse.com>

gcc on alpine Linux/i386 throws errors because the "tv_sec" element
of struct timespec is a time_t, which is a "long long" in that
environment. In general, time_t is signed. As we only use CLOCK_MONOTONIC,
which starts at boot time, a cast to long should be no problem, even
in 32bit environments.

Signed-off-by: Martin Wilck <mwilck at suse.com>
---
 multipath/main.c    |  2 +-
 multipathd/main.c   | 16 ++++++++--------
 multipathd/uxlsnr.c |  4 ++--
 3 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/multipath/main.c b/multipath/main.c
index 9ac4286..3f97582 100644
--- a/multipath/main.c
+++ b/multipath/main.c
@@ -417,7 +417,7 @@ static int print_cmd_valid(int k, const vector pathvec,
 		wait = find_multipaths_check_timeout(pp, 0, &until);
 	if (wait == FIND_MULTIPATHS_WAITING)
 		printf("FIND_MULTIPATHS_WAIT_UNTIL=\"%ld.%06ld\"\n",
-			       until.tv_sec, until.tv_nsec/1000);
+		       (long)until.tv_sec, until.tv_nsec/1000);
 	else if (wait == FIND_MULTIPATHS_WAIT_DONE)
 		printf("FIND_MULTIPATHS_WAIT_UNTIL=\"0\"\n");
 	printf("DM_MULTIPATH_DEVICE_PATH=\"%d\"\n",
diff --git a/multipathd/main.c b/multipathd/main.c
index 1967984..5316643 100644
--- a/multipathd/main.c
+++ b/multipathd/main.c
@@ -2408,8 +2408,8 @@ checkerloop (void *ap)
 		get_monotonic_time(&start_time);
 		if (start_time.tv_sec && last_time.tv_sec) {
 			timespecsub(&start_time, &last_time, &diff_time);
-			condlog(4, "tick (%lu.%06lu secs)",
-				diff_time.tv_sec, diff_time.tv_nsec / 1000);
+			condlog(4, "tick (%ld.%06lu secs)",
+				(long)diff_time.tv_sec, diff_time.tv_nsec / 1000);
 			last_time = start_time;
 			ticks = diff_time.tv_sec;
 		} else {
@@ -2470,18 +2470,18 @@ checkerloop (void *ap)
 			if (num_paths) {
 				unsigned int max_checkint;
 
-				condlog(4, "checked %d path%s in %lu.%06lu secs",
+				condlog(4, "checked %d path%s in %ld.%06lu secs",
 					num_paths, num_paths > 1 ? "s" : "",
-					diff_time.tv_sec,
+					(long)diff_time.tv_sec,
 					diff_time.tv_nsec / 1000);
 				conf = get_multipath_config();
 				max_checkint = conf->max_checkint;
 				put_multipath_config(conf);
 				if (diff_time.tv_sec > (time_t)max_checkint)
 					condlog(1, "path checkers took longer "
-						"than %lu seconds, consider "
+						"than %ld seconds, consider "
 						"increasing max_polling_interval",
-						diff_time.tv_sec);
+						(long)diff_time.tv_sec);
 			}
 		}
 
@@ -2507,8 +2507,8 @@ checkerloop (void *ap)
 			} else
 				diff_time.tv_sec = 1;
 
-			condlog(3, "waiting for %lu.%06lu secs",
-				diff_time.tv_sec,
+			condlog(3, "waiting for %ld.%06lu secs",
+				(long)diff_time.tv_sec,
 				diff_time.tv_nsec / 1000);
 			if (nanosleep(&diff_time, NULL) != 0) {
 				condlog(3, "nanosleep failed with error %d",
diff --git a/multipathd/uxlsnr.c b/multipathd/uxlsnr.c
index cd462b6..dbee0d6 100644
--- a/multipathd/uxlsnr.c
+++ b/multipathd/uxlsnr.c
@@ -154,8 +154,8 @@ static void check_timeout(struct timespec start_time, char *inbuf,
 			diff_time.tv_nsec / (1000 * 1000);
 		if (msecs > timeout)
 			condlog(2, "cli cmd '%s' timeout reached "
-				"after %lu.%06lu secs", inbuf,
-				diff_time.tv_sec, diff_time.tv_nsec / 1000);
+				"after %ld.%06lu secs", inbuf,
+				(long)diff_time.tv_sec, diff_time.tv_nsec / 1000);
 	}
 }
 
-- 
2.29.2





More information about the dm-devel mailing list