summaryrefslogtreecommitdiff
path: root/ifpps.c
diff options
context:
space:
mode:
authorDaniel Borkmann <dborkman@redhat.com>2013-05-27 11:21:03 -0400
committerDaniel Borkmann <dborkman@redhat.com>2013-05-27 17:23:27 +0200
commit4d1e7a9f186e32eb701ccedeefd677f4a068552b (patch)
tree91fee742f397b33c7b5eb95c3c8eef900e6c6669 /ifpps.c
parent130af2b5b219b7ea02f27fd41c87cb00271f3c3e (diff)
ifpps: fix bug_on trigger when parsing irq number
When parsing irq numbers on e.g. 24 CPU machines, procfs lines can get very long, so our static temporary buffer size will fail here with: Assertion `!(stats->irq_nr == 0)' failed. So allocate it relative to the CPU number. Signed-off-by: Daniel Borkmann <dborkman@redhat.com>
Diffstat (limited to 'ifpps.c')
-rw-r--r--ifpps.c28
1 files changed, 18 insertions, 10 deletions
diff --git a/ifpps.c b/ifpps.c
index 27969ee..e608885 100644
--- a/ifpps.c
+++ b/ifpps.c
@@ -242,7 +242,8 @@ static int stats_proc_net_dev(const char *ifname, struct ifstat *stats)
static int stats_proc_interrupts(char *ifname, struct ifstat *stats)
{
int ret = -EINVAL, i, cpus, try = 0;
- char *ptr, buff[256];
+ char *ptr, *buff;
+ size_t buff_len;
struct ethtool_drvinfo drvinf;
FILE *fp;
@@ -251,12 +252,14 @@ static int stats_proc_interrupts(char *ifname, struct ifstat *stats)
panic("Cannot open /proc/interrupts!\n");
cpus = get_number_cpus();
+ buff_len = cpus * 128;
+ buff = xmalloc(buff_len);
retry:
fseek(fp, 0, SEEK_SET);
- memset(buff, 0, sizeof(buff));
+ memset(buff, 0, buff_len);
- while (fgets(buff, sizeof(buff), fp) != NULL) {
- buff[sizeof(buff) - 1] = 0;
+ while (fgets(buff, buff_len, fp) != NULL) {
+ buff[buff_len - 1] = 0;
ptr = buff;
if (strstr(buff, ifname) == NULL)
@@ -275,7 +278,7 @@ retry:
}
}
- memset(buff, 0, sizeof(buff));
+ memset(buff, 0, buff_len);
}
if (ret == -EINVAL && try == 0) {
@@ -289,6 +292,7 @@ retry:
goto retry;
}
done:
+ xfree(buff);
fclose(fp);
return ret;
}
@@ -296,7 +300,8 @@ done:
static int stats_proc_softirqs(struct ifstat *stats)
{
int i, cpus;
- char *ptr, buff[256];
+ char *ptr, *buff;
+ size_t buff_len;
FILE *fp;
enum {
softirqs_net_rx,
@@ -308,11 +313,13 @@ static int stats_proc_softirqs(struct ifstat *stats)
panic("Cannot open /proc/softirqs!\n");
cpus = get_number_cpus();
+ buff_len = cpus * 128;
+ buff = xmalloc(buff_len);
- memset(buff, 0, sizeof(buff));
+ memset(buff, 0, buff_len);
- while (fgets(buff, sizeof(buff), fp) != NULL) {
- buff[sizeof(buff) - 1] = 0;
+ while (fgets(buff, buff_len, fp) != NULL) {
+ buff[buff_len - 1] = 0;
if ((ptr = strstr(buff, "NET_TX:")))
net_type = softirqs_net_tx;
@@ -332,9 +339,10 @@ static int stats_proc_softirqs(struct ifstat *stats)
}
}
- memset(buff, 0, sizeof(buff));
+ memset(buff, 0, buff_len);
}
+ xfree(buff);
fclose(fp);
return 0;
}