From: Sebastien Godard Date: Sun, 6 Feb 2011 09:09:17 +0000 (+0100) Subject: Fix a problem with long NFS and CIFS share names in cifsiostat and X-Git-Tag: v10.0.0~7 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ddf74fa6af0d9968d2ddde485c1401425a02eb73;p=sysstat Fix a problem with long NFS and CIFS share names in cifsiostat and nfsiostat. Mail from Ivana Varekova (varekova@redhat.com) 02/02/2011 Hello, I'm sending 6 patches - 3 for nfsiostat and 3 for cifsiostat nfsiostat: nfsiostat3.patch - fix the problem with long nfs shares names (...) cifsiostat: cifsiostat3.patch - fix the problem with long cifs shares names (...) --- diff --git a/CHANGES b/CHANGES index e5525c3..64e0986 100644 --- a/CHANGES +++ b/CHANGES @@ -1,6 +1,8 @@ Changes: xxxx/xx/xx: Version 10.0.0 - Sebastien Godard (sysstat orange.fr) + * [Ivana Varekova]: Fix a problem with long NFS and CIFS share + names in cifsiostat and nfsiostat. * [Ivana Varekova]: Check calloc() return value in cifsiostat and nfsiostat. * [Jan Kaluza]: Added --debuginfo option to cifsiostat and diff --git a/cifsiostat.c b/cifsiostat.c index 5d9f127..7e66f10 100644 --- a/cifsiostat.c +++ b/cifsiostat.c @@ -287,13 +287,13 @@ void read_cifs_stat(int curr) if ((fp = fopen(CIFSSTATS, "r")) == NULL) return; - sprintf(aux, "%%%ds %%10s %%10s", - MAX_NAME_LEN < 200 ? MAX_NAME_LEN : 200); + sprintf(aux, "%%*d) %%%ds", + MAX_NAME_LEN < 200 ? MAX_NAME_LEN - 1 : 200); while (fgets(line, 256, fp) != NULL) { /* Read CIFS directory name */ - if (isdigit((unsigned char) line[0]) && sscanf(line, "%*d) %s", name_tmp) == 1) { + if (isdigit((unsigned char) line[0]) && sscanf(line, aux , name_tmp) == 1) { if (start) { save_stats(cifs_name, curr, &scifs); } diff --git a/nfsiostat.c b/nfsiostat.c index 4222bd3..48d579b 100644 --- a/nfsiostat.c +++ b/nfsiostat.c @@ -307,6 +307,7 @@ void read_nfs_stat(int curr) int sw = 0; char line[256]; char *xprt_line; + char *mount_part; char nfs_name[MAX_NAME_LEN]; char mount[10], on[10], prefix[10], aux[32]; char operation[16]; @@ -319,7 +320,7 @@ void read_nfs_stat(int curr) if ((fp = fopen(NFSMOUNTSTATS, "r")) == NULL) return; - sprintf(aux, "%%%ds %%10s %%10s", + sprintf(aux, "%%%ds", MAX_NAME_LEN < 200 ? MAX_NAME_LEN : 200); while (fgets(line, 256, fp) != NULL) { @@ -327,9 +328,13 @@ void read_nfs_stat(int curr) /* Read NFS directory name */ if (!strncmp(line, "device", 6)) { sw = 0; - sscanf(line + 6, aux, nfs_name, mount, on); - if ((!strncmp(mount, "mounted", 7)) && (!strncmp(on, "on", 2))) { - sw = 1; + sscanf(line + 6, aux, nfs_name); + mount_part = strchr(line + 7, ' '); + if (mount_part != NULL) { + sscanf(mount_part, "%10s %10s", mount, on); + if ((!strncmp(mount, "mounted", 7)) && (!strncmp(on, "on", 2))) { + sw = 1; + } } }