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

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