diff options
author | Costa Tsaousis (ktsaou) <costa@tsaousis.gr> | 2017-01-20 22:59:51 +0200 |
---|---|---|
committer | Costa Tsaousis (ktsaou) <costa@tsaousis.gr> | 2017-01-20 22:59:51 +0200 |
commit | 655715342478c5da5d43c5a8e619bd214585db4d (patch) | |
tree | 9cd97e4d979c85308167a34cd0635ea10c67abb1 /src/proc_net_snmp.c | |
parent | c41fea03077803977dec24d94a26c5425da07806 (diff) |
replace strcmp() with strsame() and procfile improvements
Diffstat (limited to 'src/proc_net_snmp.c')
-rw-r--r-- | src/proc_net_snmp.c | 67 |
1 files changed, 32 insertions, 35 deletions
diff --git a/src/proc_net_snmp.c b/src/proc_net_snmp.c index 821f670cb4..ffcd282ac3 100644 --- a/src/proc_net_snmp.c +++ b/src/proc_net_snmp.c @@ -1,9 +1,6 @@ #include "common.h" #define RRD_TYPE_NET_SNMP "ipv4" -#define RRD_TYPE_NET_SNMP_LEN strlen(RRD_TYPE_NET_SNMP) - -#define NETSTAT_PRESENT 0x00000001 struct netstat_columns { char *name; @@ -168,19 +165,19 @@ static unsigned long long *netstat_columns_find(struct netstat_columns *nc, cons uint32_t i, hash = simple_hash(name); for(i = 0; nc[i].name ;i++) - if(unlikely(nc[i].hash == hash && !strcmp(nc[i].name, name))) + if(unlikely(nc[i].hash == hash && !strsame(nc[i].name, name))) return &nc[i].value; fatal("Cannot find key '%s' in /proc/net/snmp internal array.", name); } -static void parse_line_pair(procfile *ff, struct netstat_columns *nc, uint32_t header_line, uint32_t values_line) { - uint32_t hwords = procfile_linewords(ff, header_line); - uint32_t vwords = procfile_linewords(ff, values_line); - uint32_t w, i; +static void parse_line_pair(procfile *ff, struct netstat_columns *nc, size_t header_line, size_t values_line) { + size_t hwords = procfile_linewords(ff, header_line); + size_t vwords = procfile_linewords(ff, values_line); + size_t w, i; if(unlikely(vwords > hwords)) { - error("File /proc/net/snmp on header line %u has %u words, but on value line %u has %u words.", header_line, hwords, values_line, vwords); + error("File /proc/net/snmp on header line %zu has %zu words, but on value line %zu has %zu words.", header_line, hwords, values_line, vwords); vwords = hwords; } @@ -189,7 +186,7 @@ static void parse_line_pair(procfile *ff, struct netstat_columns *nc, uint32_t h uint32_t hash = simple_hash(key); for(i = 0 ; nc[i].name ;i++) { - if(unlikely(hash == nc[i].hash && !strcmp(key, nc[i].name))) { + if(unlikely(hash == nc[i].hash && !strsame(key, nc[i].name))) { nc[i].value = str2ull(procfile_lineword(ff, values_line, w)); break; } @@ -366,8 +363,8 @@ int do_proc_net_snmp(int update_every, usec_t dt) { ff = procfile_readall(ff); if(unlikely(!ff)) return 0; // we return 0, so that we will retry to open it next time - uint32_t lines = procfile_lines(ff), l; - uint32_t words; + size_t lines = procfile_lines(ff), l; + size_t words; RRDSET *st; @@ -375,17 +372,17 @@ int do_proc_net_snmp(int update_every, usec_t dt) { char *key = procfile_lineword(ff, l, 0); uint32_t hash = simple_hash(key); - if(unlikely(hash == hash_ip && strcmp(key, "Ip") == 0)) { - uint32_t h = l++; + if(unlikely(hash == hash_ip && strsame(key, "Ip") == 0)) { + size_t h = l++; - if(strcmp(procfile_lineword(ff, l, 0), "Ip") != 0) { + if(strsame(procfile_lineword(ff, l, 0), "Ip") != 0) { error("Cannot read Ip line from /proc/net/snmp."); break; } words = procfile_linewords(ff, l); if(words < 3) { - error("Cannot read /proc/net/snmp Ip line. Expected 3+ params, read %u.", words); + error("Cannot read /proc/net/snmp Ip line. Expected 3+ params, read %zu.", words); continue; } @@ -481,17 +478,17 @@ int do_proc_net_snmp(int update_every, usec_t dt) { rrdset_done(st); } } - else if(unlikely(hash == hash_icmp && strcmp(key, "Icmp") == 0)) { - uint32_t h = l++; + else if(unlikely(hash == hash_icmp && strsame(key, "Icmp") == 0)) { + size_t h = l++; - if(strcmp(procfile_lineword(ff, l, 0), "Icmp") != 0) { + if(strsame(procfile_lineword(ff, l, 0), "Icmp") != 0) { error("Cannot read Icmp line from /proc/net/snmp."); break; } words = procfile_linewords(ff, l); if(words < 3) { - error("Cannot read /proc/net/snmp Icmp line. Expected 3+ params, read %u.", words); + error("Cannot read /proc/net/snmp Icmp line. Expected 3+ params, read %zu.", words); continue; } @@ -531,10 +528,10 @@ int do_proc_net_snmp(int update_every, usec_t dt) { rrdset_done(st); } } - else if(unlikely(hash == hash_icmpmsg && strcmp(key, "IcmpMsg") == 0)) { - uint32_t h = l++; + else if(unlikely(hash == hash_icmpmsg && strsame(key, "IcmpMsg") == 0)) { + size_t h = l++; - if(strcmp(procfile_lineword(ff, l, 0), "IcmpMsg") != 0) { + if(strsame(procfile_lineword(ff, l, 0), "IcmpMsg") != 0) { error("Cannot read IcmpMsg line from /proc/net/snmp."); break; } @@ -561,17 +558,17 @@ int do_proc_net_snmp(int update_every, usec_t dt) { rrdset_done(st); } } - else if(unlikely(hash == hash_tcp && strcmp(key, "Tcp") == 0)) { - uint32_t h = l++; + else if(unlikely(hash == hash_tcp && strsame(key, "Tcp") == 0)) { + size_t h = l++; - if(strcmp(procfile_lineword(ff, l, 0), "Tcp") != 0) { + if(strsame(procfile_lineword(ff, l, 0), "Tcp") != 0) { error("Cannot read Tcp line from /proc/net/snmp."); break; } words = procfile_linewords(ff, l); if(words < 3) { - error("Cannot read /proc/net/snmp Tcp line. Expected 3+ params, read %u.", words); + error("Cannot read /proc/net/snmp Tcp line. Expected 3+ params, read %zu.", words); continue; } @@ -654,17 +651,17 @@ int do_proc_net_snmp(int update_every, usec_t dt) { rrdset_done(st); } } - else if(unlikely(hash == hash_udp && strcmp(key, "Udp") == 0)) { - uint32_t h = l++; + else if(unlikely(hash == hash_udp && strsame(key, "Udp") == 0)) { + size_t h = l++; - if(strcmp(procfile_lineword(ff, l, 0), "Udp") != 0) { + if(strsame(procfile_lineword(ff, l, 0), "Udp") != 0) { error("Cannot read Udp line from /proc/net/snmp."); break; } words = procfile_linewords(ff, l); if(words < 3) { - error("Cannot read /proc/net/snmp Udp line. Expected 3+ params, read %u.", words); + error("Cannot read /proc/net/snmp Udp line. Expected 3+ params, read %zu.", words); continue; } @@ -714,17 +711,17 @@ int do_proc_net_snmp(int update_every, usec_t dt) { rrdset_done(st); } } - else if(unlikely(hash == hash_udplite && strcmp(key, "UdpLite") == 0)) { - uint32_t h = l++; + else if(unlikely(hash == hash_udplite && strsame(key, "UdpLite") == 0)) { + size_t h = l++; - if(strcmp(procfile_lineword(ff, l, 0), "UdpLite") != 0) { + if(strsame(procfile_lineword(ff, l, 0), "UdpLite") != 0) { error("Cannot read UdpLite line from /proc/net/snmp."); break; } words = procfile_linewords(ff, l); if(words < 3) { - error("Cannot read /proc/net/snmp UdpLite line. Expected 3+ params, read %u.", words); + error("Cannot read /proc/net/snmp UdpLite line. Expected 3+ params, read %zu.", words); continue; } |