Blame SOURCES/0015-Fix-issue-48-sar-skips-long-filesystem-names.patch

72abff
From f5b70d8a0a4439b9745680a2e4ab433e76f154d5 Mon Sep 17 00:00:00 2001
72abff
From: Sebastien GODARD <sysstat@users.noreply.github.com>
72abff
Date: Fri, 20 Mar 2015 18:23:11 +0100
72abff
Subject: [PATCH] Fix issue #48: sar skips long filesystem names
72abff
72abff
If a filesystem had more than MAX_FS_LEN characters in length, sar
72abff
didn't display it.
72abff
This patch fixes the problem.
72abff
72abff
Signed-off-by: Sebastien GODARD <sysstat@users.noreply.github.com>
72abff
(cherry picked from commit a82d6abce8ff35a5bf0d060456ca653f722a9f73)
72abff
---
72abff
 rd_stats.c | 24 +++++++++++++++++++-----
72abff
 1 file changed, 19 insertions(+), 5 deletions(-)
72abff
72abff
diff --git a/rd_stats.c b/rd_stats.c
72abff
index 9f7fc37..eff0348 100644
72abff
--- a/rd_stats.c
72abff
+++ b/rd_stats.c
72abff
@@ -1915,7 +1915,7 @@ void read_bus_usb_dev(struct stats_pwr_usb *st_pwr_usb, int nbr)
72abff
 void read_filesystem(struct stats_filesystem *st_filesystem, int nbr)
72abff
 {
72abff
 	FILE *fp;
72abff
-	char line[256], fs_name[MAX_FS_LEN], mountp[128];
72abff
+	char line[512], fs_name[MAX_FS_LEN], mountp[256];
72abff
 	int fs = 0;
72abff
 	struct stats_filesystem *st_filesystem_i;
72abff
 	struct statvfs buf;
72abff
@@ -1925,13 +1925,27 @@ void read_filesystem(struct stats_filesystem *st_filesystem, int nbr)
72abff
 
72abff
 	while ((fgets(line, 256, fp) != NULL) && (fs < nbr)) {
72abff
 		if (line[0] == '/') {
72abff
-			
72abff
-			/* Read current filesystem name and mount point */
72abff
-			sscanf(line, "%71s %127s", fs_name, mountp);
72abff
-			
72abff
+
72abff
+			/* Read current filesystem name */
72abff
+			sscanf(line, "%127s", fs_name);
72abff
+			/*
72abff
+			 * And now read the corresponding mount point.
72abff
+			 * Read fs name and mount point in two distinct operations.
72abff
+			 * Indeed, if fs name length is greater than 127 chars,
72abff
+			 * previous scanf() will read only the first 127 chars, and
72abff
+			 * mount point name will be read using the remaining chars
72abff
+			 * from the fs name. This will result in a bogus name
72abff
+			 * and following statvfs() function will always fail.
72abff
+			 */
72abff
+			sscanf(strchr(line, ' ') + 1, "%255s", mountp);
72abff
+
72abff
 			/* Replace octal codes */
72abff
 			oct2chr(mountp);
72abff
 
72abff
+			/*
72abff
+			 * It's important to have read the whole mount point name
72abff
+			 * for statvfs() to work properly (see above).
72abff
+			 */
72abff
 			if ((statvfs(mountp, &buf) < 0) || (!buf.f_blocks))
72abff
 				continue;
72abff
 			
72abff
-- 
72abff
2.14.3
72abff