]> granicus.if.org Git - sysstat/commitdiff
Fix #256: sar: Don't display duplicate entries in /etc/mtab
authorSebastien GODARD <sysstat@users.noreply.github.com>
Sat, 25 Apr 2020 09:08:40 +0000 (11:08 +0200)
committerSebastien GODARD <sysstat@users.noreply.github.com>
Sat, 25 Apr 2020 09:08:40 +0000 (11:08 +0200)
Signed-off-by: Sebastien GODARD <sysstat@users.noreply.github.com>
rd_stats.c

index 8879bc634baa4e5efbcd1ddc4917b89861ee4030..45b1be7633b874ccbdb8f68e2af3f759de10eb63 100644 (file)
@@ -2503,7 +2503,7 @@ __nr_t read_filesystem(struct stats_filesystem *st_filesystem, __nr_t nr_alloc)
 {
        FILE *fp;
        char line[512], fs_name[MAX_FS_LEN], mountp[256], type[128];
-       int skip = 0, skip_next = 0;
+       int skip = 0, skip_next = 0, fs;
        char *pos = 0, *pos2 = 0;
        __nr_t fs_read = 0;
        struct stats_filesystem *st_filesystem_i;
@@ -2546,12 +2546,13 @@ __nr_t read_filesystem(struct stats_filesystem *st_filesystem, __nr_t nr_alloc)
                        sscanf(line, "%127s", fs_name);
                        /*
                         * And now read the corresponding mount point.
-                        * Read fs name and mount point in two distinct operations.
+                        * Read fs name and mount point in two distinct operations,
+                        * using '@pos + 1' position value for the mount point.
                         * Indeed, if fs name length is greater than 127 chars,
-                        * previous scanf() will read only the first 127 chars, and
-                        * mount point name will be read using the remaining chars
-                        * from the fs name. This will result in a bogus name
-                        * and following statvfs() function will always fail.
+                        * previous scanf() would read only the first 127 chars, and
+                        * mount point name would be read using the remaining chars
+                        * from the fs name. This would result in a bogus name
+                        * and following statvfs() function would always fail.
                         */
                        sscanf(pos + 1, "%255s", mountp);
 
@@ -2565,6 +2566,18 @@ __nr_t read_filesystem(struct stats_filesystem *st_filesystem, __nr_t nr_alloc)
                        if ((__statvfs(mountp, &buf) < 0) || (!buf.f_blocks))
                                continue;
 
+                       /* Check if it's a duplicate entry */
+                       fs = fs_read - 1;
+                       while (fs >= 0) {
+                               st_filesystem_i = st_filesystem + fs;
+                               if (!strcmp(st_filesystem_i->fs_name, fs_name))
+                                       break;
+                               fs--;
+                       }
+                       if (fs >= 0)
+                               /* Duplicate entry found! Ignore current entry */
+                               continue;
+
                        if (fs_read + 1 > nr_alloc) {
                                fs_read = -1;
                                break;