]> granicus.if.org Git - sysstat/commitdiff
Handle octal codes in filesystems mount point names
authorSebastien GODARD <sysstat@orange.fr.fake>
Thu, 30 May 2013 20:26:18 +0000 (22:26 +0200)
committerSebastien GODARD <sysstat@orange.fr.fake>
Thu, 30 May 2013 20:26:18 +0000 (22:26 +0200)
sar -F was unable to get statistics about filesystems whose mount points
(as given by /etc/mtab file) had octal codes in their names.
So now sar replaces those octal codes with their corresponding
characters before trying to collect stats about them.

count.c
rd_stats.c
rd_stats.h

diff --git a/count.c b/count.c
index 75f0d5f9eda37835ddd73eb149bd9cff903ffa9e..d14fe794e0649dc083597c3e20c8d16c3c8dc8e9 100644 (file)
--- a/count.c
+++ b/count.c
@@ -458,6 +458,9 @@ int get_filesystem_nr(void)
                        /* Read filesystem name and mount point */
                        sscanf(line, "%71s %127s", fs_name, mountp);
                        
+                       /* Replace octal codes */
+                       oct2chr(mountp);
+                       
                        /* Check that total size is not null */
                        if (statfs(mountp, &buf) < 0)
                                continue;
index d8fdf774ed75bbb8775aa6235cadfe5eb42f1f3b..d03880ed47b02c2e11c9afd5730a331629b86613 100644 (file)
 #define _(string) (string)
 #endif
 
+/*
+ ***************************************************************************
+ * Replace octal codes in string with their corresponding characters.
+ *
+ * IN:
+ * str         String to parse.
+ *
+ * OUT:
+ * @str                String with octal codes replaced with characters.
+ ***************************************************************************
+ */
+void oct2chr(char *str)
+{
+       int i = 0;
+       int j, len;
+       
+       len = strlen(str);
+       
+       while (i < len - 3) {
+               if ((str[i] == '\\') &&
+                   (str[i + 1] >= '0') && (str[i + 1] <= '3') &&
+                   (str[i + 2] >= '0') && (str[i + 2] <= '7') &&
+                   (str[i + 3] >= '0') && (str[i + 3] <= '7')) {
+                       /* Octal code found */
+                       str[i] = (str[i + 1] - 48) * 64 +
+                                (str[i + 2] - 48) * 8  +
+                                (str[i + 3] - 48);
+                       for (j = i + 4; j <= len; j++) {
+                               str[j - 3] = str[j];
+                       }
+                       len -= 3;
+               }
+               i++;
+       }
+}
+
 /*
  ***************************************************************************
  * Read CPU statistics and machine uptime.
@@ -1891,6 +1927,9 @@ void read_filesystem(struct stats_filesystem *st_filesystem, int nbr)
                        /* Read current filesystem name and mount point */
                        sscanf(line, "%71s %127s", fs_name, mountp);
                        
+                       /* Replace octal codes */
+                       oct2chr(mountp);
+                       
                        if ((statfs(mountp, &buf) < 0) || (!buf.f_blocks))
                                continue;
                        
index cc2984433386ca06c0d3f0bea3e3f6680d6e22ff..0c65b80b31a9b5beaea3a1bbaee6690b997be276 100644 (file)
@@ -540,6 +540,8 @@ struct stats_filesystem {
  ***************************************************************************
  */
 
+extern void
+       oct2chr(char *);
 extern void
        read_stat_cpu(struct stats_cpu *, int,
                      unsigned long long *, unsigned long long *);