From 655715342478c5da5d43c5a8e619bd214585db4d Mon Sep 17 00:00:00 2001 From: "Costa Tsaousis (ktsaou)" Date: Fri, 20 Jan 2017 22:59:51 +0200 Subject: [PATCH] replace strcmp() with strsame() and procfile improvements --- src/adaptive_resortable_list.c | 2 +- src/adaptive_resortable_list.h | 2 +- src/appconfig.c | 28 ++-- src/apps_plugin.c | 42 +++--- src/backends.c | 10 +- src/dictionary.c | 2 +- src/eval.c | 22 +-- src/freebsd_sysctl.c | 10 +- src/health.c | 40 +++--- src/inlined.h | 6 + src/log.c | 10 +- src/macos_fw.c | 10 +- src/main.c | 22 +-- src/plugin_tc.c | 56 ++++---- src/plugins_d.c | 26 ++-- src/proc_diskstats.c | 6 +- src/proc_interrupts.c | 18 +-- src/proc_meminfo.c | 88 ++++++------ src/proc_net_dev.c | 6 +- src/proc_net_ip_vs_stats.c | 1 - src/proc_net_netstat.c | 34 ++--- src/proc_net_rpc_nfs.c | 20 +-- src/proc_net_rpc_nfsd.c | 42 +++--- src/proc_net_snmp.c | 67 +++++----- src/proc_net_snmp6.c | 191 +++++++++++++------------- src/proc_net_softnet_stat.c | 15 ++- src/proc_net_stat_conntrack.c | 6 +- src/proc_net_stat_synproxy.c | 2 +- src/proc_self_mountinfo.c | 60 ++++----- src/proc_softirqs.c | 12 +- src/proc_stat.c | 18 +-- src/proc_vmstat.c | 6 +- src/procfile.c | 100 ++++++-------- src/procfile.h | 24 ++-- src/registry.c | 2 +- src/registry_internals.c | 8 +- src/registry_person.c | 4 +- src/registry_url.c | 2 +- src/rrd.c | 42 +++--- src/rrd2json.c | 2 +- src/simple_pattern.c | 4 +- src/sys_fs_cgroup.c | 96 ++------------ src/web_buffer.c | 2 +- src/web_buffer_svg.c | 36 ++--- src/web_client.c | 236 ++++++++++++++++----------------- src/web_server.c | 2 +- 46 files changed, 673 insertions(+), 767 deletions(-) diff --git a/src/adaptive_resortable_list.c b/src/adaptive_resortable_list.c index 3f7f7c19..3408b626 100644 --- a/src/adaptive_resortable_list.c +++ b/src/adaptive_resortable_list.c @@ -128,7 +128,7 @@ int arl_find_or_create_and_relink(ARL_BASE *base, const char *s, uint32_t hash, // find if it already exists in the data for(e = base->head; e ; e = e->next) - if(e->hash == hash && !strcmp(e->name, s)) + if(e->hash == hash && !strsame(e->name, s)) break; #ifdef NETDATA_INTERNAL_CHECKS diff --git a/src/adaptive_resortable_list.h b/src/adaptive_resortable_list.h index 157e1f5e..f27cccfd 100644 --- a/src/adaptive_resortable_list.h +++ b/src/adaptive_resortable_list.h @@ -118,7 +118,7 @@ static inline int arl_check(ARL_BASE *base, const char *keyword, const char *val uint32_t hash = simple_hash(keyword); // it should be the first entry (pointed by base->next_keyword) - if(likely(hash == e->hash && !strcmp(keyword, e->name))) { + if(likely(hash == e->hash && !strsame(keyword, e->name))) { // it is #ifdef NETDATA_INTERNAL_CHECKS diff --git a/src/appconfig.c b/src/appconfig.c index 81ab01be..91583f53 100644 --- a/src/appconfig.c +++ b/src/appconfig.c @@ -69,7 +69,7 @@ static inline void config_section_unlock(struct config *co) { static int config_value_compare(void* a, void* b) { if(((struct config_value *)a)->hash < ((struct config_value *)b)->hash) return -1; else if(((struct config_value *)a)->hash > ((struct config_value *)b)->hash) return 1; - else return strcmp(((struct config_value *)a)->name, ((struct config_value *)b)->name); + else return strsame(((struct config_value *)a)->name, ((struct config_value *)b)->name); } #define config_value_index_add(co, cv) (struct config_value *)avl_insert_lock(&((co)->values_index), (avl *)(cv)) @@ -90,7 +90,7 @@ static struct config_value *config_value_index_find(struct config *co, const cha static int config_compare(void* a, void* b) { if(((struct config *)a)->hash < ((struct config *)b)->hash) return -1; else if(((struct config *)a)->hash > ((struct config *)b)->hash) return 1; - else return strcmp(((struct config *)a)->name, ((struct config *)b)->name); + else return strsame(((struct config *)a)->name, ((struct config *)b)->name); } avl_tree_lock config_root_index = { @@ -238,7 +238,7 @@ char *config_get(const char *section, const char *name, const char *default_valu // this is a loaded value from the config file // if it is different that the default, mark it if(!(cv->flags & CONFIG_VALUE_CHECKED)) { - if(strcmp(cv->value, default_value) != 0) cv->flags |= CONFIG_VALUE_CHANGED; + if(strsame(cv->value, default_value) != 0) cv->flags |= CONFIG_VALUE_CHANGED; cv->flags |= CONFIG_VALUE_CHECKED; } } @@ -266,7 +266,7 @@ int config_get_boolean(const char *section, const char *name, int value) s = config_get(section, name, s); if(!s) return value; - if(!strcmp(s, "yes") || !strcmp(s, "auto") || !strcmp(s, "on demand")) return 1; + if(!strsame(s, "yes") || !strsame(s, "auto") || !strsame(s, "on demand")) return 1; return 0; } @@ -286,11 +286,11 @@ int config_get_boolean_ondemand(const char *section, const char *name, int value s = config_get(section, name, s); if(!s) return value; - if(!strcmp(s, "yes")) + if(!strsame(s, "yes")) return CONFIG_ONDEMAND_YES; - else if(!strcmp(s, "no")) + else if(!strsame(s, "no")) return CONFIG_ONDEMAND_NO; - else if(!strcmp(s, "auto") || !strcmp(s, "on demand")) + else if(!strsame(s, "auto") || !strsame(s, "on demand")) return CONFIG_ONDEMAND_ONDEMAND; return value; @@ -313,7 +313,7 @@ const char *config_set_default(const char *section, const char *name, const char if(cv->flags & CONFIG_VALUE_LOADED) return cv->value; - if(strcmp(cv->value, value) != 0) { + if(strsame(cv->value, value) != 0) { cv->flags |= CONFIG_VALUE_CHANGED; freez(cv->value); @@ -336,7 +336,7 @@ const char *config_set(const char *section, const char *name, const char *value) if(!cv) cv = config_value_create(co, name, value); cv->flags |= CONFIG_VALUE_USED; - if(strcmp(cv->value, value) != 0) { + if(strsame(cv->value, value) != 0) { cv->flags |= CONFIG_VALUE_CHANGED; freez(cv->value); @@ -492,11 +492,11 @@ void generate_config(BUFFER *wb, int only_changed) config_global_write_lock(); for(co = config_root; co ; co = co->next) { - if(!strcmp(co->name, "global") || - !strcmp(co->name, "plugins") || - !strcmp(co->name, "registry") || - !strcmp(co->name, "health") || - !strcmp(co->name, "backend")) + if(!strsame(co->name, "global") || + !strsame(co->name, "plugins") || + !strsame(co->name, "registry") || + !strsame(co->name, "health") || + !strsame(co->name, "backend")) pri = 0; else if(!strncmp(co->name, "plugin:", 7)) pri = 1; else pri = 2; diff --git a/src/apps_plugin.c b/src/apps_plugin.c index d9167b5a..0aba532b 100644 --- a/src/apps_plugin.c +++ b/src/apps_plugin.c @@ -218,7 +218,7 @@ static struct target *get_apps_groups_target(const char *id, struct target *targ name++; } for(target = apps_groups_root_target ; target ; target = target->next) { - if(!target->target && strcmp(name, target->name) == 0) + if(!target->target && strsame(name, target->name) == 0) break; } if(unlikely(debug)) { @@ -947,7 +947,7 @@ int file_descriptor_compare(void* a, void* b) { return 1; else - return strcmp(((struct file_descriptor *)a)->name, ((struct file_descriptor *)b)->name); + return strsame(((struct file_descriptor *)a)->name, ((struct file_descriptor *)b)->name); } int file_descriptor_iterator(avl *a) { if(a) {}; return 0; } @@ -1122,11 +1122,11 @@ static inline int file_descriptor_find_or_add(const char *name) if(name[0] == '/') type = FILETYPE_FILE; else if(strncmp(name, "pipe:", 5) == 0) type = FILETYPE_PIPE; else if(strncmp(name, "socket:", 7) == 0) type = FILETYPE_SOCKET; - else if(strcmp(name, "anon_inode:inotify") == 0 || strcmp(name, "inotify") == 0) type = FILETYPE_INOTIFY; - else if(strcmp(name, "anon_inode:[eventfd]") == 0) type = FILETYPE_EVENTFD; - else if(strcmp(name, "anon_inode:[eventpoll]") == 0) type = FILETYPE_EVENTPOLL; - else if(strcmp(name, "anon_inode:[timerfd]") == 0) type = FILETYPE_TIMERFD; - else if(strcmp(name, "anon_inode:[signalfd]") == 0) type = FILETYPE_SIGNALFD; + else if(strsame(name, "anon_inode:inotify") == 0 || strsame(name, "inotify") == 0) type = FILETYPE_INOTIFY; + else if(strsame(name, "anon_inode:[eventfd]") == 0) type = FILETYPE_EVENTFD; + else if(strsame(name, "anon_inode:[eventpoll]") == 0) type = FILETYPE_EVENTPOLL; + else if(strsame(name, "anon_inode:[timerfd]") == 0) type = FILETYPE_TIMERFD; + else if(strsame(name, "anon_inode:[signalfd]") == 0) type = FILETYPE_SIGNALFD; else if(strncmp(name, "anon_inode:", 11) == 0) { if(unlikely(debug)) fprintf(stderr, "apps.plugin: FIXME: unknown anonymous inode: %s\n", name); @@ -1173,7 +1173,7 @@ static inline int read_pid_file_descriptors(struct pid_stat *p) { p->fds[c] = -p->fds[c]; while((de = readdir(fds))) { - if(strcmp(de->d_name, ".") == 0 || strcmp(de->d_name, "..") == 0) + if(strsame(de->d_name, ".") == 0 || strsame(de->d_name, "..") == 0) continue; // check if the fds array is small @@ -1647,9 +1647,9 @@ static inline int collect_data_for_pid(pid_t pid) { // 2. the target has the prefix // 3. the target has the suffix // 4. the target is something inside cmdline - if( (!w->starts_with && !w->ends_with && w->comparehash == hash && !strcmp(w->compare, p->comm)) + if( (!w->starts_with && !w->ends_with && w->comparehash == hash && !strsame(w->compare, p->comm)) || (w->starts_with && !w->ends_with && !strncmp(w->compare, p->comm, w->comparelen)) - || (!w->starts_with && w->ends_with && pclen >= w->comparelen && !strcmp(w->compare, &p->comm[pclen - w->comparelen])) + || (!w->starts_with && w->ends_with && pclen >= w->comparelen && !strsame(w->compare, &p->comm[pclen - w->comparelen])) || (proc_pid_cmdline_is_needed && w->starts_with && w->ends_with && strstr(p->cmdline, w->compare)) ) { if(w->target) p->target = w->target; @@ -2684,58 +2684,58 @@ static void parse_args(int argc, char **argv) } } - if(strcmp("version", argv[i]) == 0 || strcmp("-v", argv[i]) == 0) { + if(strsame("version", argv[i]) == 0 || strsame("-v", argv[i]) == 0) { printf("apps.plugin %s\n", VERSION); exit(0); } - if(strcmp("debug", argv[i]) == 0) { + if(strsame("debug", argv[i]) == 0) { debug = 1; // debug_flags = 0xffffffff; continue; } - if(strcmp("no-childs", argv[i]) == 0 || strcmp("without-childs", argv[i]) == 0) { + if(strsame("no-childs", argv[i]) == 0 || strsame("without-childs", argv[i]) == 0) { include_exited_childs = 0; continue; } - if(strcmp("with-childs", argv[i]) == 0) { + if(strsame("with-childs", argv[i]) == 0) { include_exited_childs = 1; continue; } - if(strcmp("with-guest", argv[i]) == 0) { + if(strsame("with-guest", argv[i]) == 0) { enable_guest_charts = 1; continue; } - if(strcmp("no-guest", argv[i]) == 0 || strcmp("without-guest", argv[i]) == 0) { + if(strsame("no-guest", argv[i]) == 0 || strsame("without-guest", argv[i]) == 0) { enable_guest_charts = 0; continue; } - if(strcmp("with-files", argv[i]) == 0) { + if(strsame("with-files", argv[i]) == 0) { enable_file_charts = 1; continue; } - if(strcmp("no-files", argv[i]) == 0 || strcmp("without-files", argv[i]) == 0) { + if(strsame("no-files", argv[i]) == 0 || strsame("without-files", argv[i]) == 0) { enable_file_charts = 0; continue; } - if(strcmp("no-users", argv[i]) == 0 || strcmp("without-users", argv[i]) == 0) { + if(strsame("no-users", argv[i]) == 0 || strsame("without-users", argv[i]) == 0) { enable_users_charts = 0; continue; } - if(strcmp("no-groups", argv[i]) == 0 || strcmp("without-groups", argv[i]) == 0) { + if(strsame("no-groups", argv[i]) == 0 || strsame("without-groups", argv[i]) == 0) { enable_groups_charts = 0; continue; } - if(strcmp("-h", argv[i]) == 0 || strcmp("--help", argv[i]) == 0) { + if(strsame("-h", argv[i]) == 0 || strsame("--help", argv[i]) == 0) { fprintf(stderr, "apps.plugin %s\n" "(C) 2016 Costa Tsaousis" diff --git a/src/backends.c b/src/backends.c index 1272d047..1d126a20 100644 --- a/src/backends.c +++ b/src/backends.c @@ -169,13 +169,13 @@ void *backends_main(void *ptr) { if(!enabled || frequency < 1) goto cleanup; - if(!strcmp(source, "as collected")) { + if(!strsame(source, "as collected")) { options = BACKEND_SOURCE_DATA_AS_COLLECTED; } - else if(!strcmp(source, "average")) { + else if(!strsame(source, "average")) { options = BACKEND_SOURCE_DATA_AVERAGE; } - else if(!strcmp(source, "sum") || !strcmp(source, "volume")) { + else if(!strsame(source, "sum") || !strsame(source, "volume")) { options = BACKEND_SOURCE_DATA_SUM; } else { @@ -183,7 +183,7 @@ void *backends_main(void *ptr) { goto cleanup; } - if(!strcmp(type, "graphite") || !strcmp(type, "graphite:plaintext")) { + if(!strsame(type, "graphite") || !strsame(type, "graphite:plaintext")) { default_port = 2003; if(options == BACKEND_SOURCE_DATA_AS_COLLECTED) backend_request_formatter = format_dimension_collected_graphite_plaintext; @@ -192,7 +192,7 @@ void *backends_main(void *ptr) { backend_response_checker = process_graphite_response; } - else if(!strcmp(type, "opentsdb") || !strcmp(type, "opentsdb:telnet")) { + else if(!strsame(type, "opentsdb") || !strsame(type, "opentsdb:telnet")) { default_port = 4242; if(options == BACKEND_SOURCE_DATA_AS_COLLECTED) backend_request_formatter = format_dimension_collected_opentsdb_telnet; diff --git a/src/dictionary.c b/src/dictionary.c index fb9efeed..1466577f 100644 --- a/src/dictionary.c +++ b/src/dictionary.c @@ -56,7 +56,7 @@ static inline void dictionary_unlock(DICTIONARY *dict) { static int name_value_compare(void* a, void* b) { if(((NAME_VALUE *)a)->hash < ((NAME_VALUE *)b)->hash) return -1; else if(((NAME_VALUE *)a)->hash > ((NAME_VALUE *)b)->hash) return 1; - else return strcmp(((NAME_VALUE *)a)->name, ((NAME_VALUE *)b)->name); + else return strsame(((NAME_VALUE *)a)->name, ((NAME_VALUE *)b)->name); } static inline NAME_VALUE *dictionary_name_value_index_find_nolock(DICTIONARY *dict, const char *name, uint32_t hash) { diff --git a/src/eval.c b/src/eval.c index 122959ce..aeaf9c2b 100644 --- a/src/eval.c +++ b/src/eval.c @@ -77,7 +77,7 @@ static inline calculated_number eval_variable(EVAL_EXPRESSION *exp, EVAL_VARIABL critical_hash = simple_hash("CRITICAL"); } - if(unlikely(v->hash == this_hash && !strcmp(v->name, "this"))) { + if(unlikely(v->hash == this_hash && !strsame(v->name, "this"))) { n = (exp->this)?*exp->this:NAN; buffer_strcat(exp->error_msg, "[ $this = "); print_parsed_as_constant(exp->error_msg, n); @@ -85,7 +85,7 @@ static inline calculated_number eval_variable(EVAL_EXPRESSION *exp, EVAL_VARIABL return n; } - if(unlikely(v->hash == after_hash && !strcmp(v->name, "after"))) { + if(unlikely(v->hash == after_hash && !strsame(v->name, "after"))) { n = (exp->after && *exp->after)?*exp->after:NAN; buffer_strcat(exp->error_msg, "[ $after = "); print_parsed_as_constant(exp->error_msg, n); @@ -93,7 +93,7 @@ static inline calculated_number eval_variable(EVAL_EXPRESSION *exp, EVAL_VARIABL return n; } - if(unlikely(v->hash == before_hash && !strcmp(v->name, "before"))) { + if(unlikely(v->hash == before_hash && !strsame(v->name, "before"))) { n = (exp->before && *exp->before)?*exp->before:NAN; buffer_strcat(exp->error_msg, "[ $before = "); print_parsed_as_constant(exp->error_msg, n); @@ -101,7 +101,7 @@ static inline calculated_number eval_variable(EVAL_EXPRESSION *exp, EVAL_VARIABL return n; } - if(unlikely(v->hash == now_hash && !strcmp(v->name, "now"))) { + if(unlikely(v->hash == now_hash && !strsame(v->name, "now"))) { n = now_realtime_sec(); buffer_strcat(exp->error_msg, "[ $now = "); print_parsed_as_constant(exp->error_msg, n); @@ -109,7 +109,7 @@ static inline calculated_number eval_variable(EVAL_EXPRESSION *exp, EVAL_VARIABL return n; } - if(unlikely(v->hash == status_hash && !strcmp(v->name, "status"))) { + if(unlikely(v->hash == status_hash && !strsame(v->name, "status"))) { n = (exp->status)?*exp->status:RRDCALC_STATUS_UNINITIALIZED; buffer_strcat(exp->error_msg, "[ $status = "); print_parsed_as_constant(exp->error_msg, n); @@ -117,7 +117,7 @@ static inline calculated_number eval_variable(EVAL_EXPRESSION *exp, EVAL_VARIABL return n; } - if(unlikely(v->hash == removed_hash && !strcmp(v->name, "REMOVED"))) { + if(unlikely(v->hash == removed_hash && !strsame(v->name, "REMOVED"))) { n = RRDCALC_STATUS_REMOVED; buffer_strcat(exp->error_msg, "[ $REMOVED = "); print_parsed_as_constant(exp->error_msg, n); @@ -125,7 +125,7 @@ static inline calculated_number eval_variable(EVAL_EXPRESSION *exp, EVAL_VARIABL return n; } - if(unlikely(v->hash == uninitialized_hash && !strcmp(v->name, "UNINITIALIZED"))) { + if(unlikely(v->hash == uninitialized_hash && !strsame(v->name, "UNINITIALIZED"))) { n = RRDCALC_STATUS_UNINITIALIZED; buffer_strcat(exp->error_msg, "[ $UNINITIALIZED = "); print_parsed_as_constant(exp->error_msg, n); @@ -133,7 +133,7 @@ static inline calculated_number eval_variable(EVAL_EXPRESSION *exp, EVAL_VARIABL return n; } - if(unlikely(v->hash == undefined_hash && !strcmp(v->name, "UNDEFINED"))) { + if(unlikely(v->hash == undefined_hash && !strsame(v->name, "UNDEFINED"))) { n = RRDCALC_STATUS_UNDEFINED; buffer_strcat(exp->error_msg, "[ $UNDEFINED = "); print_parsed_as_constant(exp->error_msg, n); @@ -141,7 +141,7 @@ static inline calculated_number eval_variable(EVAL_EXPRESSION *exp, EVAL_VARIABL return n; } - if(unlikely(v->hash == clear_hash && !strcmp(v->name, "CLEAR"))) { + if(unlikely(v->hash == clear_hash && !strsame(v->name, "CLEAR"))) { n = RRDCALC_STATUS_CLEAR; buffer_strcat(exp->error_msg, "[ $CLEAR = "); print_parsed_as_constant(exp->error_msg, n); @@ -149,7 +149,7 @@ static inline calculated_number eval_variable(EVAL_EXPRESSION *exp, EVAL_VARIABL return n; } - if(unlikely(v->hash == warning_hash && !strcmp(v->name, "WARNING"))) { + if(unlikely(v->hash == warning_hash && !strsame(v->name, "WARNING"))) { n = RRDCALC_STATUS_WARNING; buffer_strcat(exp->error_msg, "[ $WARNING = "); print_parsed_as_constant(exp->error_msg, n); @@ -157,7 +157,7 @@ static inline calculated_number eval_variable(EVAL_EXPRESSION *exp, EVAL_VARIABL return n; } - if(unlikely(v->hash == critical_hash && !strcmp(v->name, "CRITICAL"))) { + if(unlikely(v->hash == critical_hash && !strsame(v->name, "CRITICAL"))) { n = RRDCALC_STATUS_CRITICAL; buffer_strcat(exp->error_msg, "[ $CRITICAL = "); print_parsed_as_constant(exp->error_msg, n); diff --git a/src/freebsd_sysctl.c b/src/freebsd_sysctl.c index 7edaf4f0..ab86ce5c 100644 --- a/src/freebsd_sysctl.c +++ b/src/freebsd_sysctl.c @@ -2127,11 +2127,11 @@ int do_freebsd_sysctl(int update_every, usec_t dt) { if (mntbuf[i].f_flags == MNT_RDONLY || mntbuf[i].f_blocks == 0 || // taken from gnulib/mountlist.c and shortened to FreeBSD related fstypes - strcmp(mntbuf[i].f_fstypename, "autofs") == 0 || - strcmp(mntbuf[i].f_fstypename, "procfs") == 0 || - strcmp(mntbuf[i].f_fstypename, "subfs") == 0 || - strcmp(mntbuf[i].f_fstypename, "devfs") == 0 || - strcmp(mntbuf[i].f_fstypename, "none") == 0) + strsame(mntbuf[i].f_fstypename, "autofs") == 0 || + strsame(mntbuf[i].f_fstypename, "procfs") == 0 || + strsame(mntbuf[i].f_fstypename, "subfs") == 0 || + strsame(mntbuf[i].f_fstypename, "devfs") == 0 || + strsame(mntbuf[i].f_fstypename, "none") == 0) continue; // -------------------------------------------------------------------------- diff --git a/src/health.c b/src/health.c index 193312ee..24f6813c 100755 --- a/src/health.c +++ b/src/health.c @@ -232,7 +232,7 @@ static inline ssize_t health_alarm_log_read(RRDHOST *host, FILE *fp, const char } // check for a possible host missmatch - //if(strcmp(pointers[1], host->hostname)) + //if(strsame(pointers[1], host->hostname)) // error("Health: line %zu of file '%s' provides an alarm for host '%s' but this is named '%s'.", line, filename, pointers[1], host->hostname); ae->unique_id = unique_id; @@ -453,7 +453,7 @@ static inline int rrdvar_fix_name(char *variable) { int rrdvar_compare(void* a, void* b) { if(((RRDVAR *)a)->hash < ((RRDVAR *)b)->hash) return -1; else if(((RRDVAR *)a)->hash > ((RRDVAR *)b)->hash) return 1; - else return strcmp(((RRDVAR *)a)->name, ((RRDVAR *)b)->name); + else return strsame(((RRDVAR *)a)->name, ((RRDVAR *)b)->name); } static inline RRDVAR *rrdvar_index_add(avl_tree_lock *tree, RRDVAR *rv) { @@ -1100,8 +1100,8 @@ static void rrdsetcalc_link(RRDSET *st, RRDCALC *rc) { } static inline int rrdcalc_is_matching_this_rrdset(RRDCALC *rc, RRDSET *st) { - if( (rc->hash_chart == st->hash && !strcmp(rc->chart, st->id)) || - (rc->hash_chart == st->hash_name && !strcmp(rc->chart, st->name))) + if( (rc->hash_chart == st->hash && !strsame(rc->chart, st->id)) || + (rc->hash_chart == st->hash_name && !strsame(rc->chart, st->name))) return 1; return 0; @@ -1176,7 +1176,7 @@ RRDCALC *rrdcalc_find(RRDSET *st, const char *name) { uint32_t hash = simple_hash(name); for( rc = st->alarms; rc ; rc = rc->rrdset_next ) { - if(unlikely(rc->hash == hash && !strcmp(rc->name, name))) + if(unlikely(rc->hash == hash && !strsame(rc->name, name))) return rc; } @@ -1196,7 +1196,7 @@ static inline int rrdcalc_exists(RRDHOST *host, const char *chart, const char *n // make sure it does not already exist for(rc = host->alarms; rc ; rc = rc->next) { - if (unlikely(rc->chart && rc->hash == hash_name && rc->hash_chart == hash_chart && !strcmp(name, rc->name) && !strcmp(chart, rc->chart))) { + if (unlikely(rc->chart && rc->hash == hash_name && rc->hash_chart == hash_chart && !strsame(name, rc->name) && !strsame(chart, rc->chart))) { debug(D_HEALTH, "Health alarm '%s.%s' already exists in host '%s'.", chart, name, host->hostname); error("Health alarm '%s.%s' already exists in host '%s'.", chart, name, host->hostname); return 1; @@ -1214,7 +1214,7 @@ static inline uint32_t rrdcalc_get_unique_id(RRDHOST *host, const char *chart, c // re-use old IDs, by looking them up in the alarm log ALARM_ENTRY *ae; for(ae = host->health_log.alarms; ae ;ae = ae->next) { - if(unlikely(ae->hash_name == hash_name && ae->hash_chart == hash_chart && !strcmp(name, ae->name) && !strcmp(chart, ae->chart))) { + if(unlikely(ae->hash_name == hash_name && ae->hash_chart == hash_chart && !strsame(name, ae->name) && !strsame(chart, ae->chart))) { if(next_event_id) *next_event_id = ae->alarm_event_id + 1; return ae->alarm_id; } @@ -1400,7 +1400,7 @@ void rrdcalctemplate_link_matching(RRDSET *st) { RRDCALCTEMPLATE *rt; for(rt = st->rrdhost->templates; rt ; rt = rt->next) { - if(rt->hash_context == st->hash_context && !strcmp(rt->context, st->context) + if(rt->hash_context == st->hash_context && !strsame(rt->context, st->context) && (!rt->family_pattern || simple_pattern_matches(rt->family_pattern, st->family))) { RRDCALC *rc = rrdcalc_create(st->rrdhost, rt, st->id); if(unlikely(!rc)) @@ -1540,7 +1540,7 @@ static inline int rrdcalctemplate_add_template_from_config(RRDHOST *host, RRDCAL RRDCALCTEMPLATE *t, *last = NULL; for (t = host->templates; t ; last = t, t = t->next) { - if(unlikely(t->hash_name == rt->hash_name && !strcmp(t->name, rt->name))) { + if(unlikely(t->hash_name == rt->hash_name && !strsame(t->name, rt->name))) { error("Health configuration template '%s' already exists for host '%s'.", rt->name, host->hostname); return 0; } @@ -1955,7 +1955,7 @@ int health_readfile(const char *path, const char *filename) { else if(rc) { if(hash == hash_on && !strcasecmp(key, HEALTH_ON_KEY)) { if(rc->chart) { - if(strcmp(rc->chart, value)) + if(strsame(rc->chart, value)) error("Health configuration at line %zu of file '%s/%s' for alarm '%s' has key '%s' twice, once with value '%s' and later with value '%s'. Using ('%s').", line, path, filename, rc->name, key, rc->chart, value, value); @@ -2019,7 +2019,7 @@ int health_readfile(const char *path, const char *filename) { } else if(hash == hash_exec && !strcasecmp(key, HEALTH_EXEC_KEY)) { if(rc->exec) { - if(strcmp(rc->exec, value)) + if(strsame(rc->exec, value)) error("Health configuration at line %zu of file '%s/%s' for alarm '%s' has key '%s' twice, once with value '%s' and later with value '%s'. Using ('%s').", line, path, filename, rc->name, key, rc->exec, value, value); @@ -2029,7 +2029,7 @@ int health_readfile(const char *path, const char *filename) { } else if(hash == hash_recipient && !strcasecmp(key, HEALTH_RECIPIENT_KEY)) { if(rc->recipient) { - if(strcmp(rc->recipient, value)) + if(strsame(rc->recipient, value)) error("Health configuration at line %zu of file '%s/%s' for alarm '%s' has key '%s' twice, once with value '%s' and later with value '%s'. Using ('%s').", line, path, filename, rc->name, key, rc->recipient, value, value); @@ -2039,7 +2039,7 @@ int health_readfile(const char *path, const char *filename) { } else if(hash == hash_units && !strcasecmp(key, HEALTH_UNITS_KEY)) { if(rc->units) { - if(strcmp(rc->units, value)) + if(strsame(rc->units, value)) error("Health configuration at line %zu of file '%s/%s' for alarm '%s' has key '%s' twice, once with value '%s' and later with value '%s'. Using ('%s').", line, path, filename, rc->name, key, rc->units, value, value); @@ -2050,7 +2050,7 @@ int health_readfile(const char *path, const char *filename) { } else if(hash == hash_info && !strcasecmp(key, HEALTH_INFO_KEY)) { if(rc->info) { - if(strcmp(rc->info, value)) + if(strsame(rc->info, value)) error("Health configuration at line %zu of file '%s/%s' for alarm '%s' has key '%s' twice, once with value '%s' and later with value '%s'. Using ('%s').", line, path, filename, rc->name, key, rc->info, value, value); @@ -2070,7 +2070,7 @@ int health_readfile(const char *path, const char *filename) { else if(rt) { if(hash == hash_on && !strcasecmp(key, HEALTH_ON_KEY)) { if(rt->context) { - if(strcmp(rt->context, value)) + if(strsame(rt->context, value)) error("Health configuration at line %zu of file '%s/%s' for template '%s' has key '%s' twice, once with value '%s' and later with value '%s'. Using ('%s').", line, path, filename, rt->name, key, rt->context, value, value); @@ -2140,7 +2140,7 @@ int health_readfile(const char *path, const char *filename) { } else if(hash == hash_exec && !strcasecmp(key, HEALTH_EXEC_KEY)) { if(rt->exec) { - if(strcmp(rt->exec, value)) + if(strsame(rt->exec, value)) error("Health configuration at line %zu of file '%s/%s' for template '%s' has key '%s' twice, once with value '%s' and later with value '%s'. Using ('%s').", line, path, filename, rt->name, key, rt->exec, value, value); @@ -2150,7 +2150,7 @@ int health_readfile(const char *path, const char *filename) { } else if(hash == hash_recipient && !strcasecmp(key, HEALTH_RECIPIENT_KEY)) { if(rt->recipient) { - if(strcmp(rt->recipient, value)) + if(strsame(rt->recipient, value)) error("Health configuration at line %zu of file '%s/%s' for template '%s' has key '%s' twice, once with value '%s' and later with value '%s'. Using ('%s').", line, path, filename, rt->name, key, rt->recipient, value, value); @@ -2160,7 +2160,7 @@ int health_readfile(const char *path, const char *filename) { } else if(hash == hash_units && !strcasecmp(key, HEALTH_UNITS_KEY)) { if(rt->units) { - if(strcmp(rt->units, value)) + if(strsame(rt->units, value)) error("Health configuration at line %zu of file '%s/%s' for template '%s' has key '%s' twice, once with value '%s' and later with value '%s'. Using ('%s').", line, path, filename, rt->name, key, rt->units, value, value); @@ -2171,7 +2171,7 @@ int health_readfile(const char *path, const char *filename) { } else if(hash == hash_info && !strcasecmp(key, HEALTH_INFO_KEY)) { if(rt->info) { - if(strcmp(rt->info, value)) + if(strsame(rt->info, value)) error("Health configuration at line %zu of file '%s/%s' for template '%s' has key '%s' twice, once with value '%s' and later with value '%s'. Using ('%s').", line, path, filename, rt->name, key, rt->info, value, value); @@ -2239,7 +2239,7 @@ void health_readdir(const char *path) { } else if((de->d_type == DT_LNK || de->d_type == DT_REG || de->d_type == DT_UNKNOWN) && - len > 5 && !strcmp(&de->d_name[len - 5], ".conf")) { + len > 5 && !strsame(&de->d_name[len - 5], ".conf")) { health_readfile(path, de->d_name); } diff --git a/src/inlined.h b/src/inlined.h index b7392763..0e3b2910 100644 --- a/src/inlined.h +++ b/src/inlined.h @@ -77,6 +77,12 @@ static inline unsigned long long str2ull(const char *s) { return n; } +static inline int strsame(register const char *a, register const char *b) { + if(unlikely(a == b)) return 0; + while(*a && *a == *b) { a++; b++; } + return *a - *b; +} + static inline int read_single_number_file(const char *filename, unsigned long long *result) { char buffer[30 + 1]; diff --git a/src/log.c b/src/log.c index d4c7fa14..e96fa139 100644 --- a/src/log.c +++ b/src/log.c @@ -26,10 +26,10 @@ void syslog_init(void) { int open_log_file(int fd, FILE **fp, const char *filename, int *enabled_syslog) { int f; - if(!filename || !*filename || !strcmp(filename, "none")) + if(!filename || !*filename || !strsame(filename, "none")) filename = "/dev/null"; - if(!strcmp(filename, "syslog")) { + if(!strsame(filename, "syslog")) { filename = "/dev/null"; syslog_init(); if(enabled_syslog) *enabled_syslog = 1; @@ -38,15 +38,15 @@ int open_log_file(int fd, FILE **fp, const char *filename, int *enabled_syslog) // don't do anything if the user is willing // to have the standard one - if(!strcmp(filename, "system")) { + if(!strsame(filename, "system")) { if(fd != -1) return fd; filename = "stdout"; } - if(!strcmp(filename, "stdout")) + if(!strsame(filename, "stdout")) f = STDOUT_FILENO; - else if(!strcmp(filename, "stderr")) + else if(!strsame(filename, "stderr")) f = STDERR_FILENO; else { diff --git a/src/macos_fw.c b/src/macos_fw.c index a62aa7a7..f20feb83 100644 --- a/src/macos_fw.c +++ b/src/macos_fw.c @@ -330,11 +330,11 @@ int do_macos_iokit(int update_every, usec_t dt) { if (mntbuf[i].f_flags == MNT_RDONLY || mntbuf[i].f_blocks == 0 || // taken from gnulib/mountlist.c and shortened to FreeBSD related fstypes - strcmp(mntbuf[i].f_fstypename, "autofs") == 0 || - strcmp(mntbuf[i].f_fstypename, "procfs") == 0 || - strcmp(mntbuf[i].f_fstypename, "subfs") == 0 || - strcmp(mntbuf[i].f_fstypename, "devfs") == 0 || - strcmp(mntbuf[i].f_fstypename, "none") == 0) + strsame(mntbuf[i].f_fstypename, "autofs") == 0 || + strsame(mntbuf[i].f_fstypename, "procfs") == 0 || + strsame(mntbuf[i].f_fstypename, "subfs") == 0 || + strsame(mntbuf[i].f_fstypename, "devfs") == 0 || + strsame(mntbuf[i].f_fstypename, "none") == 0) continue; // -------------------------------------------------------------------------- diff --git a/src/main.c b/src/main.c index 36c022f8..fdedb081 100644 --- a/src/main.c +++ b/src/main.c @@ -77,15 +77,15 @@ void web_server_threading_selection(void) { web_enable_gzip = config_get_boolean("global", "enable web responses gzip compression", web_enable_gzip); char *s = config_get("global", "web compression strategy", "default"); - if(!strcmp(s, "default")) + if(!strsame(s, "default")) web_gzip_strategy = Z_DEFAULT_STRATEGY; - else if(!strcmp(s, "filtered")) + else if(!strsame(s, "filtered")) web_gzip_strategy = Z_FILTERED; - else if(!strcmp(s, "huffman only")) + else if(!strsame(s, "huffman only")) web_gzip_strategy = Z_HUFFMAN_ONLY; - else if(!strcmp(s, "rle")) + else if(!strsame(s, "rle")) web_gzip_strategy = Z_RLE; - else if(!strcmp(s, "fixed")) + else if(!strsame(s, "fixed")) web_gzip_strategy = Z_FIXED; else { error("Invalid compression strategy '%s'. Valid strategies are 'default', 'filtered', 'huffman only', 'rle' and 'fixed'. Proceeding with 'default'.", s); @@ -351,22 +351,22 @@ int main(int argc, char **argv) { i = 1; while(i < argc) { - if(strcmp(argv[i], "-pidfile") == 0 && (i+1) < argc) { + if(strsame(argv[i], "-pidfile") == 0 && (i+1) < argc) { strncpyz(pidfile, argv[i+1], FILENAME_MAX); fprintf(stderr, "%s: deprecated option -- %s -- please use -P instead.\n", argv[0], argv[i]); remove_option(i, &argc, argv); } - else if(strcmp(argv[i], "-nodaemon") == 0 || strcmp(argv[i], "-nd") == 0) { + else if(strsame(argv[i], "-nodaemon") == 0 || strsame(argv[i], "-nd") == 0) { dont_fork = 1; fprintf(stderr, "%s: deprecated option -- %s -- please use -D instead.\n ", argv[0], argv[i]); remove_option(i, &argc, argv); } - else if(strcmp(argv[i], "-ch") == 0 && (i+1) < argc) { + else if(strsame(argv[i], "-ch") == 0 && (i+1) < argc) { config_set("global", "host access prefix", argv[i+1]); fprintf(stderr, "%s: deprecated option -- %s -- please use -s instead.\n", argv[0], argv[i]); remove_option(i, &argc, argv); } - else if(strcmp(argv[i], "-l") == 0 && (i+1) < argc) { + else if(strsame(argv[i], "-l") == 0 && (i+1) < argc) { config_set("global", "history", argv[i+1]); fprintf(stderr, "%s: deprecated option -- %s -- This option will be removed with V2.*.\n", argv[0], argv[i]); remove_option(i, &argc, argv); @@ -443,14 +443,14 @@ int main(int argc, char **argv) { char* stacksize_string = "stacksize="; char* debug_flags_string = "debug_flags="; - if(strcmp(optarg, "unittest") == 0) { + if(strsame(optarg, "unittest") == 0) { rrd_update_every = 1; if(run_all_mockup_tests()) exit(1); if(unit_test_storage()) exit(1); fprintf(stderr, "\n\nALL TESTS PASSED\n\n"); exit(0); } - else if(strcmp(optarg, "simple-pattern") == 0) { + else if(strsame(optarg, "simple-pattern") == 0) { if(optind + 2 > argc) { fprintf(stderr, "%s", "\nUSAGE: -W simple-pattern 'pattern' 'string'\n\n" " Checks if 'pattern' matches the given 'string'.\n" diff --git a/src/plugin_tc.c b/src/plugin_tc.c index 6226d49e..0d8c5dca 100644 --- a/src/plugin_tc.c +++ b/src/plugin_tc.c @@ -92,7 +92,7 @@ struct tc_device *tc_device_root = NULL; static int tc_device_compare(void* a, void* b) { if(((struct tc_device *)a)->hash < ((struct tc_device *)b)->hash) return -1; else if(((struct tc_device *)a)->hash > ((struct tc_device *)b)->hash) return 1; - else return strcmp(((struct tc_device *)a)->id, ((struct tc_device *)b)->id); + else return strsame(((struct tc_device *)a)->id, ((struct tc_device *)b)->id); } avl_tree tc_device_root_index = { @@ -118,7 +118,7 @@ static inline struct tc_device *tc_device_index_find(const char *id, uint32_t ha static int tc_class_compare(void* a, void* b) { if(((struct tc_class *)a)->hash < ((struct tc_class *)b)->hash) return -1; else if(((struct tc_class *)a)->hash > ((struct tc_class *)b)->hash) return 1; - else return strcmp(((struct tc_class *)a)->id, ((struct tc_class *)b)->id); + else return strsame(((struct tc_class *)a)->id, ((struct tc_class *)b)->id); } #define tc_class_index_add(st, rd) (struct tc_class *)avl_insert(&((st)->classes_index), (avl *)(rd)) @@ -216,8 +216,8 @@ static inline void tc_device_commit(struct tc_device *d) { if(unlikely(c == x)) continue; if(x->parentid && ( - ( c->hash == x->parent_hash && strcmp(c->id, x->parentid) == 0) || - (c->leafid && c->leaf_hash == x->parent_hash && strcmp(c->leafid, x->parentid) == 0))) { + ( c->hash == x->parent_hash && strsame(c->id, x->parentid) == 0) || + (c->leafid && c->leaf_hash == x->parent_hash && strsame(c->leafid, x->parentid) == 0))) { // debug(D_TC_LOOP, "TC: In device '%s', class '%s' (leafid: '%s') has as leaf class '%s' (parentid: '%s').", d->name?d->name:d->id, c->name?c->name:c->id, c->leafid?c->leafid:c->id, x->name?x->name:x->id, x->parentid?x->parentid:x->id); c->isleaf = 0; x->hasparent = 1; @@ -309,7 +309,7 @@ static inline void tc_device_commit(struct tc_device *d) { debug(D_TC_LOOP, "TC: Updating chart for device '%s'", d->name?d->name:d->id); rrdset_next(d->st_bytes); - if(unlikely(d->name_updated && d->name && strcmp(d->id, d->name) != 0)) { + if(unlikely(d->name_updated && d->name && strsame(d->id, d->name) != 0)) { rrdset_set_name(d->st_bytes, d->name); d->name_updated = 0; } @@ -338,7 +338,7 @@ static inline void tc_device_commit(struct tc_device *d) { rrddim_set_by_pointer(d->st_bytes, c->rd_bytes, c->bytes); // if it has a name, different to the id - if(unlikely(c->name_updated && c->name && strcmp(c->id, c->name) != 0)) { + if(unlikely(c->name_updated && c->name && strsame(c->id, c->name) != 0)) { // update the rrd dimension with the new name debug(D_TC_LOOP, "TC: Setting chart '%s', dimension '%s' name to '%s'", d->st_bytes->id, c->rd_bytes->id, c->name); rrddim_set_name(d->st_bytes, c->rd_bytes, c->name); @@ -392,7 +392,7 @@ static inline void tc_device_commit(struct tc_device *d) { rrddim_set_by_pointer(d->st_packets, c->rd_packets, c->packets); // if it has a name, different to the id - if(unlikely(c->name_updated && c->name && strcmp(c->id, c->name) != 0)) { + if(unlikely(c->name_updated && c->name && strsame(c->id, c->name) != 0)) { // update the rrd dimension with the new name debug(D_TC_LOOP, "TC: Setting chart '%s', dimension '%s' name to '%s'", d->st_packets->id, c->rd_packets->id, c->name); rrddim_set_name(d->st_packets, c->rd_packets, c->name); @@ -446,7 +446,7 @@ static inline void tc_device_commit(struct tc_device *d) { rrddim_set_by_pointer(d->st_dropped, c->rd_dropped, c->dropped); // if it has a name, different to the id - if(unlikely(c->name_updated && c->name && strcmp(c->id, c->name) != 0)) { + if(unlikely(c->name_updated && c->name && strsame(c->id, c->name) != 0)) { // update the rrd dimension with the new name debug(D_TC_LOOP, "TC: Setting chart '%s', dimension '%s' name to '%s'", d->st_dropped->id, c->rd_dropped->id, c->name); rrddim_set_name(d->st_dropped, c->rd_dropped, c->name); @@ -500,7 +500,7 @@ static inline void tc_device_commit(struct tc_device *d) { rrddim_set_by_pointer(d->st_tokens, c->rd_tokens, c->tokens); // if it has a name, different to the id - if(unlikely(c->name_updated && c->name && strcmp(c->id, c->name) != 0)) { + if(unlikely(c->name_updated && c->name && strsame(c->id, c->name) != 0)) { // update the rrd dimension with the new name debug(D_TC_LOOP, "TC: Setting chart '%s', dimension '%s' name to '%s'", d->st_tokens->id, c->rd_tokens->id, c->name); rrddim_set_name(d->st_tokens, c->rd_tokens, c->name); @@ -554,7 +554,7 @@ static inline void tc_device_commit(struct tc_device *d) { rrddim_set_by_pointer(d->st_ctokens, c->rd_ctokens, c->ctokens); // if it has a name, different to the id - if(unlikely(c->name_updated && c->name && strcmp(c->id, c->name) != 0)) { + if(unlikely(c->name_updated && c->name && strsame(c->id, c->name) != 0)) { // update the rrd dimension with the new name debug(D_TC_LOOP, "TC: Setting chart '%s', dimension '%s' name to '%s'", d->st_ctokens->id, c->rd_ctokens->id, c->name); rrddim_set_name(d->st_ctokens, c->rd_ctokens, c->name); @@ -575,7 +575,7 @@ static inline void tc_device_set_class_name(struct tc_device *d, char *id, char freez(c->name); c->name = NULL; - if(likely(name && *name && strcmp(c->id, name) != 0)) { + if(likely(name && *name && strsame(c->id, name) != 0)) { debug(D_TC_LOOP, "TC: Setting device '%s', class '%s' name to '%s'", d->id, id, name); c->name = strdupz(name); c->name_updated = 1; @@ -587,7 +587,7 @@ static inline void tc_device_set_device_name(struct tc_device *d, char *name) { freez(d->name); d->name = NULL; - if(likely(name && *name && strcmp(d->id, name) != 0)) { + if(likely(name && *name && strsame(d->id, name) != 0)) { debug(D_TC_LOOP, "TC: Setting device '%s' name to '%s'", d->id, name); d->name = strdupz(name); d->name_updated = 1; @@ -598,7 +598,7 @@ static inline void tc_device_set_device_family(struct tc_device *d, char *family freez(d->family); d->family = NULL; - if(likely(family && *family && strcmp(d->id, family) != 0)) { + if(likely(family && *family && strsame(d->id, family) != 0)) { debug(D_TC_LOOP, "TC: Setting device '%s' family to '%s'", d->id, family); d->family = strdupz(family); d->family_updated = 1; @@ -815,17 +815,17 @@ void *tc_main(void *ptr) { first_hash = simple_hash(words[0]); - if(unlikely(device && first_hash == CLASS_HASH && strcmp(words[0], "class") == 0)) { + if(unlikely(device && first_hash == CLASS_HASH && strsame(words[0], "class") == 0)) { // debug(D_TC_LOOP, "CLASS line on class id='%s', parent='%s', parentid='%s', leaf='%s', leafid='%s'", words[2], words[3], words[4], words[5], words[6]); // words[1] : class type // words[2] : N:XX // words[3] : parent or root - if(likely(words[1] && words[2] && words[3] && (strcmp(words[3], "parent") == 0 || strcmp(words[3], "root") == 0))) { + if(likely(words[1] && words[2] && words[3] && (strsame(words[3], "parent") == 0 || strsame(words[3], "root") == 0))) { //char *type = words[1]; // the class: htb, fq_codel, etc // we are only interested for HTB classes - //if(strcmp(type, "htb") != 0) continue; + //if(strsame(type, "htb") != 0) continue; char *id = words[2]; // the class major:minor char *parent = words[3]; // 'parent' or 'root' @@ -833,11 +833,11 @@ void *tc_main(void *ptr) { char *leaf = words[5]; // 'leaf' char *leafid = words[6]; // leafid - if(strcmp(parent, "root") == 0) { + if(strsame(parent, "root") == 0) { parentid = NULL; leafid = NULL; } - else if(!leaf || strcmp(leaf, "leaf") != 0) + else if(!leaf || strsame(leaf, "leaf") != 0) leafid = NULL; char leafbuf[20 + 1] = ""; @@ -854,7 +854,7 @@ void *tc_main(void *ptr) { class = NULL; } } - else if(unlikely(first_hash == END_HASH && strcmp(words[0], "END") == 0)) { + else if(unlikely(first_hash == END_HASH && strsame(words[0], "END") == 0)) { // debug(D_TC_LOOP, "END line"); if(likely(device)) { @@ -871,7 +871,7 @@ void *tc_main(void *ptr) { device = NULL; class = NULL; } - else if(unlikely(first_hash == BEGIN_HASH && strcmp(words[0], "BEGIN") == 0)) { + else if(unlikely(first_hash == BEGIN_HASH && strsame(words[0], "BEGIN") == 0)) { // debug(D_TC_LOOP, "BEGIN line on device '%s'", words[1]); if(likely(words[1] && *words[1])) { @@ -884,7 +884,7 @@ void *tc_main(void *ptr) { class = NULL; } - else if(unlikely(device && class && first_hash == SENT_HASH && strcmp(words[0], "Sent") == 0)) { + else if(unlikely(device && class && first_hash == SENT_HASH && strsame(words[0], "Sent") == 0)) { // debug(D_TC_LOOP, "SENT line '%s'", words[1]); if(likely(words[1] && *words[1])) { class->bytes = str2ull(words[1]); @@ -906,7 +906,7 @@ void *tc_main(void *ptr) { if(likely(words[10] && *words[10])) class->requeues = str2ull(words[8]); } - else if(unlikely(device && class && class->updated && first_hash == LENDED_HASH && strcmp(words[0], "lended:") == 0)) { + else if(unlikely(device && class && class->updated && first_hash == LENDED_HASH && strsame(words[0], "lended:") == 0)) { // debug(D_TC_LOOP, "LENDED line '%s'", words[1]); if(likely(words[1] && *words[1])) class->lended = str2ull(words[1]); @@ -917,7 +917,7 @@ void *tc_main(void *ptr) { if(likely(words[5] && *words[5])) class->giants = str2ull(words[5]); } - else if(unlikely(device && class && class->updated && first_hash == TOKENS_HASH && strcmp(words[0], "tokens:") == 0)) { + else if(unlikely(device && class && class->updated && first_hash == TOKENS_HASH && strsame(words[0], "tokens:") == 0)) { // debug(D_TC_LOOP, "TOKENS line '%s'", words[1]); if(likely(words[1] && *words[1])) class->tokens = str2ull(words[1]); @@ -925,24 +925,24 @@ void *tc_main(void *ptr) { if(likely(words[3] && *words[3])) class->ctokens = str2ull(words[3]); } - else if(unlikely(device && first_hash == SETDEVICENAME_HASH && strcmp(words[0], "SETDEVICENAME") == 0)) { + else if(unlikely(device && first_hash == SETDEVICENAME_HASH && strsame(words[0], "SETDEVICENAME") == 0)) { // debug(D_TC_LOOP, "SETDEVICENAME line '%s'", words[1]); if(likely(words[1] && *words[1])) tc_device_set_device_name(device, words[1]); } - else if(unlikely(device && first_hash == SETDEVICEGROUP_HASH && strcmp(words[0], "SETDEVICEGROUP") == 0)) { + else if(unlikely(device && first_hash == SETDEVICEGROUP_HASH && strsame(words[0], "SETDEVICEGROUP") == 0)) { // debug(D_TC_LOOP, "SETDEVICEGROUP line '%s'", words[1]); if(likely(words[1] && *words[1])) tc_device_set_device_family(device, words[1]); } - else if(unlikely(device && first_hash == SETCLASSNAME_HASH && strcmp(words[0], "SETCLASSNAME") == 0)) { + else if(unlikely(device && first_hash == SETCLASSNAME_HASH && strsame(words[0], "SETCLASSNAME") == 0)) { // debug(D_TC_LOOP, "SETCLASSNAME line '%s' '%s'", words[1], words[2]); char *id = words[1]; char *path = words[2]; if(likely(id && *id && path && *path)) tc_device_set_class_name(device, id, path); } - else if(unlikely(first_hash == WORKTIME_HASH && strcmp(words[0], "WORKTIME") == 0)) { + else if(unlikely(first_hash == WORKTIME_HASH && strsame(words[0], "WORKTIME") == 0)) { // debug(D_TC_LOOP, "WORKTIME line '%s' '%s'", words[1], words[2]); getrusage(RUSAGE_THREAD, &thread); @@ -970,7 +970,7 @@ void *tc_main(void *ptr) { } #ifdef DETACH_PLUGINS_FROM_NETDATA - else if(unlikely(first_hash == MYPID_HASH && (strcmp(words[0], "MYPID") == 0))) { + else if(unlikely(first_hash == MYPID_HASH && (strsame(words[0], "MYPID") == 0))) { // debug(D_TC_LOOP, "MYPID line '%s'", words[1]); char *id = words[1]; pid_t pid = atol(id); diff --git a/src/plugins_d.c b/src/plugins_d.c index ef7b7e84..7fe46e46 100644 --- a/src/plugins_d.c +++ b/src/plugins_d.c @@ -143,7 +143,7 @@ void *pluginsd_worker_thread(void *arg) hash = simple_hash(s); - if(likely(hash == SET_HASH && !strcmp(s, "SET"))) { + if(likely(hash == SET_HASH && !strsame(s, "SET"))) { char *dimension = words[1]; char *value = words[2]; @@ -167,7 +167,7 @@ void *pluginsd_worker_thread(void *arg) if(value) rrddim_set(st, dimension, strtoll(value, NULL, 0)); } - else if(likely(hash == BEGIN_HASH && !strcmp(s, "BEGIN"))) { + else if(likely(hash == BEGIN_HASH && !strsame(s, "BEGIN"))) { char *id = words[1]; char *microseconds_txt = words[2]; @@ -193,7 +193,7 @@ void *pluginsd_worker_thread(void *arg) else rrdset_next(st); } } - else if(likely(hash == END_HASH && !strcmp(s, "END"))) { + else if(likely(hash == END_HASH && !strsame(s, "END"))) { if(unlikely(!st)) { error("PLUGINSD: '%s' is requesting an END, without a BEGIN. Disabling it.", cd->fullfilename); cd->enabled = 0; @@ -208,15 +208,15 @@ void *pluginsd_worker_thread(void *arg) count++; } - else if(likely(hash == FLUSH_HASH && !strcmp(s, "FLUSH"))) { + else if(likely(hash == FLUSH_HASH && !strsame(s, "FLUSH"))) { debug(D_PLUGINSD, "PLUGINSD: '%s' is requesting a FLUSH", cd->fullfilename); st = NULL; } - else if(likely(hash == CHART_HASH && !strcmp(s, "CHART"))) { + else if(likely(hash == CHART_HASH && !strsame(s, "CHART"))) { int noname = 0; st = NULL; - if((words[1]) != NULL && (words[2]) != NULL && strcmp(words[1], words[2]) == 0) + if((words[1]) != NULL && (words[2]) != NULL && strsame(words[1], words[2]) == 0) noname = 1; char *type = words[1]; @@ -272,7 +272,7 @@ void *pluginsd_worker_thread(void *arg) } else debug(D_PLUGINSD, "PLUGINSD: Chart '%s' already exists. Not adding it again.", st->id); } - else if(likely(hash == DIMENSION_HASH && !strcmp(s, "DIMENSION"))) { + else if(likely(hash == DIMENSION_HASH && !strsame(s, "DIMENSION"))) { char *id = words[1]; char *name = words[2]; char *algorithm = words[3]; @@ -326,21 +326,21 @@ void *pluginsd_worker_thread(void *arg) } else if(unlikely(st->debug)) debug(D_PLUGINSD, "PLUGINSD: dimension %s/%s already exists. Not adding it again.", st->id, id); } - else if(unlikely(hash == DISABLE_HASH && !strcmp(s, "DISABLE"))) { + else if(unlikely(hash == DISABLE_HASH && !strsame(s, "DISABLE"))) { info("PLUGINSD: '%s' called DISABLE. Disabling it.", cd->fullfilename); cd->enabled = 0; killpid(cd->pid, SIGTERM); break; } #ifdef DETACH_PLUGINS_FROM_NETDATA - else if(likely(hash == MYPID_HASH && !strcmp(s, "MYPID"))) { + else if(likely(hash == MYPID_HASH && !strsame(s, "MYPID"))) { char *pid_s = words[1]; pid_t pid = strtod(pid_s, NULL, 0); if(likely(pid)) cd->pid = pid; debug(D_PLUGINSD, "PLUGINSD: %s is on pid %d", cd->id, cd->pid); } - else if(likely(hash == STOPPING_WAKE_ME_UP_PLEASE_HASH && !strcmp(s, "STOPPING_WAKE_ME_UP_PLEASE"))) { + else if(likely(hash == STOPPING_WAKE_ME_UP_PLEASE_HASH && !strsame(s, "STOPPING_WAKE_ME_UP_PLEASE"))) { error("PLUGINSD: '%s' (pid %d) called STOPPING_WAKE_ME_UP_PLEASE.", cd->fullfilename, cd->pid); now_realtime_timeval(&now); @@ -472,11 +472,11 @@ void *pluginsd_main(void *ptr) { debug(D_PLUGINSD, "PLUGINSD: Examining file '%s'", file->d_name); - if(unlikely(strcmp(file->d_name, ".") == 0 || strcmp(file->d_name, "..") == 0)) continue; + if(unlikely(strsame(file->d_name, ".") == 0 || strsame(file->d_name, "..") == 0)) continue; int len = (int) strlen(file->d_name); if(unlikely(len <= (int)PLUGINSD_FILE_SUFFIX_LEN)) continue; - if(unlikely(strcmp(PLUGINSD_FILE_SUFFIX, &file->d_name[len - (int)PLUGINSD_FILE_SUFFIX_LEN]) != 0)) { + if(unlikely(strsame(PLUGINSD_FILE_SUFFIX, &file->d_name[len - (int)PLUGINSD_FILE_SUFFIX_LEN]) != 0)) { debug(D_PLUGINSD, "PLUGINSD: File '%s' does not end in '%s'.", file->d_name, PLUGINSD_FILE_SUFFIX); continue; } @@ -492,7 +492,7 @@ void *pluginsd_main(void *ptr) { // check if it runs already for(cd = pluginsd_root ; cd ; cd = cd->next) - if(unlikely(strcmp(cd->filename, file->d_name) == 0)) break; + if(unlikely(strsame(cd->filename, file->d_name) == 0)) break; if(likely(cd && !cd->obsolete)) { debug(D_PLUGINSD, "PLUGINSD: plugin '%s' is already running", cd->filename); diff --git a/src/proc_diskstats.c b/src/proc_diskstats.c index fed87e8e..1c8dfdc9 100644 --- a/src/proc_diskstats.c +++ b/src/proc_diskstats.c @@ -91,7 +91,7 @@ static struct disk *get_disk(unsigned long major, unsigned long minor, char *dis struct dirent *dp; while( (dp = readdir(dirp)) ) { // . and .. are also files in empty folders. - if(unlikely(strcmp(dp->d_name, ".") == 0 || strcmp(dp->d_name, "..") == 0)) { + if(unlikely(strsame(dp->d_name, ".") == 0 || strsame(dp->d_name, "..") == 0)) { continue; } @@ -243,7 +243,7 @@ int do_proc_diskstats(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; + size_t lines = procfile_lines(ff), l; for(l = 0; l < lines ;l++) { // -------------------------------------------------------------------------- @@ -260,7 +260,7 @@ int do_proc_diskstats(int update_every, usec_t dt) { last_writes = 0, last_writesectors = 0, last_writems = 0, last_busy_ms = 0; - uint32_t words = procfile_linewords(ff, l); + size_t words = procfile_linewords(ff, l); if(unlikely(words < 14)) continue; major = str2ul(procfile_lineword(ff, l, 0)); diff --git a/src/proc_interrupts.c b/src/proc_interrupts.c index c2e91b8f..f663c0fd 100644 --- a/src/proc_interrupts.c +++ b/src/proc_interrupts.c @@ -23,12 +23,12 @@ struct interrupt { // given a base, get a pointer to each record #define irrindex(base, line, cpus) ((struct interrupt *)&((char *)(base))[line * recordsize(cpus)]) -static inline struct interrupt *get_interrupts_array(uint32_t lines, int cpus) { +static inline struct interrupt *get_interrupts_array(size_t lines, int cpus) { static struct interrupt *irrs = NULL; - static uint32_t allocated = 0; + static size_t allocated = 0; if(unlikely(lines != allocated)) { - uint32_t l; + size_t l; int c; irrs = (struct interrupt *)reallocz(irrs, lines * recordsize(cpus)); @@ -69,8 +69,8 @@ int do_proc_interrupts(int update_every, usec_t dt) { 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 = procfile_linewords(ff, 0); + size_t lines = procfile_lines(ff), l; + size_t words = procfile_linewords(ff, 0); if(unlikely(!lines)) { error("Cannot read /proc/interrupts, zero lines reported."); @@ -108,8 +108,8 @@ int do_proc_interrupts(int update_every, usec_t dt) { irr->id = procfile_lineword(ff, l, 0); if(unlikely(!irr->id || !irr->id[0])) continue; - int idlen = strlen(irr->id); - if(unlikely(irr->id[idlen - 1] == ':')) + size_t idlen = strlen(irr->id); + if(unlikely(idlen && irr->id[idlen - 1] == ':')) irr->id[idlen - 1] = '\0'; int c; @@ -124,8 +124,8 @@ int do_proc_interrupts(int update_every, usec_t dt) { if(unlikely(isdigit(irr->id[0]) && (uint32_t)(cpus + 2) < words)) { strncpyz(irr->name, procfile_lineword(ff, l, words - 1), MAX_INTERRUPT_NAME); - int nlen = strlen(irr->name); - int idlen = strlen(irr->id); + size_t nlen = strlen(irr->name); + idlen = strlen(irr->id); if(likely(nlen + 1 + idlen <= MAX_INTERRUPT_NAME)) { irr->name[nlen] = '_'; strncpyz(&irr->name[nlen + 1], irr->id, MAX_INTERRUPT_NAME - nlen - 1); diff --git a/src/proc_meminfo.c b/src/proc_meminfo.c index 829d7129..d5fc156c 100644 --- a/src/proc_meminfo.c +++ b/src/proc_meminfo.c @@ -113,7 +113,7 @@ int do_proc_meminfo(int update_every, usec_t dt) { 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; + size_t lines = procfile_lines(ff), l; int hwcorrupted = 0; @@ -162,54 +162,54 @@ int do_proc_meminfo(int update_every, usec_t dt) { unsigned long long *value = NULL; for(l = 0; l < lines ;l++) { - uint32_t words = procfile_linewords(ff, l); + size_t words = procfile_linewords(ff, l); if(unlikely(words < 2)) continue; char *name = procfile_lineword(ff, l, 0); uint32_t hash = simple_hash(name); - if(hash == MemTotal_hash && strcmp(name, "MemTotal") == 0) value = &MemTotal; - else if(hash == MemFree_hash && strcmp(name, "MemFree") == 0) value = &MemFree; - else if(hash == Buffers_hash && strcmp(name, "Buffers") == 0) value = &Buffers; - else if(hash == Cached_hash && strcmp(name, "Cached") == 0) value = &Cached; - //else if(hash == SwapCached_hash && strcmp(name, "SwapCached") == 0) value = &SwapCached; - //else if(hash == Active_hash && strcmp(name, "Active") == 0) value = &Active; - //else if(hash == Inactive_hash && strcmp(name, "Inactive") == 0) value = &Inactive; - //else if(hash == ActiveAnon_hash && strcmp(name, "ActiveAnon") == 0) value = &ActiveAnon; - //else if(hash == InactiveAnon_hash && strcmp(name, "InactiveAnon") == 0) value = &InactiveAnon; - //else if(hash == ActiveFile_hash && strcmp(name, "ActiveFile") == 0) value = &ActiveFile; - //else if(hash == InactiveFile_hash && strcmp(name, "InactiveFile") == 0) value = &InactiveFile; - //else if(hash == Unevictable_hash && strcmp(name, "Unevictable") == 0) value = &Unevictable; - //else if(hash == Mlocked_hash && strcmp(name, "Mlocked") == 0) value = &Mlocked; - else if(hash == SwapTotal_hash && strcmp(name, "SwapTotal") == 0) value = &SwapTotal; - else if(hash == SwapFree_hash && strcmp(name, "SwapFree") == 0) value = &SwapFree; - else if(hash == Dirty_hash && strcmp(name, "Dirty") == 0) value = &Dirty; - else if(hash == Writeback_hash && strcmp(name, "Writeback") == 0) value = &Writeback; - //else if(hash == AnonPages_hash && strcmp(name, "AnonPages") == 0) value = &AnonPages; - //else if(hash == Mapped_hash && strcmp(name, "Mapped") == 0) value = &Mapped; - //else if(hash == Shmem_hash && strcmp(name, "Shmem") == 0) value = &Shmem; - else if(hash == Slab_hash && strcmp(name, "Slab") == 0) value = &Slab; - else if(hash == SReclaimable_hash && strcmp(name, "SReclaimable") == 0) value = &SReclaimable; - else if(hash == SUnreclaim_hash && strcmp(name, "SUnreclaim") == 0) value = &SUnreclaim; - else if(hash == KernelStack_hash && strcmp(name, "KernelStack") == 0) value = &KernelStack; - else if(hash == PageTables_hash && strcmp(name, "PageTables") == 0) value = &PageTables; - else if(hash == NFS_Unstable_hash && strcmp(name, "NFS_Unstable") == 0) value = &NFS_Unstable; - else if(hash == Bounce_hash && strcmp(name, "Bounce") == 0) value = &Bounce; - else if(hash == WritebackTmp_hash && strcmp(name, "WritebackTmp") == 0) value = &WritebackTmp; - //else if(hash == CommitLimit_hash && strcmp(name, "CommitLimit") == 0) value = &CommitLimit; - else if(hash == Committed_AS_hash && strcmp(name, "Committed_AS") == 0) value = &Committed_AS; - //else if(hash == VmallocTotal_hash && strcmp(name, "VmallocTotal") == 0) value = &VmallocTotal; - else if(hash == VmallocUsed_hash && strcmp(name, "VmallocUsed") == 0) value = &VmallocUsed; - //else if(hash == VmallocChunk_hash && strcmp(name, "VmallocChunk") == 0) value = &VmallocChunk; - else if(hash == HardwareCorrupted_hash && strcmp(name, "HardwareCorrupted") == 0) { value = &HardwareCorrupted; hwcorrupted = 1; } - //else if(hash == AnonHugePages_hash && strcmp(name, "AnonHugePages") == 0) value = &AnonHugePages; - //else if(hash == HugePages_Total_hash && strcmp(name, "HugePages_Total") == 0) value = &HugePages_Total; - //else if(hash == HugePages_Free_hash && strcmp(name, "HugePages_Free") == 0) value = &HugePages_Free; - //else if(hash == HugePages_Rsvd_hash && strcmp(name, "HugePages_Rsvd") == 0) value = &HugePages_Rsvd; - //else if(hash == HugePages_Surp_hash && strcmp(name, "HugePages_Surp") == 0) value = &HugePages_Surp; - //else if(hash == Hugepagesize_hash && strcmp(name, "Hugepagesize") == 0) value = &Hugepagesize; - //else if(hash == DirectMap4k_hash && strcmp(name, "DirectMap4k") == 0) value = &DirectMap4k; - //else if(hash == DirectMap2M_hash && strcmp(name, "DirectMap2M") == 0) value = &DirectMap2M; + if(hash == MemTotal_hash && strsame(name, "MemTotal") == 0) value = &MemTotal; + else if(hash == MemFree_hash && strsame(name, "MemFree") == 0) value = &MemFree; + else if(hash == Buffers_hash && strsame(name, "Buffers") == 0) value = &Buffers; + else if(hash == Cached_hash && strsame(name, "Cached") == 0) value = &Cached; + //else if(hash == SwapCached_hash && strsame(name, "SwapCached") == 0) value = &SwapCached; + //else if(hash == Active_hash && strsame(name, "Active") == 0) value = &Active; + //else if(hash == Inactive_hash && strsame(name, "Inactive") == 0) value = &Inactive; + //else if(hash == ActiveAnon_hash && strsame(name, "ActiveAnon") == 0) value = &ActiveAnon; + //else if(hash == InactiveAnon_hash && strsame(name, "InactiveAnon") == 0) value = &InactiveAnon; + //else if(hash == ActiveFile_hash && strsame(name, "ActiveFile") == 0) value = &ActiveFile; + //else if(hash == InactiveFile_hash && strsame(name, "InactiveFile") == 0) value = &InactiveFile; + //else if(hash == Unevictable_hash && strsame(name, "Unevictable") == 0) value = &Unevictable; + //else if(hash == Mlocked_hash && strsame(name, "Mlocked") == 0) value = &Mlocked; + else if(hash == SwapTotal_hash && strsame(name, "SwapTotal") == 0) value = &SwapTotal; + else if(hash == SwapFree_hash && strsame(name, "SwapFree") == 0) value = &SwapFree; + else if(hash == Dirty_hash && strsame(name, "Dirty") == 0) value = &Dirty; + else if(hash == Writeback_hash && strsame(name, "Writeback") == 0) value = &Writeback; + //else if(hash == AnonPages_hash && strsame(name, "AnonPages") == 0) value = &AnonPages; + //else if(hash == Mapped_hash && strsame(name, "Mapped") == 0) value = &Mapped; + //else if(hash == Shmem_hash && strsame(name, "Shmem") == 0) value = &Shmem; + else if(hash == Slab_hash && strsame(name, "Slab") == 0) value = &Slab; + else if(hash == SReclaimable_hash && strsame(name, "SReclaimable") == 0) value = &SReclaimable; + else if(hash == SUnreclaim_hash && strsame(name, "SUnreclaim") == 0) value = &SUnreclaim; + else if(hash == KernelStack_hash && strsame(name, "KernelStack") == 0) value = &KernelStack; + else if(hash == PageTables_hash && strsame(name, "PageTables") == 0) value = &PageTables; + else if(hash == NFS_Unstable_hash && strsame(name, "NFS_Unstable") == 0) value = &NFS_Unstable; + else if(hash == Bounce_hash && strsame(name, "Bounce") == 0) value = &Bounce; + else if(hash == WritebackTmp_hash && strsame(name, "WritebackTmp") == 0) value = &WritebackTmp; + //else if(hash == CommitLimit_hash && strsame(name, "CommitLimit") == 0) value = &CommitLimit; + else if(hash == Committed_AS_hash && strsame(name, "Committed_AS") == 0) value = &Committed_AS; + //else if(hash == VmallocTotal_hash && strsame(name, "VmallocTotal") == 0) value = &VmallocTotal; + else if(hash == VmallocUsed_hash && strsame(name, "VmallocUsed") == 0) value = &VmallocUsed; + //else if(hash == VmallocChunk_hash && strsame(name, "VmallocChunk") == 0) value = &VmallocChunk; + else if(hash == HardwareCorrupted_hash && strsame(name, "HardwareCorrupted") == 0) { value = &HardwareCorrupted; hwcorrupted = 1; } + //else if(hash == AnonHugePages_hash && strsame(name, "AnonHugePages") == 0) value = &AnonHugePages; + //else if(hash == HugePages_Total_hash && strsame(name, "HugePages_Total") == 0) value = &HugePages_Total; + //else if(hash == HugePages_Free_hash && strsame(name, "HugePages_Free") == 0) value = &HugePages_Free; + //else if(hash == HugePages_Rsvd_hash && strsame(name, "HugePages_Rsvd") == 0) value = &HugePages_Rsvd; + //else if(hash == HugePages_Surp_hash && strsame(name, "HugePages_Surp") == 0) value = &HugePages_Surp; + //else if(hash == Hugepagesize_hash && strsame(name, "Hugepagesize") == 0) value = &Hugepagesize; + //else if(hash == DirectMap4k_hash && strsame(name, "DirectMap4k") == 0) value = &DirectMap4k; + //else if(hash == DirectMap2M_hash && strsame(name, "DirectMap2M") == 0) value = &DirectMap2M; if(value) { *value = str2ull(procfile_lineword(ff, l, 1)); diff --git a/src/proc_net_dev.c b/src/proc_net_dev.c index f37e2fe4..69ded9d2 100644 --- a/src/proc_net_dev.c +++ b/src/proc_net_dev.c @@ -77,7 +77,7 @@ static struct netdev *get_netdev(const char *name) { // search it, from the last position to the end for(d = last ; d ; d = d->next) { - if(unlikely(hash == d->hash && !strcmp(name, d->name))) { + if(unlikely(hash == d->hash && !strsame(name, d->name))) { last = d->next; return d; } @@ -85,7 +85,7 @@ static struct netdev *get_netdev(const char *name) { // search it from the beginning to the last position we used for(d = netdev_root ; d != last ; d = d->next) { - if(unlikely(hash == d->hash && !strcmp(name, d->name))) { + if(unlikely(hash == d->hash && !strsame(name, d->name))) { last = d->next; return d; } @@ -143,7 +143,7 @@ int do_proc_net_dev(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; + size_t lines = procfile_lines(ff), l; for(l = 2; l < lines ;l++) { // require 17 words on each line if(unlikely(procfile_linewords(ff, l) < 17)) continue; diff --git a/src/proc_net_ip_vs_stats.c b/src/proc_net_ip_vs_stats.c index 3513a25f..34cadaea 100644 --- a/src/proc_net_ip_vs_stats.c +++ b/src/proc_net_ip_vs_stats.c @@ -1,7 +1,6 @@ #include "common.h" #define RRD_TYPE_NET_IPVS "ipvs" -#define RRD_TYPE_NET_IPVS_LEN strlen(RRD_TYPE_NET_IPVS) int do_proc_net_ip_vs_stats(int update_every, usec_t dt) { static int do_bandwidth = -1, do_sockets = -1, do_packets = -1; diff --git a/src/proc_net_netstat.c b/src/proc_net_netstat.c index e6a991f1..3d81e968 100644 --- a/src/proc_net_netstat.c +++ b/src/proc_net_netstat.c @@ -161,19 +161,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/netstat 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/netstat 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/netstat on header line %zu has %zu words, but on value line %zu has %zu words.", header_line, hwords, values_line, vwords); vwords = hwords; } @@ -182,7 +182,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; } @@ -549,23 +549,23 @@ int do_proc_net_netstat(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; for(l = 0; l < lines ;l++) { char *key = procfile_lineword(ff, l, 0); uint32_t hash = simple_hash(key); - if(unlikely(hash == hash_ipext && strcmp(key, "IpExt") == 0)) { - uint32_t h = l++; + if(unlikely(hash == hash_ipext && strsame(key, "IpExt") == 0)) { + size_t h = l++; - if(unlikely(strcmp(procfile_lineword(ff, l, 0), "IpExt") != 0)) { + if(unlikely(strsame(procfile_lineword(ff, l, 0), "IpExt") != 0)) { error("Cannot read IpExt line from /proc/net/netstat."); break; } words = procfile_linewords(ff, l); if(unlikely(words < 2)) { - error("Cannot read /proc/net/netstat IpExt line. Expected 2+ params, read %u.", words); + error("Cannot read /proc/net/netstat IpExt line. Expected 2+ params, read %zu.", words); continue; } @@ -711,16 +711,16 @@ int do_proc_net_netstat(int update_every, usec_t dt) { rrdset_done(st); } } - else if(unlikely(hash == hash_tcpext && strcmp(key, "TcpExt") == 0)) { - uint32_t h = l++; + else if(unlikely(hash == hash_tcpext && strsame(key, "TcpExt") == 0)) { + size_t h = l++; - if(unlikely(strcmp(procfile_lineword(ff, l, 0), "TcpExt") != 0)) { + if(unlikely(strsame(procfile_lineword(ff, l, 0), "TcpExt") != 0)) { error("Cannot read TcpExt line from /proc/net/netstat."); break; } words = procfile_linewords(ff, l); if(unlikely(words < 2)) { - error("Cannot read /proc/net/netstat TcpExt line. Expected 2+ params, read %u.", words); + error("Cannot read /proc/net/netstat TcpExt line. Expected 2+ params, read %zu.", words); continue; } diff --git a/src/proc_net_rpc_nfs.c b/src/proc_net_rpc_nfs.c index e590a8fd..3300a605 100644 --- a/src/proc_net_rpc_nfs.c +++ b/src/proc_net_rpc_nfs.c @@ -151,28 +151,28 @@ int do_proc_net_rpc_nfs(int update_every, usec_t dt) { if(do_proc4 == -1) do_proc4 = config_get_boolean("plugin:proc:/proc/net/rpc/nfs", "NFS v4 procedures", 1); // if they are enabled, reset them to 1 - // later we do them =2 to avoid doing strcmp for all lines + // later we do them =2 to avoid doing strsame() for all lines if(do_net) do_net = 1; if(do_rpc) do_rpc = 1; if(do_proc2) do_proc2 = 1; if(do_proc3) do_proc3 = 1; if(do_proc4) do_proc4 = 1; - uint32_t lines = procfile_lines(ff), l; + size_t lines = procfile_lines(ff), l; char *type; unsigned long long net_count = 0, net_udp_count = 0, net_tcp_count = 0, net_tcp_connections = 0; unsigned long long rpc_calls = 0, rpc_retransmits = 0, rpc_auth_refresh = 0; for(l = 0; l < lines ;l++) { - uint32_t words = procfile_linewords(ff, l); + size_t words = procfile_linewords(ff, l); if(!words) continue; type = procfile_lineword(ff, l, 0); - if(do_net == 1 && strcmp(type, "net") == 0) { + if(do_net == 1 && strsame(type, "net") == 0) { if(words < 5) { - error("%s line of /proc/net/rpc/nfs has %u words, expected %d", type, words, 5); + error("%s line of /proc/net/rpc/nfs has %zu words, expected %d", type, words, 5); continue; } @@ -185,9 +185,9 @@ int do_proc_net_rpc_nfs(int update_every, usec_t dt) { if(sum == 0ULL) do_net = -1; else do_net = 2; } - else if(do_rpc == 1 && strcmp(type, "rpc") == 0) { + else if(do_rpc == 1 && strsame(type, "rpc") == 0) { if(words < 4) { - error("%s line of /proc/net/rpc/nfs has %u words, expected %d", type, words, 6); + error("%s line of /proc/net/rpc/nfs has %zu words, expected %d", type, words, 6); continue; } @@ -199,7 +199,7 @@ int do_proc_net_rpc_nfs(int update_every, usec_t dt) { if(sum == 0ULL) do_rpc = -1; else do_rpc = 2; } - else if(do_proc2 == 1 && strcmp(type, "proc2") == 0) { + else if(do_proc2 == 1 && strsame(type, "proc2") == 0) { // the first number is the count of numbers present // so we start for word 2 @@ -220,7 +220,7 @@ int do_proc_net_rpc_nfs(int update_every, usec_t dt) { } else do_proc2 = 2; } - else if(do_proc3 == 1 && strcmp(type, "proc3") == 0) { + else if(do_proc3 == 1 && strsame(type, "proc3") == 0) { // the first number is the count of numbers present // so we start for word 2 @@ -241,7 +241,7 @@ int do_proc_net_rpc_nfs(int update_every, usec_t dt) { } else do_proc3 = 2; } - else if(do_proc4 == 1 && strcmp(type, "proc4") == 0) { + else if(do_proc4 == 1 && strsame(type, "proc4") == 0) { // the first number is the count of numbers present // so we start for word 2 diff --git a/src/proc_net_rpc_nfsd.c b/src/proc_net_rpc_nfsd.c index 2b75d09f..22bd899a 100644 --- a/src/proc_net_rpc_nfsd.c +++ b/src/proc_net_rpc_nfsd.c @@ -239,7 +239,7 @@ int do_proc_net_rpc_nfsd(int update_every, usec_t dt) { if(do_proc4ops == -1) do_proc4ops = config_get_boolean("plugin:proc:/proc/net/rpc/nfsd", "NFS v4 operations", 1); // if they are enabled, reset them to 1 - // later we do them =2 to avoid doing strcmp for all lines + // later we do them =2 to avoid doing strsame() for all lines if(do_rc) do_rc = 1; if(do_fh) do_fh = 1; if(do_io) do_io = 1; @@ -252,7 +252,7 @@ int do_proc_net_rpc_nfsd(int update_every, usec_t dt) { if(do_proc4) do_proc4 = 1; if(do_proc4ops) do_proc4ops = 1; - uint32_t lines = procfile_lines(ff), l; + size_t lines = procfile_lines(ff), l; char *type; unsigned long long rc_hits = 0, rc_misses = 0, rc_nocache = 0; @@ -264,14 +264,14 @@ int do_proc_net_rpc_nfsd(int update_every, usec_t dt) { unsigned long long rpc_calls = 0, rpc_bad_format = 0, rpc_bad_auth = 0, rpc_bad_client = 0; for(l = 0; l < lines ;l++) { - uint32_t words = procfile_linewords(ff, l); + size_t words = procfile_linewords(ff, l); if(!words) continue; type = procfile_lineword(ff, l, 0); - if(do_rc == 1 && strcmp(type, "rc") == 0) { + if(do_rc == 1 && strsame(type, "rc") == 0) { if(words < 4) { - error("%s line of /proc/net/rpc/nfsd has %u words, expected %d", type, words, 4); + error("%s line of /proc/net/rpc/nfsd has %zu words, expected %d", type, words, 4); continue; } @@ -283,9 +283,9 @@ int do_proc_net_rpc_nfsd(int update_every, usec_t dt) { if(sum == 0ULL) do_rc = -1; else do_rc = 2; } - else if(do_fh == 1 && strcmp(type, "fh") == 0) { + else if(do_fh == 1 && strsame(type, "fh") == 0) { if(words < 6) { - error("%s line of /proc/net/rpc/nfsd has %u words, expected %d", type, words, 6); + error("%s line of /proc/net/rpc/nfsd has %zu words, expected %d", type, words, 6); continue; } @@ -299,9 +299,9 @@ int do_proc_net_rpc_nfsd(int update_every, usec_t dt) { if(sum == 0ULL) do_fh = -1; else do_fh = 2; } - else if(do_io == 1 && strcmp(type, "io") == 0) { + else if(do_io == 1 && strsame(type, "io") == 0) { if(words < 3) { - error("%s line of /proc/net/rpc/nfsd has %u words, expected %d", type, words, 3); + error("%s line of /proc/net/rpc/nfsd has %zu words, expected %d", type, words, 3); continue; } @@ -312,9 +312,9 @@ int do_proc_net_rpc_nfsd(int update_every, usec_t dt) { if(sum == 0ULL) do_io = -1; else do_io = 2; } - else if(do_th == 1 && strcmp(type, "th") == 0) { + else if(do_th == 1 && strsame(type, "th") == 0) { if(words < 13) { - error("%s line of /proc/net/rpc/nfsd has %u words, expected %d", type, words, 13); + error("%s line of /proc/net/rpc/nfsd has %zu words, expected %d", type, words, 13); continue; } @@ -343,9 +343,9 @@ int do_proc_net_rpc_nfsd(int update_every, usec_t dt) { } else do_th = 2; } - else if(do_ra == 1 && strcmp(type, "ra") == 0) { + else if(do_ra == 1 && strsame(type, "ra") == 0) { if(words < 13) { - error("%s line of /proc/net/rpc/nfsd has %u words, expected %d", type, words, 13); + error("%s line of /proc/net/rpc/nfsd has %zu words, expected %d", type, words, 13); continue; } @@ -372,9 +372,9 @@ int do_proc_net_rpc_nfsd(int update_every, usec_t dt) { } else do_ra = 2; } - else if(do_net == 1 && strcmp(type, "net") == 0) { + else if(do_net == 1 && strsame(type, "net") == 0) { if(words < 5) { - error("%s line of /proc/net/rpc/nfsd has %u words, expected %d", type, words, 5); + error("%s line of /proc/net/rpc/nfsd has %zu words, expected %d", type, words, 5); continue; } @@ -387,9 +387,9 @@ int do_proc_net_rpc_nfsd(int update_every, usec_t dt) { if(sum == 0ULL) do_net = -1; else do_net = 2; } - else if(do_rpc == 1 && strcmp(type, "rpc") == 0) { + else if(do_rpc == 1 && strsame(type, "rpc") == 0) { if(words < 6) { - error("%s line of /proc/net/rpc/nfsd has %u words, expected %d", type, words, 6); + error("%s line of /proc/net/rpc/nfsd has %zu words, expected %d", type, words, 6); continue; } @@ -402,7 +402,7 @@ int do_proc_net_rpc_nfsd(int update_every, usec_t dt) { if(sum == 0ULL) do_rpc = -1; else do_rpc = 2; } - else if(do_proc2 == 1 && strcmp(type, "proc2") == 0) { + else if(do_proc2 == 1 && strsame(type, "proc2") == 0) { // the first number is the count of numbers present // so we start for word 2 @@ -423,7 +423,7 @@ int do_proc_net_rpc_nfsd(int update_every, usec_t dt) { } else do_proc2 = 2; } - else if(do_proc3 == 1 && strcmp(type, "proc3") == 0) { + else if(do_proc3 == 1 && strsame(type, "proc3") == 0) { // the first number is the count of numbers present // so we start for word 2 @@ -444,7 +444,7 @@ int do_proc_net_rpc_nfsd(int update_every, usec_t dt) { } else do_proc3 = 2; } - else if(do_proc4 == 1 && strcmp(type, "proc4") == 0) { + else if(do_proc4 == 1 && strsame(type, "proc4") == 0) { // the first number is the count of numbers present // so we start for word 2 @@ -465,7 +465,7 @@ int do_proc_net_rpc_nfsd(int update_every, usec_t dt) { } else do_proc4 = 2; } - else if(do_proc4ops == 1 && strcmp(type, "proc4ops") == 0) { + else if(do_proc4ops == 1 && strsame(type, "proc4ops") == 0) { // the first number is the count of numbers present // so we start for word 2 diff --git a/src/proc_net_snmp.c b/src/proc_net_snmp.c index 821f670c..ffcd282a 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; } diff --git a/src/proc_net_snmp6.c b/src/proc_net_snmp6.c index 3812c5af..34bbb7f3 100644 --- a/src/proc_net_snmp6.c +++ b/src/proc_net_snmp6.c @@ -1,7 +1,6 @@ #include "common.h" #define RRD_TYPE_NET_SNMP6 "ipv6" -#define RRD_TYPE_NET_SNMP6_LEN strlen(RRD_TYPE_NET_SNMP6) int do_proc_net_snmp6(int update_every, usec_t dt) { (void)dt; @@ -252,7 +251,7 @@ int do_proc_net_snmp6(int update_every, usec_t dt) { 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; + size_t lines = procfile_lines(ff), l; unsigned long long Ip6InReceives = 0ULL; unsigned long long Ip6InHdrErrors = 0ULL; @@ -350,9 +349,9 @@ int do_proc_net_snmp6(int update_every, usec_t dt) { unsigned long long *ptr = NULL; for(l = 0; l < lines ;l++) { - uint32_t words = procfile_linewords(ff, l); + size_t words = procfile_linewords(ff, l); if(unlikely(words < 2)) { - if(unlikely(words)) error("Cannot read /proc/net/snmp6 line %u. Expected 2 params, read %u.", l, words); + if(unlikely(words)) error("Cannot read /proc/net/snmp6 line %zu. Expected 2 params, read %zu.", l, words); continue; } @@ -363,98 +362,98 @@ int do_proc_net_snmp6(int update_every, usec_t dt) { uint32_t hash = simple_hash(name); - if(unlikely(hash == hash_Ip6InReceives && strcmp(name, "Ip6InReceives") == 0)) ptr = &Ip6InReceives; - else if(unlikely(hash == hash_Ip6InHdrErrors && strcmp(name, "Ip6InHdrErrors") == 0)) ptr = &Ip6InHdrErrors; - else if(unlikely(hash == hash_Ip6InTooBigErrors && strcmp(name, "Ip6InTooBigErrors") == 0)) ptr = &Ip6InTooBigErrors; - else if(unlikely(hash == hash_Ip6InNoRoutes && strcmp(name, "Ip6InNoRoutes") == 0)) ptr = &Ip6InNoRoutes; - else if(unlikely(hash == hash_Ip6InAddrErrors && strcmp(name, "Ip6InAddrErrors") == 0)) ptr = &Ip6InAddrErrors; - else if(unlikely(hash == hash_Ip6InUnknownProtos && strcmp(name, "Ip6InUnknownProtos") == 0)) ptr = &Ip6InUnknownProtos; - else if(unlikely(hash == hash_Ip6InTruncatedPkts && strcmp(name, "Ip6InTruncatedPkts") == 0)) ptr = &Ip6InTruncatedPkts; - else if(unlikely(hash == hash_Ip6InDiscards && strcmp(name, "Ip6InDiscards") == 0)) ptr = &Ip6InDiscards; - else if(unlikely(hash == hash_Ip6InDelivers && strcmp(name, "Ip6InDelivers") == 0)) ptr = &Ip6InDelivers; - else if(unlikely(hash == hash_Ip6OutForwDatagrams && strcmp(name, "Ip6OutForwDatagrams") == 0)) ptr = &Ip6OutForwDatagrams; - else if(unlikely(hash == hash_Ip6OutRequests && strcmp(name, "Ip6OutRequests") == 0)) ptr = &Ip6OutRequests; - else if(unlikely(hash == hash_Ip6OutDiscards && strcmp(name, "Ip6OutDiscards") == 0)) ptr = &Ip6OutDiscards; - else if(unlikely(hash == hash_Ip6OutNoRoutes && strcmp(name, "Ip6OutNoRoutes") == 0)) ptr = &Ip6OutNoRoutes; - else if(unlikely(hash == hash_Ip6ReasmTimeout && strcmp(name, "Ip6ReasmTimeout") == 0)) ptr = &Ip6ReasmTimeout; - else if(unlikely(hash == hash_Ip6ReasmReqds && strcmp(name, "Ip6ReasmReqds") == 0)) ptr = &Ip6ReasmReqds; - else if(unlikely(hash == hash_Ip6ReasmOKs && strcmp(name, "Ip6ReasmOKs") == 0)) ptr = &Ip6ReasmOKs; - else if(unlikely(hash == hash_Ip6ReasmFails && strcmp(name, "Ip6ReasmFails") == 0)) ptr = &Ip6ReasmFails; - else if(unlikely(hash == hash_Ip6FragOKs && strcmp(name, "Ip6FragOKs") == 0)) ptr = &Ip6FragOKs; - else if(unlikely(hash == hash_Ip6FragFails && strcmp(name, "Ip6FragFails") == 0)) ptr = &Ip6FragFails; - else if(unlikely(hash == hash_Ip6FragCreates && strcmp(name, "Ip6FragCreates") == 0)) ptr = &Ip6FragCreates; - else if(unlikely(hash == hash_Ip6InMcastPkts && strcmp(name, "Ip6InMcastPkts") == 0)) ptr = &Ip6InMcastPkts; - else if(unlikely(hash == hash_Ip6OutMcastPkts && strcmp(name, "Ip6OutMcastPkts") == 0)) ptr = &Ip6OutMcastPkts; - else if(unlikely(hash == hash_Ip6InOctets && strcmp(name, "Ip6InOctets") == 0)) ptr = &Ip6InOctets; - else if(unlikely(hash == hash_Ip6OutOctets && strcmp(name, "Ip6OutOctets") == 0)) ptr = &Ip6OutOctets; - else if(unlikely(hash == hash_Ip6InMcastOctets && strcmp(name, "Ip6InMcastOctets") == 0)) ptr = &Ip6InMcastOctets; - else if(unlikely(hash == hash_Ip6OutMcastOctets && strcmp(name, "Ip6OutMcastOctets") == 0)) ptr = &Ip6OutMcastOctets; - else if(unlikely(hash == hash_Ip6InBcastOctets && strcmp(name, "Ip6InBcastOctets") == 0)) ptr = &Ip6InBcastOctets; - else if(unlikely(hash == hash_Ip6OutBcastOctets && strcmp(name, "Ip6OutBcastOctets") == 0)) ptr = &Ip6OutBcastOctets; - else if(unlikely(hash == hash_Ip6InNoECTPkts && strcmp(name, "Ip6InNoECTPkts") == 0)) ptr = &Ip6InNoECTPkts; - else if(unlikely(hash == hash_Ip6InECT1Pkts && strcmp(name, "Ip6InECT1Pkts") == 0)) ptr = &Ip6InECT1Pkts; - else if(unlikely(hash == hash_Ip6InECT0Pkts && strcmp(name, "Ip6InECT0Pkts") == 0)) ptr = &Ip6InECT0Pkts; - else if(unlikely(hash == hash_Ip6InCEPkts && strcmp(name, "Ip6InCEPkts") == 0)) ptr = &Ip6InCEPkts; - else if(unlikely(hash == hash_Icmp6InMsgs && strcmp(name, "Icmp6InMsgs") == 0)) ptr = &Icmp6InMsgs; - else if(unlikely(hash == hash_Icmp6InErrors && strcmp(name, "Icmp6InErrors") == 0)) ptr = &Icmp6InErrors; - else if(unlikely(hash == hash_Icmp6OutMsgs && strcmp(name, "Icmp6OutMsgs") == 0)) ptr = &Icmp6OutMsgs; - else if(unlikely(hash == hash_Icmp6OutErrors && strcmp(name, "Icmp6OutErrors") == 0)) ptr = &Icmp6OutErrors; - else if(unlikely(hash == hash_Icmp6InCsumErrors && strcmp(name, "Icmp6InCsumErrors") == 0)) ptr = &Icmp6InCsumErrors; - else if(unlikely(hash == hash_Icmp6InDestUnreachs && strcmp(name, "Icmp6InDestUnreachs") == 0)) ptr = &Icmp6InDestUnreachs; - else if(unlikely(hash == hash_Icmp6InPktTooBigs && strcmp(name, "Icmp6InPktTooBigs") == 0)) ptr = &Icmp6InPktTooBigs; - else if(unlikely(hash == hash_Icmp6InTimeExcds && strcmp(name, "Icmp6InTimeExcds") == 0)) ptr = &Icmp6InTimeExcds; - else if(unlikely(hash == hash_Icmp6InParmProblems && strcmp(name, "Icmp6InParmProblems") == 0)) ptr = &Icmp6InParmProblems; - else if(unlikely(hash == hash_Icmp6InEchos && strcmp(name, "Icmp6InEchos") == 0)) ptr = &Icmp6InEchos; - else if(unlikely(hash == hash_Icmp6InEchoReplies && strcmp(name, "Icmp6InEchoReplies") == 0)) ptr = &Icmp6InEchoReplies; - else if(unlikely(hash == hash_Icmp6InGroupMembQueries && strcmp(name, "Icmp6InGroupMembQueries") == 0)) ptr = &Icmp6InGroupMembQueries; - else if(unlikely(hash == hash_Icmp6InGroupMembResponses && strcmp(name, "Icmp6InGroupMembResponses") == 0)) ptr = &Icmp6InGroupMembResponses; - else if(unlikely(hash == hash_Icmp6InGroupMembReductions && strcmp(name, "Icmp6InGroupMembReductions") == 0)) ptr = &Icmp6InGroupMembReductions; - else if(unlikely(hash == hash_Icmp6InRouterSolicits && strcmp(name, "Icmp6InRouterSolicits") == 0)) ptr = &Icmp6InRouterSolicits; - else if(unlikely(hash == hash_Icmp6InRouterAdvertisements && strcmp(name, "Icmp6InRouterAdvertisements") == 0)) ptr = &Icmp6InRouterAdvertisements; - else if(unlikely(hash == hash_Icmp6InNeighborSolicits && strcmp(name, "Icmp6InNeighborSolicits") == 0)) ptr = &Icmp6InNeighborSolicits; - else if(unlikely(hash == hash_Icmp6InNeighborAdvertisements && strcmp(name, "Icmp6InNeighborAdvertisements") == 0)) ptr = &Icmp6InNeighborAdvertisements; - else if(unlikely(hash == hash_Icmp6InRedirects && strcmp(name, "Icmp6InRedirects") == 0)) ptr = &Icmp6InRedirects; - else if(unlikely(hash == hash_Icmp6InMLDv2Reports && strcmp(name, "Icmp6InMLDv2Reports") == 0)) ptr = &Icmp6InMLDv2Reports; - else if(unlikely(hash == hash_Icmp6OutDestUnreachs && strcmp(name, "Icmp6OutDestUnreachs") == 0)) ptr = &Icmp6OutDestUnreachs; - else if(unlikely(hash == hash_Icmp6OutPktTooBigs && strcmp(name, "Icmp6OutPktTooBigs") == 0)) ptr = &Icmp6OutPktTooBigs; - else if(unlikely(hash == hash_Icmp6OutTimeExcds && strcmp(name, "Icmp6OutTimeExcds") == 0)) ptr = &Icmp6OutTimeExcds; - else if(unlikely(hash == hash_Icmp6OutParmProblems && strcmp(name, "Icmp6OutParmProblems") == 0)) ptr = &Icmp6OutParmProblems; - else if(unlikely(hash == hash_Icmp6OutEchos && strcmp(name, "Icmp6OutEchos") == 0)) ptr = &Icmp6OutEchos; - else if(unlikely(hash == hash_Icmp6OutEchoReplies && strcmp(name, "Icmp6OutEchoReplies") == 0)) ptr = &Icmp6OutEchoReplies; - else if(unlikely(hash == hash_Icmp6OutGroupMembQueries && strcmp(name, "Icmp6OutGroupMembQueries") == 0)) ptr = &Icmp6OutGroupMembQueries; - else if(unlikely(hash == hash_Icmp6OutGroupMembResponses && strcmp(name, "Icmp6OutGroupMembResponses") == 0)) ptr = &Icmp6OutGroupMembResponses; - else if(unlikely(hash == hash_Icmp6OutGroupMembReductions && strcmp(name, "Icmp6OutGroupMembReductions") == 0)) ptr = &Icmp6OutGroupMembReductions; - else if(unlikely(hash == hash_Icmp6OutRouterSolicits && strcmp(name, "Icmp6OutRouterSolicits") == 0)) ptr = &Icmp6OutRouterSolicits; - else if(unlikely(hash == hash_Icmp6OutRouterAdvertisements && strcmp(name, "Icmp6OutRouterAdvertisements") == 0)) ptr = &Icmp6OutRouterAdvertisements; - else if(unlikely(hash == hash_Icmp6OutNeighborSolicits && strcmp(name, "Icmp6OutNeighborSolicits") == 0)) ptr = &Icmp6OutNeighborSolicits; - else if(unlikely(hash == hash_Icmp6OutNeighborAdvertisements && strcmp(name, "Icmp6OutNeighborAdvertisements") == 0)) ptr = &Icmp6OutNeighborAdvertisements; - else if(unlikely(hash == hash_Icmp6OutRedirects && strcmp(name, "Icmp6OutRedirects") == 0)) ptr = &Icmp6OutRedirects; - else if(unlikely(hash == hash_Icmp6OutMLDv2Reports && strcmp(name, "Icmp6OutMLDv2Reports") == 0)) ptr = &Icmp6OutMLDv2Reports; - else if(unlikely(hash == hash_Icmp6InType1 && strcmp(name, "Icmp6InType1") == 0)) ptr = &Icmp6InType1; - else if(unlikely(hash == hash_Icmp6InType128 && strcmp(name, "Icmp6InType128") == 0)) ptr = &Icmp6InType128; - else if(unlikely(hash == hash_Icmp6InType129 && strcmp(name, "Icmp6InType129") == 0)) ptr = &Icmp6InType129; - else if(unlikely(hash == hash_Icmp6InType136 && strcmp(name, "Icmp6InType136") == 0)) ptr = &Icmp6InType136; - else if(unlikely(hash == hash_Icmp6OutType1 && strcmp(name, "Icmp6OutType1") == 0)) ptr = &Icmp6OutType1; - else if(unlikely(hash == hash_Icmp6OutType128 && strcmp(name, "Icmp6OutType128") == 0)) ptr = &Icmp6OutType128; - else if(unlikely(hash == hash_Icmp6OutType129 && strcmp(name, "Icmp6OutType129") == 0)) ptr = &Icmp6OutType129; - else if(unlikely(hash == hash_Icmp6OutType133 && strcmp(name, "Icmp6OutType133") == 0)) ptr = &Icmp6OutType133; - else if(unlikely(hash == hash_Icmp6OutType135 && strcmp(name, "Icmp6OutType135") == 0)) ptr = &Icmp6OutType135; - else if(unlikely(hash == hash_Icmp6OutType143 && strcmp(name, "Icmp6OutType143") == 0)) ptr = &Icmp6OutType143; - else if(unlikely(hash == hash_Udp6InDatagrams && strcmp(name, "Udp6InDatagrams") == 0)) ptr = &Udp6InDatagrams; - else if(unlikely(hash == hash_Udp6NoPorts && strcmp(name, "Udp6NoPorts") == 0)) ptr = &Udp6NoPorts; - else if(unlikely(hash == hash_Udp6InErrors && strcmp(name, "Udp6InErrors") == 0)) ptr = &Udp6InErrors; - else if(unlikely(hash == hash_Udp6OutDatagrams && strcmp(name, "Udp6OutDatagrams") == 0)) ptr = &Udp6OutDatagrams; - else if(unlikely(hash == hash_Udp6RcvbufErrors && strcmp(name, "Udp6RcvbufErrors") == 0)) ptr = &Udp6RcvbufErrors; - else if(unlikely(hash == hash_Udp6SndbufErrors && strcmp(name, "Udp6SndbufErrors") == 0)) ptr = &Udp6SndbufErrors; - else if(unlikely(hash == hash_Udp6InCsumErrors && strcmp(name, "Udp6InCsumErrors") == 0)) ptr = &Udp6InCsumErrors; - else if(unlikely(hash == hash_Udp6IgnoredMulti && strcmp(name, "Udp6IgnoredMulti") == 0)) ptr = &Udp6IgnoredMulti; - else if(unlikely(hash == hash_UdpLite6InDatagrams && strcmp(name, "UdpLite6InDatagrams") == 0)) ptr = &UdpLite6InDatagrams; - else if(unlikely(hash == hash_UdpLite6NoPorts && strcmp(name, "UdpLite6NoPorts") == 0)) ptr = &UdpLite6NoPorts; - else if(unlikely(hash == hash_UdpLite6InErrors && strcmp(name, "UdpLite6InErrors") == 0)) ptr = &UdpLite6InErrors; - else if(unlikely(hash == hash_UdpLite6OutDatagrams && strcmp(name, "UdpLite6OutDatagrams") == 0)) ptr = &UdpLite6OutDatagrams; - else if(unlikely(hash == hash_UdpLite6RcvbufErrors && strcmp(name, "UdpLite6RcvbufErrors") == 0)) ptr = &UdpLite6RcvbufErrors; - else if(unlikely(hash == hash_UdpLite6SndbufErrors && strcmp(name, "UdpLite6SndbufErrors") == 0)) ptr = &UdpLite6SndbufErrors; - else if(unlikely(hash == hash_UdpLite6InCsumErrors && strcmp(name, "UdpLite6InCsumErrors") == 0)) ptr = &UdpLite6InCsumErrors; + if(unlikely(hash == hash_Ip6InReceives && strsame(name, "Ip6InReceives") == 0)) ptr = &Ip6InReceives; + else if(unlikely(hash == hash_Ip6InHdrErrors && strsame(name, "Ip6InHdrErrors") == 0)) ptr = &Ip6InHdrErrors; + else if(unlikely(hash == hash_Ip6InTooBigErrors && strsame(name, "Ip6InTooBigErrors") == 0)) ptr = &Ip6InTooBigErrors; + else if(unlikely(hash == hash_Ip6InNoRoutes && strsame(name, "Ip6InNoRoutes") == 0)) ptr = &Ip6InNoRoutes; + else if(unlikely(hash == hash_Ip6InAddrErrors && strsame(name, "Ip6InAddrErrors") == 0)) ptr = &Ip6InAddrErrors; + else if(unlikely(hash == hash_Ip6InUnknownProtos && strsame(name, "Ip6InUnknownProtos") == 0)) ptr = &Ip6InUnknownProtos; + else if(unlikely(hash == hash_Ip6InTruncatedPkts && strsame(name, "Ip6InTruncatedPkts") == 0)) ptr = &Ip6InTruncatedPkts; + else if(unlikely(hash == hash_Ip6InDiscards && strsame(name, "Ip6InDiscards") == 0)) ptr = &Ip6InDiscards; + else if(unlikely(hash == hash_Ip6InDelivers && strsame(name, "Ip6InDelivers") == 0)) ptr = &Ip6InDelivers; + else if(unlikely(hash == hash_Ip6OutForwDatagrams && strsame(name, "Ip6OutForwDatagrams") == 0)) ptr = &Ip6OutForwDatagrams; + else if(unlikely(hash == hash_Ip6OutRequests && strsame(name, "Ip6OutRequests") == 0)) ptr = &Ip6OutRequests; + else if(unlikely(hash == hash_Ip6OutDiscards && strsame(name, "Ip6OutDiscards") == 0)) ptr = &Ip6OutDiscards; + else if(unlikely(hash == hash_Ip6OutNoRoutes && strsame(name, "Ip6OutNoRoutes") == 0)) ptr = &Ip6OutNoRoutes; + else if(unlikely(hash == hash_Ip6ReasmTimeout && strsame(name, "Ip6ReasmTimeout") == 0)) ptr = &Ip6ReasmTimeout; + else if(unlikely(hash == hash_Ip6ReasmReqds && strsame(name, "Ip6ReasmReqds") == 0)) ptr = &Ip6ReasmReqds; + else if(unlikely(hash == hash_Ip6ReasmOKs && strsame(name, "Ip6ReasmOKs") == 0)) ptr = &Ip6ReasmOKs; + else if(unlikely(hash == hash_Ip6ReasmFails && strsame(name, "Ip6ReasmFails") == 0)) ptr = &Ip6ReasmFails; + else if(unlikely(hash == hash_Ip6FragOKs && strsame(name, "Ip6FragOKs") == 0)) ptr = &Ip6FragOKs; + else if(unlikely(hash == hash_Ip6FragFails && strsame(name, "Ip6FragFails") == 0)) ptr = &Ip6FragFails; + else if(unlikely(hash == hash_Ip6FragCreates && strsame(name, "Ip6FragCreates") == 0)) ptr = &Ip6FragCreates; + else if(unlikely(hash == hash_Ip6InMcastPkts && strsame(name, "Ip6InMcastPkts") == 0)) ptr = &Ip6InMcastPkts; + else if(unlikely(hash == hash_Ip6OutMcastPkts && strsame(name, "Ip6OutMcastPkts") == 0)) ptr = &Ip6OutMcastPkts; + else if(unlikely(hash == hash_Ip6InOctets && strsame(name, "Ip6InOctets") == 0)) ptr = &Ip6InOctets; + else if(unlikely(hash == hash_Ip6OutOctets && strsame(name, "Ip6OutOctets") == 0)) ptr = &Ip6OutOctets; + else if(unlikely(hash == hash_Ip6InMcastOctets && strsame(name, "Ip6InMcastOctets") == 0)) ptr = &Ip6InMcastOctets; + else if(unlikely(hash == hash_Ip6OutMcastOctets && strsame(name, "Ip6OutMcastOctets") == 0)) ptr = &Ip6OutMcastOctets; + else if(unlikely(hash == hash_Ip6InBcastOctets && strsame(name, "Ip6InBcastOctets") == 0)) ptr = &Ip6InBcastOctets; + else if(unlikely(hash == hash_Ip6OutBcastOctets && strsame(name, "Ip6OutBcastOctets") == 0)) ptr = &Ip6OutBcastOctets; + else if(unlikely(hash == hash_Ip6InNoECTPkts && strsame(name, "Ip6InNoECTPkts") == 0)) ptr = &Ip6InNoECTPkts; + else if(unlikely(hash == hash_Ip6InECT1Pkts && strsame(name, "Ip6InECT1Pkts") == 0)) ptr = &Ip6InECT1Pkts; + else if(unlikely(hash == hash_Ip6InECT0Pkts && strsame(name, "Ip6InECT0Pkts") == 0)) ptr = &Ip6InECT0Pkts; + else if(unlikely(hash == hash_Ip6InCEPkts && strsame(name, "Ip6InCEPkts") == 0)) ptr = &Ip6InCEPkts; + else if(unlikely(hash == hash_Icmp6InMsgs && strsame(name, "Icmp6InMsgs") == 0)) ptr = &Icmp6InMsgs; + else if(unlikely(hash == hash_Icmp6InErrors && strsame(name, "Icmp6InErrors") == 0)) ptr = &Icmp6InErrors; + else if(unlikely(hash == hash_Icmp6OutMsgs && strsame(name, "Icmp6OutMsgs") == 0)) ptr = &Icmp6OutMsgs; + else if(unlikely(hash == hash_Icmp6OutErrors && strsame(name, "Icmp6OutErrors") == 0)) ptr = &Icmp6OutErrors; + else if(unlikely(hash == hash_Icmp6InCsumErrors && strsame(name, "Icmp6InCsumErrors") == 0)) ptr = &Icmp6InCsumErrors; + else if(unlikely(hash == hash_Icmp6InDestUnreachs && strsame(name, "Icmp6InDestUnreachs") == 0)) ptr = &Icmp6InDestUnreachs; + else if(unlikely(hash == hash_Icmp6InPktTooBigs && strsame(name, "Icmp6InPktTooBigs") == 0)) ptr = &Icmp6InPktTooBigs; + else if(unlikely(hash == hash_Icmp6InTimeExcds && strsame(name, "Icmp6InTimeExcds") == 0)) ptr = &Icmp6InTimeExcds; + else if(unlikely(hash == hash_Icmp6InParmProblems && strsame(name, "Icmp6InParmProblems") == 0)) ptr = &Icmp6InParmProblems; + else if(unlikely(hash == hash_Icmp6InEchos && strsame(name, "Icmp6InEchos") == 0)) ptr = &Icmp6InEchos; + else if(unlikely(hash == hash_Icmp6InEchoReplies && strsame(name, "Icmp6InEchoReplies") == 0)) ptr = &Icmp6InEchoReplies; + else if(unlikely(hash == hash_Icmp6InGroupMembQueries && strsame(name, "Icmp6InGroupMembQueries") == 0)) ptr = &Icmp6InGroupMembQueries; + else if(unlikely(hash == hash_Icmp6InGroupMembResponses && strsame(name, "Icmp6InGroupMembResponses") == 0)) ptr = &Icmp6InGroupMembResponses; + else if(unlikely(hash == hash_Icmp6InGroupMembReductions && strsame(name, "Icmp6InGroupMembReductions") == 0)) ptr = &Icmp6InGroupMembReductions; + else if(unlikely(hash == hash_Icmp6InRouterSolicits && strsame(name, "Icmp6InRouterSolicits") == 0)) ptr = &Icmp6InRouterSolicits; + else if(unlikely(hash == hash_Icmp6InRouterAdvertisements && strsame(name, "Icmp6InRouterAdvertisements") == 0)) ptr = &Icmp6InRouterAdvertisements; + else if(unlikely(hash == hash_Icmp6InNeighborSolicits && strsame(name, "Icmp6InNeighborSolicits") == 0)) ptr = &Icmp6InNeighborSolicits; + else if(unlikely(hash == hash_Icmp6InNeighborAdvertisements && strsame(name, "Icmp6InNeighborAdvertisements") == 0)) ptr = &Icmp6InNeighborAdvertisements; + else if(unlikely(hash == hash_Icmp6InRedirects && strsame(name, "Icmp6InRedirects") == 0)) ptr = &Icmp6InRedirects; + else if(unlikely(hash == hash_Icmp6InMLDv2Reports && strsame(name, "Icmp6InMLDv2Reports") == 0)) ptr = &Icmp6InMLDv2Reports; + else if(unlikely(hash == hash_Icmp6OutDestUnreachs && strsame(name, "Icmp6OutDestUnreachs") == 0)) ptr = &Icmp6OutDestUnreachs; + else if(unlikely(hash == hash_Icmp6OutPktTooBigs && strsame(name, "Icmp6OutPktTooBigs") == 0)) ptr = &Icmp6OutPktTooBigs; + else if(unlikely(hash == hash_Icmp6OutTimeExcds && strsame(name, "Icmp6OutTimeExcds") == 0)) ptr = &Icmp6OutTimeExcds; + else if(unlikely(hash == hash_Icmp6OutParmProblems && strsame(name, "Icmp6OutParmProblems") == 0)) ptr = &Icmp6OutParmProblems; + else if(unlikely(hash == hash_Icmp6OutEchos && strsame(name, "Icmp6OutEchos") == 0)) ptr = &Icmp6OutEchos; + else if(unlikely(hash == hash_Icmp6OutEchoReplies && strsame(name, "Icmp6OutEchoReplies") == 0)) ptr = &Icmp6OutEchoReplies; + else if(unlikely(hash == hash_Icmp6OutGroupMembQueries && strsame(name, "Icmp6OutGroupMembQueries") == 0)) ptr = &Icmp6OutGroupMembQueries; + else if(unlikely(hash == hash_Icmp6OutGroupMembResponses && strsame(name, "Icmp6OutGroupMembResponses") == 0)) ptr = &Icmp6OutGroupMembResponses; + else if(unlikely(hash == hash_Icmp6OutGroupMembReductions && strsame(name, "Icmp6OutGroupMembReductions") == 0)) ptr = &Icmp6OutGroupMembReductions; + else if(unlikely(hash == hash_Icmp6OutRouterSolicits && strsame(name, "Icmp6OutRouterSolicits") == 0)) ptr = &Icmp6OutRouterSolicits; + else if(unlikely(hash == hash_Icmp6OutRouterAdvertisements && strsame(name, "Icmp6OutRouterAdvertisements") == 0)) ptr = &Icmp6OutRouterAdvertisements; + else if(unlikely(hash == hash_Icmp6OutNeighborSolicits && strsame(name, "Icmp6OutNeighborSolicits") == 0)) ptr = &Icmp6OutNeighborSolicits; + else if(unlikely(hash == hash_Icmp6OutNeighborAdvertisements && strsame(name, "Icmp6OutNeighborAdvertisements") == 0)) ptr = &Icmp6OutNeighborAdvertisements; + else if(unlikely(hash == hash_Icmp6OutRedirects && strsame(name, "Icmp6OutRedirects") == 0)) ptr = &Icmp6OutRedirects; + else if(unlikely(hash == hash_Icmp6OutMLDv2Reports && strsame(name, "Icmp6OutMLDv2Reports") == 0)) ptr = &Icmp6OutMLDv2Reports; + else if(unlikely(hash == hash_Icmp6InType1 && strsame(name, "Icmp6InType1") == 0)) ptr = &Icmp6InType1; + else if(unlikely(hash == hash_Icmp6InType128 && strsame(name, "Icmp6InType128") == 0)) ptr = &Icmp6InType128; + else if(unlikely(hash == hash_Icmp6InType129 && strsame(name, "Icmp6InType129") == 0)) ptr = &Icmp6InType129; + else if(unlikely(hash == hash_Icmp6InType136 && strsame(name, "Icmp6InType136") == 0)) ptr = &Icmp6InType136; + else if(unlikely(hash == hash_Icmp6OutType1 && strsame(name, "Icmp6OutType1") == 0)) ptr = &Icmp6OutType1; + else if(unlikely(hash == hash_Icmp6OutType128 && strsame(name, "Icmp6OutType128") == 0)) ptr = &Icmp6OutType128; + else if(unlikely(hash == hash_Icmp6OutType129 && strsame(name, "Icmp6OutType129") == 0)) ptr = &Icmp6OutType129; + else if(unlikely(hash == hash_Icmp6OutType133 && strsame(name, "Icmp6OutType133") == 0)) ptr = &Icmp6OutType133; + else if(unlikely(hash == hash_Icmp6OutType135 && strsame(name, "Icmp6OutType135") == 0)) ptr = &Icmp6OutType135; + else if(unlikely(hash == hash_Icmp6OutType143 && strsame(name, "Icmp6OutType143") == 0)) ptr = &Icmp6OutType143; + else if(unlikely(hash == hash_Udp6InDatagrams && strsame(name, "Udp6InDatagrams") == 0)) ptr = &Udp6InDatagrams; + else if(unlikely(hash == hash_Udp6NoPorts && strsame(name, "Udp6NoPorts") == 0)) ptr = &Udp6NoPorts; + else if(unlikely(hash == hash_Udp6InErrors && strsame(name, "Udp6InErrors") == 0)) ptr = &Udp6InErrors; + else if(unlikely(hash == hash_Udp6OutDatagrams && strsame(name, "Udp6OutDatagrams") == 0)) ptr = &Udp6OutDatagrams; + else if(unlikely(hash == hash_Udp6RcvbufErrors && strsame(name, "Udp6RcvbufErrors") == 0)) ptr = &Udp6RcvbufErrors; + else if(unlikely(hash == hash_Udp6SndbufErrors && strsame(name, "Udp6SndbufErrors") == 0)) ptr = &Udp6SndbufErrors; + else if(unlikely(hash == hash_Udp6InCsumErrors && strsame(name, "Udp6InCsumErrors") == 0)) ptr = &Udp6InCsumErrors; + else if(unlikely(hash == hash_Udp6IgnoredMulti && strsame(name, "Udp6IgnoredMulti") == 0)) ptr = &Udp6IgnoredMulti; + else if(unlikely(hash == hash_UdpLite6InDatagrams && strsame(name, "UdpLite6InDatagrams") == 0)) ptr = &UdpLite6InDatagrams; + else if(unlikely(hash == hash_UdpLite6NoPorts && strsame(name, "UdpLite6NoPorts") == 0)) ptr = &UdpLite6NoPorts; + else if(unlikely(hash == hash_UdpLite6InErrors && strsame(name, "UdpLite6InErrors") == 0)) ptr = &UdpLite6InErrors; + else if(unlikely(hash == hash_UdpLite6OutDatagrams && strsame(name, "UdpLite6OutDatagrams") == 0)) ptr = &UdpLite6OutDatagrams; + else if(unlikely(hash == hash_UdpLite6RcvbufErrors && strsame(name, "UdpLite6RcvbufErrors") == 0)) ptr = &UdpLite6RcvbufErrors; + else if(unlikely(hash == hash_UdpLite6SndbufErrors && strsame(name, "UdpLite6SndbufErrors") == 0)) ptr = &UdpLite6SndbufErrors; + else if(unlikely(hash == hash_UdpLite6InCsumErrors && strsame(name, "UdpLite6InCsumErrors") == 0)) ptr = &UdpLite6InCsumErrors; if(unlikely(ptr)) { *ptr = str2ull(value); diff --git a/src/proc_net_softnet_stat.c b/src/proc_net_softnet_stat.c index 4a6b4114..2f4eb3e6 100644 --- a/src/proc_net_softnet_stat.c +++ b/src/proc_net_softnet_stat.c @@ -1,6 +1,6 @@ #include "common.h" -static inline char *softnet_column_name(uint32_t column) { +static inline char *softnet_column_name(size_t column) { switch(column) { // https://github.com/torvalds/linux/blob/a7fd20d1c476af4563e66865213474a2f9f473a4/net/core/net-procfs.c#L161-L166 case 0: return "processed"; @@ -17,7 +17,8 @@ int do_proc_net_softnet_stat(int update_every, usec_t dt) { static procfile *ff = NULL; static int do_per_core = -1; - static uint32_t allocated_lines = 0, allocated_columns = 0, *data = NULL; + static size_t allocated_lines = 0, allocated_columns = 0; + static uint32_t *data = NULL; if(unlikely(do_per_core == -1)) do_per_core = config_get_boolean("plugin:proc:/proc/net/softnet_stat", "softnet_stat per core", 1); @@ -31,11 +32,11 @@ int do_proc_net_softnet_stat(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 = procfile_linewords(ff, 0), w; + size_t lines = procfile_lines(ff), l; + size_t words = procfile_linewords(ff, 0), w; if(unlikely(!lines || !words)) { - error("Cannot read /proc/net/softnet_stat, %u lines and %u columns reported.", lines, words); + error("Cannot read /proc/net/softnet_stat, %zu lines and %zu columns reported.", lines, words); return 1; } @@ -94,12 +95,12 @@ int do_proc_net_softnet_stat(int update_every, usec_t dt) { if(do_per_core) { for(l = 0; l < lines ;l++) { char id[50+1]; - snprintfz(id, 50, "cpu%u_softnet_stat", l); + snprintfz(id, 50, "cpu%zu_softnet_stat", l); st = rrdset_find_bytype("cpu", id); if(unlikely(!st)) { char title[100+1]; - snprintfz(title, 100, "CPU%u softnet_stat", l); + snprintfz(title, 100, "CPU%zu softnet_stat", l); st = rrdset_create("cpu", id, NULL, "softnet_stat", NULL, title, "events/s", 4101 + l, update_every, RRDSET_TYPE_LINE); for(w = 0; w < allocated_columns ;w++) diff --git a/src/proc_net_stat_conntrack.c b/src/proc_net_stat_conntrack.c index 3ccc9626..b9c72498 100644 --- a/src/proc_net_stat_conntrack.c +++ b/src/proc_net_stat_conntrack.c @@ -61,12 +61,12 @@ int do_proc_net_stat_conntrack(int update_every, usec_t dt) { 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; + size_t lines = procfile_lines(ff), l; for(l = 1; l < lines ;l++) { - uint32_t words = procfile_linewords(ff, l); + size_t words = procfile_linewords(ff, l); if(unlikely(words < 17)) { - if(unlikely(words)) error("Cannot read /proc/net/stat/nf_conntrack line. Expected 17 params, read %u.", words); + if(unlikely(words)) error("Cannot read /proc/net/stat/nf_conntrack line. Expected 17 params, read %zu.", words); continue; } diff --git a/src/proc_net_stat_synproxy.c b/src/proc_net_stat_synproxy.c index c3ac00b5..6bb0a3c6 100644 --- a/src/proc_net_stat_synproxy.c +++ b/src/proc_net_stat_synproxy.c @@ -39,7 +39,7 @@ int do_proc_net_stat_synproxy(int update_every, usec_t dt) { // synproxy gives its values per CPU for(l = 1; l < lines ;l++) { - int words = procfile_linewords(ff, l); + size_t words = procfile_linewords(ff, l); if(unlikely(words < 6)) continue; diff --git a/src/proc_self_mountinfo.c b/src/proc_self_mountinfo.c index d07f2251..49755217 100644 --- a/src/proc_self_mountinfo.c +++ b/src/proc_self_mountinfo.c @@ -7,39 +7,39 @@ /* A file system is "remote" if its Fs_name contains a ':' or if (it is of type (smbfs or cifs) and its Fs_name starts with '//') or Fs_name is equal to "-hosts" (used by autofs to mount remote fs). */ -# define ME_REMOTE(Fs_name, Fs_type) \ - (strchr (Fs_name, ':') != NULL \ - || ((Fs_name)[0] == '/' \ - && (Fs_name)[1] == '/' \ - && (strcmp (Fs_type, "smbfs") == 0 \ - || strcmp (Fs_type, "cifs") == 0)) \ - || (strcmp("-hosts", Fs_name) == 0)) +# define ME_REMOTE(Fs_name, Fs_type) \ + (strchr (Fs_name, ':') != NULL \ + || ((Fs_name)[0] == '/' \ + && (Fs_name)[1] == '/' \ + && (strsame (Fs_type, "smbfs") == 0 \ + || strsame (Fs_type, "cifs") == 0)) \ + || (strsame("-hosts", Fs_name) == 0)) #endif -#define ME_DUMMY_0(Fs_name, Fs_type) \ - (strcmp (Fs_type, "autofs") == 0 \ - || strcmp (Fs_type, "proc") == 0 \ - || strcmp (Fs_type, "subfs") == 0 \ - /* for Linux 2.6/3.x */ \ - || strcmp (Fs_type, "debugfs") == 0 \ - || strcmp (Fs_type, "devpts") == 0 \ - || strcmp (Fs_type, "fusectl") == 0 \ - || strcmp (Fs_type, "mqueue") == 0 \ - || strcmp (Fs_type, "rpc_pipefs") == 0 \ - || strcmp (Fs_type, "sysfs") == 0 \ - /* FreeBSD, Linux 2.4 */ \ - || strcmp (Fs_type, "devfs") == 0 \ - /* for NetBSD 3.0 */ \ - || strcmp (Fs_type, "kernfs") == 0 \ - /* for Irix 6.5 */ \ - || strcmp (Fs_type, "ignore") == 0) +#define ME_DUMMY_0(Fs_name, Fs_type) \ + (strsame (Fs_type, "autofs") == 0 \ + || strsame (Fs_type, "proc") == 0 \ + || strsame (Fs_type, "subfs") == 0 \ + /* for Linux 2.6/3.x */ \ + || strsame (Fs_type, "debugfs") == 0 \ + || strsame (Fs_type, "devpts") == 0 \ + || strsame (Fs_type, "fusectl") == 0 \ + || strsame (Fs_type, "mqueue") == 0 \ + || strsame (Fs_type, "rpc_pipefs") == 0 \ + || strsame (Fs_type, "sysfs") == 0 \ + /* FreeBSD, Linux 2.4 */ \ + || strsame (Fs_type, "devfs") == 0 \ + /* for NetBSD 3.0 */ \ + || strsame (Fs_type, "kernfs") == 0 \ + /* for Irix 6.5 */ \ + || strsame (Fs_type, "ignore") == 0) /* Historically, we have marked as "dummy" any file system of type "none", but now that programs like du need to know about bind-mounted directories, we grant an exception to any with "bind" in its list of mount options. I.e., those are *not* dummy entries. */ # define ME_DUMMY(Fs_name, Fs_type) \ - (ME_DUMMY_0 (Fs_name, Fs_type) || strcmp (Fs_type, "none") == 0) + (ME_DUMMY_0 (Fs_name, Fs_type) || strsame (Fs_type, "none") == 0) // ---------------------------------------------------------------------------- @@ -66,8 +66,8 @@ struct mountinfo *mountinfo_find_by_filesystem_mount_source(struct mountinfo *ro && mi->mount_source && mi->filesystem_hash == filesystem_hash && mi->mount_source_hash == mount_source_hash - && !strcmp(mi->filesystem, filesystem) - && !strcmp(mi->mount_source, mount_source))) + && !strsame(mi->filesystem, filesystem) + && !strsame(mi->mount_source, mount_source))) return mi; return NULL; @@ -83,7 +83,7 @@ struct mountinfo *mountinfo_find_by_filesystem_super_option(struct mountinfo *ro if(unlikely(mi->filesystem && mi->super_options && mi->filesystem_hash == filesystem_hash - && !strcmp(mi->filesystem, filesystem))) { + && !strsame(mi->filesystem, filesystem))) { // super_options is a comma separated list char *s = mi->super_options, *e; @@ -163,7 +163,7 @@ static inline int is_read_only(const char *s) { size_t len = strlen(s); if(len < 2) return 0; if(len == 2) { - if(!strcmp(s, "ro")) return 1; + if(!strsame(s, "ro")) return 1; return 0; } if(!strncmp(s, "ro,", 3)) return 1; @@ -376,7 +376,7 @@ struct mountinfo *mountinfo_read(int do_statvfs) { if(unlikely(bind)) { struct mountinfo *mi; for(mi = root; mi ; mi = mi->next) { - if(unlikely(strcmp(mnt->mnt_dir, mi->mount_point) == 0)) { + if(unlikely(strsame(mnt->mnt_dir, mi->mount_point) == 0)) { fprintf(stderr, "Mount point '%s' is BIND\n", mi->mount_point); mi->flags |= MOUNTINFO_IS_BIND; break; diff --git a/src/proc_softirqs.c b/src/proc_softirqs.c index 5da7155f..c7b10d70 100644 --- a/src/proc_softirqs.c +++ b/src/proc_softirqs.c @@ -23,9 +23,9 @@ struct interrupt { // given a base, get a pointer to each record #define irrindex(base, line, cpus) ((struct interrupt *)&((char *)(base))[line * recordsize(cpus)]) -static inline struct interrupt *get_interrupts_array(uint32_t lines, int cpus) { +static inline struct interrupt *get_interrupts_array(size_t lines, int cpus) { static struct interrupt *irrs = NULL; - static uint32_t allocated = 0; + static size_t allocated = 0; if(unlikely(lines != allocated)) { uint32_t l; @@ -66,8 +66,8 @@ int do_proc_softirqs(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 = procfile_linewords(ff, 0); + size_t lines = procfile_lines(ff), l; + size_t words = procfile_linewords(ff, 0); if(unlikely(!lines)) { error("Cannot read /proc/softirqs, zero lines reported."); @@ -105,8 +105,8 @@ int do_proc_softirqs(int update_every, usec_t dt) { irr->id = procfile_lineword(ff, l, 0); if(unlikely(!irr->id || !irr->id[0])) continue; - int idlen = strlen(irr->id); - if(unlikely(irr->id[idlen - 1] == ':')) + size_t idlen = strlen(irr->id); + if(unlikely(idlen && irr->id[idlen - 1] == ':')) irr->id[idlen - 1] = '\0'; int c; diff --git a/src/proc_stat.c b/src/proc_stat.c index d8f764ec..11096aa8 100644 --- a/src/proc_stat.c +++ b/src/proc_stat.c @@ -32,8 +32,8 @@ int do_proc_stat(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; unsigned long long processes = 0, running = 0 , blocked = 0; RRDSET *st; @@ -46,7 +46,7 @@ int do_proc_stat(int update_every, usec_t dt) { if(likely(row_key[0] == 'c' && row_key[1] == 'p' && row_key[2] == 'u')) { words = procfile_linewords(ff, l); if(unlikely(words < 9)) { - error("Cannot read /proc/stat cpu line. Expected 9 params, read %u.", words); + error("Cannot read /proc/stat cpu line. Expected 9 params, read %zu.", words); continue; } @@ -73,7 +73,7 @@ int do_proc_stat(int update_every, usec_t dt) { long priority; int isthistotal; - if(unlikely(strcmp(id, "cpu")) == 0) { + if(unlikely(strsame(id, "cpu")) == 0) { title = "Total CPU utilization"; type = "system"; context = "system.cpu"; @@ -126,7 +126,7 @@ int do_proc_stat(int update_every, usec_t dt) { rrdset_done(st); } } - else if(unlikely(hash == hash_intr && strcmp(row_key, "intr") == 0)) { + else if(unlikely(hash == hash_intr && strsame(row_key, "intr") == 0)) { unsigned long long value = str2ull(procfile_lineword(ff, l, 1)); // -------------------------------------------------------------------- @@ -145,7 +145,7 @@ int do_proc_stat(int update_every, usec_t dt) { rrdset_done(st); } } - else if(unlikely(hash == hash_ctxt && strcmp(row_key, "ctxt") == 0)) { + else if(unlikely(hash == hash_ctxt && strsame(row_key, "ctxt") == 0)) { unsigned long long value = str2ull(procfile_lineword(ff, l, 1)); // -------------------------------------------------------------------- @@ -163,13 +163,13 @@ int do_proc_stat(int update_every, usec_t dt) { rrdset_done(st); } } - else if(unlikely(hash == hash_processes && !processes && strcmp(row_key, "processes") == 0)) { + else if(unlikely(hash == hash_processes && !processes && strsame(row_key, "processes") == 0)) { processes = str2ull(procfile_lineword(ff, l, 1)); } - else if(unlikely(hash == hash_procs_running && !running && strcmp(row_key, "procs_running") == 0)) { + else if(unlikely(hash == hash_procs_running && !running && strsame(row_key, "procs_running") == 0)) { running = str2ull(procfile_lineword(ff, l, 1)); } - else if(unlikely(hash == hash_procs_blocked && !blocked && strcmp(row_key, "procs_blocked") == 0)) { + else if(unlikely(hash == hash_procs_blocked && !blocked && strsame(row_key, "procs_blocked") == 0)) { blocked = str2ull(procfile_lineword(ff, l, 1)); } } diff --git a/src/proc_vmstat.c b/src/proc_vmstat.c index d1aac04c..9b1f0e95 100644 --- a/src/proc_vmstat.c +++ b/src/proc_vmstat.c @@ -71,13 +71,13 @@ int do_proc_vmstat(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; + size_t lines = procfile_lines(ff), l; arl_begin(arl_base); for(l = 0; l < lines ;l++) { - uint32_t words = procfile_linewords(ff, l); + size_t words = procfile_linewords(ff, l); if(unlikely(words < 2)) { - if(unlikely(words)) error("Cannot read /proc/vmstat line %u. Expected 2 params, read %u.", l, words); + if(unlikely(words)) error("Cannot read /proc/vmstat line %zu. Expected 2 params, read %zu.", l, words); continue; } diff --git a/src/procfile.c b/src/procfile.c index 31bdb5e2..6f52bf46 100644 --- a/src/procfile.c +++ b/src/procfile.c @@ -1,4 +1,5 @@ #include "common.h" +#include "procfile.h" #define PF_PREFIX "PROCFILE" @@ -10,15 +11,15 @@ int procfile_adaptive_initial_allocation = 0; // if adaptive allocation is set, these store the // max values we have seen so far -uint32_t procfile_max_lines = PFLINES_INCREASE_STEP; -uint32_t procfile_max_words = PFWORDS_INCREASE_STEP; +size_t procfile_max_lines = PFLINES_INCREASE_STEP; +size_t procfile_max_words = PFWORDS_INCREASE_STEP; size_t procfile_max_allocation = PROCFILE_INCREMENT_BUFFER; // ---------------------------------------------------------------------------- // An array of words - -pfwords *pfwords_add(pfwords *fw, char *str) { +static inline pfwords *pfwords_add(pfwords *fw, char *str) NEVERNULL; +static inline pfwords *pfwords_add(pfwords *fw, char *str) { // debug(D_PROCFILE, PF_PREFIX ": adding word No %d: '%s'", fw->len, str); if(unlikely(fw->len == fw->size)) { @@ -33,10 +34,11 @@ pfwords *pfwords_add(pfwords *fw, char *str) { return fw; } -pfwords *pfwords_new(void) { +static inline pfwords *pfwords_new(void) NEVERNULL; +static inline pfwords *pfwords_new(void) { // debug(D_PROCFILE, PF_PREFIX ": initializing words"); - uint32_t size = (procfile_adaptive_initial_allocation) ? procfile_max_words : PFWORDS_INCREASE_STEP; + size_t size = (procfile_adaptive_initial_allocation) ? procfile_max_words : PFWORDS_INCREASE_STEP; pfwords *new = mallocz(sizeof(pfwords) + size * sizeof(char *)); new->len = 0; @@ -44,12 +46,12 @@ pfwords *pfwords_new(void) { return new; } -void pfwords_reset(pfwords *fw) { +static inline void pfwords_reset(pfwords *fw) { // debug(D_PROCFILE, PF_PREFIX ": reseting words"); fw->len = 0; } -void pfwords_free(pfwords *fw) { +static inline void pfwords_free(pfwords *fw) { // debug(D_PROCFILE, PF_PREFIX ": freeing words"); freez(fw); @@ -59,7 +61,8 @@ void pfwords_free(pfwords *fw) { // ---------------------------------------------------------------------------- // An array of lines -pflines *pflines_add(pflines *fl, uint32_t first_word) { +static inline pflines *pflines_add(pflines *fl, size_t first_word) NEVERNULL; +static inline pflines *pflines_add(pflines *fl, size_t first_word) { // debug(D_PROCFILE, PF_PREFIX ": adding line %d at word %d", fl->len, first_word); if(unlikely(fl->len == fl->size)) { @@ -75,10 +78,11 @@ pflines *pflines_add(pflines *fl, uint32_t first_word) { return fl; } -pflines *pflines_new(void) { +static inline pflines *pflines_new(void) NEVERNULL; +static inline pflines *pflines_new(void) { // debug(D_PROCFILE, PF_PREFIX ": initializing lines"); - uint32_t size = (unlikely(procfile_adaptive_initial_allocation)) ? procfile_max_words : PFLINES_INCREASE_STEP; + size_t size = (unlikely(procfile_adaptive_initial_allocation)) ? procfile_max_words : PFLINES_INCREASE_STEP; pflines *new = mallocz(sizeof(pflines) + size * sizeof(ffline)); new->len = 0; @@ -86,13 +90,13 @@ pflines *pflines_new(void) { return new; } -void pflines_reset(pflines *fl) { +static inline void pflines_reset(pflines *fl) { // debug(D_PROCFILE, PF_PREFIX ": reseting lines"); fl->len = 0; } -void pflines_free(pflines *fl) { +static inline void pflines_free(pflines *fl) { // debug(D_PROCFILE, PF_PREFIX ": freeing lines"); freez(fl); @@ -119,20 +123,20 @@ void procfile_close(procfile *ff) { freez(ff); } -procfile *procfile_parser(procfile *ff) { - debug(D_PROCFILE, PF_PREFIX ": Parsing file '%s'", ff->filename); +static inline void procfile_parser(procfile *ff) { + // debug(D_PROCFILE, PF_PREFIX ": Parsing file '%s'", ff->filename); - char *s = ff->data, *e = &ff->data[ff->len], *t = ff->data, quote = 0; - uint32_t l = 0, w = 0; - int opened = 0; + register char *s = ff->data, *e = &ff->data[ff->len], *t = ff->data; + register char *separators = ff->separators; + char quote = 0; + size_t l = 0, w = 0, opened = 0; ff->lines = pflines_add(ff->lines, w); - if(unlikely(!ff->lines)) goto cleanup; while(likely(s < e)) { // we are not at the end - switch(ff->separators[(uint8_t)(*s)]) { + switch(separators[(unsigned char)(*s)]) { case PF_CHAR_IS_OPEN: if(s == t) { opened++; @@ -144,7 +148,7 @@ procfile *procfile_parser(procfile *ff) { } else s++; - continue; + break; case PF_CHAR_IS_CLOSE: if(opened) { @@ -153,8 +157,6 @@ procfile *procfile_parser(procfile *ff) { if(!opened) { *s = '\0'; ff->words = pfwords_add(ff->words, t); - if(unlikely(!ff->words)) goto cleanup; - ff->lines->lines[l].words++; w++; @@ -165,7 +167,7 @@ procfile *procfile_parser(procfile *ff) { } else s++; - continue; + break; case PF_CHAR_IS_QUOTE: if(unlikely(!quote && s == t)) { @@ -179,8 +181,6 @@ procfile *procfile_parser(procfile *ff) { *s = '\0'; ff->words = pfwords_add(ff->words, t); - if(unlikely(!ff->words)) goto cleanup; - ff->lines->lines[l].words++; w++; @@ -188,55 +188,50 @@ procfile *procfile_parser(procfile *ff) { } else s++; - continue; + break; case PF_CHAR_IS_SEPARATOR: if(unlikely(quote || opened)) { // we are inside a quote s++; - continue; + break; } if(unlikely(s == t)) { // skip all leading white spaces t = ++s; - continue; + break; } // end of word *s = '\0'; ff->words = pfwords_add(ff->words, t); - if(unlikely(!ff->words)) goto cleanup; - ff->lines->lines[l].words++; w++; t = ++s; - continue; + break; case PF_CHAR_IS_NEWLINE: // end of line *s = '\0'; ff->words = pfwords_add(ff->words, t); - if(unlikely(!ff->words)) goto cleanup; - ff->lines->lines[l].words++; w++; // debug(D_PROCFILE, PF_PREFIX ": ended line %d with %d words", l, ff->lines->lines[l].words); ff->lines = pflines_add(ff->lines, w); - if(unlikely(!ff->lines)) goto cleanup; l++; t = ++s; - continue; + break; default: s++; - continue; + break; } } @@ -250,18 +245,8 @@ procfile *procfile_parser(procfile *ff) { } ff->words = pfwords_add(ff->words, t); - if(unlikely(!ff->words)) goto cleanup; - ff->lines->lines[l].words++; - w++; } - - return ff; - -cleanup: - error(PF_PREFIX ": Failed to parse file '%s'", ff->filename); - procfile_close(ff); - return NULL; } procfile *procfile_readall(procfile *ff) { @@ -301,8 +286,7 @@ procfile *procfile_readall(procfile *ff) { pflines_reset(ff->lines); pfwords_reset(ff->words); - - ff = procfile_parser(ff); + procfile_parser(ff); if(unlikely(procfile_adaptive_initial_allocation)) { if(unlikely(ff->len > procfile_max_allocation)) procfile_max_allocation = ff->len; @@ -405,12 +389,6 @@ procfile *procfile_open(const char *filename, const char *separators, uint32_t f ff->lines = pflines_new(); ff->words = pfwords_new(); - if(unlikely(!ff->lines || !ff->words)) { - error(PF_PREFIX ": Cannot initialize parser for file '%s'", filename); - procfile_close(ff); - return NULL; - } - procfile_set_separators(ff, separators); debug(D_PROCFILE, "File '%s' opened.", filename); @@ -442,20 +420,20 @@ procfile *procfile_reopen(procfile *ff, const char *filename, const char *separa // example parsing of procfile data void procfile_print(procfile *ff) { - uint32_t lines = procfile_lines(ff), l; + size_t lines = procfile_lines(ff), l; char *s; - debug(D_PROCFILE, "File '%s' with %u lines and %u words", ff->filename, ff->lines->len, ff->words->len); + debug(D_PROCFILE, "File '%s' with %zu lines and %zu words", ff->filename, ff->lines->len, ff->words->len); for(l = 0; likely(l < lines) ;l++) { - uint32_t words = procfile_linewords(ff, l); + size_t words = procfile_linewords(ff, l); - debug(D_PROCFILE, " line %u starts at word %u and has %u words", l, ff->lines->lines[l].first, ff->lines->lines[l].words); + debug(D_PROCFILE, " line %zu starts at word %zu and has %zu words", l, ff->lines->lines[l].first, ff->lines->lines[l].words); - uint32_t w; + size_t w; for(w = 0; likely(w < words) ;w++) { s = procfile_lineword(ff, l, w); - debug(D_PROCFILE, " [%u.%u] '%s'", l, w, s); + debug(D_PROCFILE, " [%zu.%zu] '%s'", l, w, s); } } } diff --git a/src/procfile.h b/src/procfile.h index 5e00b258..a586ba48 100644 --- a/src/procfile.h +++ b/src/procfile.h @@ -30,8 +30,8 @@ // An array of words typedef struct { - uint32_t len; // used entries - uint32_t size; // capacity + size_t len; // used entries + size_t size; // capacity char *words[]; // array of pointers } pfwords; @@ -40,15 +40,15 @@ typedef struct { // An array of lines typedef struct { - uint32_t words; // how many words this line has - uint32_t first; // the id of the first word of this line - // in the words array + size_t words; // how many words this line has + size_t first; // the id of the first word of this line + // in the words array } ffline; typedef struct { - uint32_t len; // used entries - uint32_t size; // capacity - ffline lines[]; // array of lines + size_t len; // used entries + size_t size; // capacity + ffline lines[]; // array of lines } pflines; @@ -61,13 +61,13 @@ typedef struct { typedef struct { char filename[FILENAME_MAX + 1]; uint32_t flags; - int fd; // the file desriptor - size_t len; // the bytes we have placed into data - size_t size; // the bytes we have allocated for data + int fd; // the file desriptor + size_t len; // the bytes we have placed into data + size_t size; // the bytes we have allocated for data pflines *lines; pfwords *words; char separators[256]; - char data[]; // allocated buffer to keep file contents + char data[]; // allocated buffer to keep file contents } procfile; // close the proc file and free all related memory diff --git a/src/registry.c b/src/registry.c index d223cd6f..97bda809 100644 --- a/src/registry.c +++ b/src/registry.c @@ -158,7 +158,7 @@ int registry_request_access_json(struct web_client *w, char *person_guid, char * return 200; } - if(unlikely(person_guid[0] && !strcmp(person_guid, REGISTRY_VERIFY_COOKIES_GUID))) + if(unlikely(person_guid[0] && !strsame(person_guid, REGISTRY_VERIFY_COOKIES_GUID))) person_guid[0] = '\0'; // ------------------------------------------------------------------------ diff --git a/src/registry_internals.c b/src/registry_internals.c index d32d549e..a8c44380 100644 --- a/src/registry_internals.c +++ b/src/registry_internals.c @@ -17,7 +17,7 @@ int registry_regenerate_guid(const char *guid, char *result) { uuid_unparse_lower(uuid, result); #ifdef NETDATA_INTERNAL_CHECKS - if(strcmp(guid, result)) + if(strsame(guid, result)) info("Registry: source GUID '%s' and re-generated GUID '%s' differ!", guid, result); #endif /* NETDATA_INTERNAL_CHECKS */ } @@ -175,7 +175,7 @@ REGISTRY_PERSON *registry_request_delete(char *person_guid, char *machine_guid, delete_url = registry_fix_url(delete_url, NULL); // make sure the user is not deleting the url it uses - if(!strcmp(delete_url, pu->url->url)) { + if(!strsame(delete_url, pu->url->url)) { info("Registry Delete Request: delete URL is the one currently accessed, person: '%s', machine '%s', url '%s', delete url '%s'" , p->guid, m->guid, pu->url->url, delete_url); return NULL; @@ -264,8 +264,8 @@ static inline int is_machine_guid_blacklisted(const char *guid) { // we blacklist them here, so that the next version of netdata will generate // new ones. - if(!strcmp(guid, "8a795b0c-2311-11e6-8563-000c295076a6") - || !strcmp(guid, "4aed1458-1c3e-11e6-a53f-000c290fc8f5") + if(!strsame(guid, "8a795b0c-2311-11e6-8563-000c295076a6") + || !strsame(guid, "4aed1458-1c3e-11e6-a53f-000c290fc8f5") ) { error("Blacklisted machine GUID '%s' found.", guid); return 1; diff --git a/src/registry_person.c b/src/registry_person.c index 5f9099c9..6b18672e 100644 --- a/src/registry_person.c +++ b/src/registry_person.c @@ -9,7 +9,7 @@ int person_url_compare(void *a, void *b) { if(hash1 < hash2) return -1; else if(hash1 > hash2) return 1; - else return strcmp(((REGISTRY_PERSON_URL *)a)->url->url, ((REGISTRY_PERSON_URL *)b)->url->url); + else return strsame(((REGISTRY_PERSON_URL *)a)->url->url, ((REGISTRY_PERSON_URL *)b)->url->url); } inline REGISTRY_PERSON_URL *registry_person_url_index_find(REGISTRY_PERSON *p, const char *url) { @@ -242,7 +242,7 @@ REGISTRY_PERSON_URL *registry_person_link_to_url(REGISTRY_PERSON *p, REGISTRY_MA pu->machine = m; } - if(strcmp(pu->machine_name, name)) { + if(strsame(pu->machine_name, name)) { // the name of the PERSON_URL has changed ! pu = registry_person_url_reallocate(p, m, u, name, namelen, when, pu); } diff --git a/src/registry_url.c b/src/registry_url.c index 52d36a89..b7412ada 100644 --- a/src/registry_url.c +++ b/src/registry_url.c @@ -6,7 +6,7 @@ int registry_url_compare(void *a, void *b) { if(((REGISTRY_URL *)a)->hash < ((REGISTRY_URL *)b)->hash) return -1; else if(((REGISTRY_URL *)a)->hash > ((REGISTRY_URL *)b)->hash) return 1; - else return strcmp(((REGISTRY_URL *)a)->url, ((REGISTRY_URL *)b)->url); + else return strsame(((REGISTRY_URL *)a)->url, ((REGISTRY_URL *)b)->url); } inline REGISTRY_URL *registry_url_index_add(REGISTRY_URL *u) { diff --git a/src/rrd.c b/src/rrd.c index 27e8e6b2..bd15c765 100644 --- a/src/rrd.c +++ b/src/rrd.c @@ -91,7 +91,7 @@ void rrdhost_check_wrlock_int(RRDHOST *host, const char *file, const char *funct static int rrdfamily_compare(void *a, void *b) { if(((RRDFAMILY *)a)->hash_family < ((RRDFAMILY *)b)->hash_family) return -1; else if(((RRDFAMILY *)a)->hash_family > ((RRDFAMILY *)b)->hash_family) return 1; - else return strcmp(((RRDFAMILY *)a)->family, ((RRDFAMILY *)b)->family); + else return strsame(((RRDFAMILY *)a)->family, ((RRDFAMILY *)b)->family); } #define rrdfamily_index_add(host, rc) (RRDFAMILY *)avl_insert_lock(&((host)->rrdfamily_root_index), (avl *)(rc)) @@ -146,7 +146,7 @@ void rrdfamily_free(RRDFAMILY *rc) { static int rrdset_compare(void* a, void* b) { if(((RRDSET *)a)->hash < ((RRDSET *)b)->hash) return -1; else if(((RRDSET *)a)->hash > ((RRDSET *)b)->hash) return 1; - else return strcmp(((RRDSET *)a)->id, ((RRDSET *)b)->id); + else return strsame(((RRDSET *)a)->id, ((RRDSET *)b)->id); } #define rrdset_index_add(host, st) (RRDSET *)avl_insert_lock(&((host)->rrdset_root_index), (avl *)(st)) @@ -173,7 +173,7 @@ static int rrdset_compare_name(void* a, void* b) { if(A->hash_name < B->hash_name) return -1; else if(A->hash_name > B->hash_name) return 1; - else return strcmp(A->name, B->name); + else return strsame(A->name, B->name); } RRDSET *rrdset_index_add_name(RRDHOST *host, RRDSET *st) { @@ -202,7 +202,7 @@ static RRDSET *rrdset_index_find_name(RRDHOST *host, const char *name, uint32_t result = avl_search_lock(&host->rrdset_root_index_name, (avl *) (&(tmp.avlname))); if(result) { RRDSET *st = rrdset_from_avlname(result); - if(strcmp(st->magic, RRDSET_MAGIC)) + if(strsame(st->magic, RRDSET_MAGIC)) error("Search for RRDSET %s returned an invalid RRDSET %s (name %s)", name, st->id, st->name); // fprintf(stderr, "FOUND: %s\n", name); @@ -219,7 +219,7 @@ static RRDSET *rrdset_index_find_name(RRDHOST *host, const char *name, uint32_t static int rrddim_compare(void* a, void* b) { if(((RRDDIM *)a)->hash < ((RRDDIM *)b)->hash) return -1; else if(((RRDDIM *)a)->hash > ((RRDDIM *)b)->hash) return 1; - else return strcmp(((RRDDIM *)a)->id, ((RRDDIM *)b)->id); + else return strsame(((RRDDIM *)a)->id, ((RRDDIM *)b)->id); } #define rrddim_index_add(st, rd) (RRDDIM *)avl_insert_lock(&((st)->dimensions_index), (avl *)(rd)) @@ -238,9 +238,9 @@ static RRDDIM *rrddim_index_find(RRDSET *st, const char *id, uint32_t hash) { int rrdset_type_id(const char *name) { - if(unlikely(strcmp(name, RRDSET_TYPE_AREA_NAME) == 0)) return RRDSET_TYPE_AREA; - else if(unlikely(strcmp(name, RRDSET_TYPE_STACKED_NAME) == 0)) return RRDSET_TYPE_STACKED; - else if(unlikely(strcmp(name, RRDSET_TYPE_LINE_NAME) == 0)) return RRDSET_TYPE_LINE; + if(unlikely(strsame(name, RRDSET_TYPE_AREA_NAME) == 0)) return RRDSET_TYPE_AREA; + else if(unlikely(strsame(name, RRDSET_TYPE_STACKED_NAME) == 0)) return RRDSET_TYPE_STACKED; + else if(unlikely(strsame(name, RRDSET_TYPE_LINE_NAME) == 0)) return RRDSET_TYPE_LINE; return RRDSET_TYPE_LINE; } @@ -289,9 +289,9 @@ const char *rrd_memory_mode_name(int id) int rrd_memory_mode_id(const char *name) { - if(unlikely(!strcmp(name, RRD_MEMORY_MODE_RAM_NAME))) + if(unlikely(!strsame(name, RRD_MEMORY_MODE_RAM_NAME))) return RRD_MEMORY_MODE_RAM; - else if(unlikely(!strcmp(name, RRD_MEMORY_MODE_MAP_NAME))) + else if(unlikely(!strsame(name, RRD_MEMORY_MODE_MAP_NAME))) return RRD_MEMORY_MODE_MAP; return RRD_MEMORY_MODE_SAVE; @@ -302,10 +302,10 @@ int rrd_memory_mode_id(const char *name) int rrddim_algorithm_id(const char *name) { - if(strcmp(name, RRDDIM_INCREMENTAL_NAME) == 0) return RRDDIM_INCREMENTAL; - if(strcmp(name, RRDDIM_ABSOLUTE_NAME) == 0) return RRDDIM_ABSOLUTE; - if(strcmp(name, RRDDIM_PCENT_OVER_ROW_TOTAL_NAME) == 0) return RRDDIM_PCENT_OVER_ROW_TOTAL; - if(strcmp(name, RRDDIM_PCENT_OVER_DIFF_TOTAL_NAME) == 0) return RRDDIM_PCENT_OVER_DIFF_TOTAL; + if(strsame(name, RRDDIM_INCREMENTAL_NAME) == 0) return RRDDIM_INCREMENTAL; + if(strsame(name, RRDDIM_ABSOLUTE_NAME) == 0) return RRDDIM_ABSOLUTE; + if(strsame(name, RRDDIM_PCENT_OVER_ROW_TOTAL_NAME) == 0) return RRDDIM_PCENT_OVER_ROW_TOTAL; + if(strsame(name, RRDDIM_PCENT_OVER_DIFF_TOTAL_NAME) == 0) return RRDDIM_PCENT_OVER_DIFF_TOTAL; return RRDDIM_ABSOLUTE; } @@ -353,7 +353,7 @@ char *rrdset_strncpyz_name(char *to, const char *from, size_t length) void rrdset_set_name(RRDSET *st, const char *name) { - if(unlikely(st->name && !strcmp(st->name, name))) + if(unlikely(st->name && !strsame(st->name, name))) return; debug(D_RRD_CALLS, "rrdset_set_name() old: %s, new: %s", st->name, name); @@ -504,12 +504,12 @@ RRDSET *rrdset_create(const char *type, const char *id, const char *name, const snprintfz(fullfilename, FILENAME_MAX, "%s/main.db", cache_dir); if(rrd_memory_mode != RRD_MEMORY_MODE_RAM) st = (RRDSET *)mymmap(fullfilename, size, ((rrd_memory_mode == RRD_MEMORY_MODE_MAP)?MAP_SHARED:MAP_PRIVATE), 0); if(st) { - if(strcmp(st->magic, RRDSET_MAGIC) != 0) { + if(strsame(st->magic, RRDSET_MAGIC) != 0) { errno = 0; info("Initializing file %s.", fullfilename); memset(st, 0, size); } - else if(strcmp(st->id, fullid) != 0) { + else if(strsame(st->id, fullid) != 0) { errno = 0; error("File %s contents are not for chart %s. Clearing it.", fullfilename, fullid); // munmap(st, size); @@ -588,7 +588,7 @@ RRDSET *rrdset_create(const char *type, const char *id, const char *name, const st->isdetail = 0; st->debug = 0; - // if(!strcmp(st->id, "disk_util.dm-0")) { + // if(!strsame(st->id, "disk_util.dm-0")) { // st->debug = 1; // error("enabled debugging for '%s'", st->id); // } @@ -672,7 +672,7 @@ RRDDIM *rrddim_add(RRDSET *st, const char *id, const char *name, long multiplier struct timeval now; now_realtime_timeval(&now); - if(strcmp(rd->magic, RRDDIMENSION_MAGIC) != 0) { + if(strsame(rd->magic, RRDDIMENSION_MAGIC) != 0) { errno = 0; info("Initializing file %s.", fullfilename); memset(rd, 0, size); @@ -707,7 +707,7 @@ RRDDIM *rrddim_add(RRDSET *st, const char *id, const char *name, long multiplier error("File %s is too old. Clearing it.", fullfilename); memset(rd, 0, size); } - else if(strcmp(rd->id, id) != 0) { + else if(strsame(rd->id, id) != 0) { errno = 0; error("File %s contents are not for dimension %s. Clearing it.", fullfilename, id); // munmap(rd, size); @@ -795,7 +795,7 @@ RRDDIM *rrddim_add(RRDSET *st, const char *id, const char *name, long multiplier void rrddim_set_name(RRDSET *st, RRDDIM *rd, const char *name) { - if(unlikely(rd->name && !strcmp(rd->name, name))) + if(unlikely(rd->name && !strsame(rd->name, name))) return; debug(D_RRD_CALLS, "rrddim_set_name() from %s.%s to %s.%s", st->name, rd->name, st->name, name); diff --git a/src/rrd2json.c b/src/rrd2json.c index 06747500..02c4547b 100644 --- a/src/rrd2json.c +++ b/src/rrd2json.c @@ -561,7 +561,7 @@ void rrdr_disable_not_selected_dimensions(RRDR *r, const char *dims) // find it and enable it for(c = 0, d = r->st->dimensions; d ;c++, d = d->next) { - if(unlikely((hash == d->hash && !strcmp(d->id, tok)) || !strcmp(d->name, tok))) { + if(unlikely((hash == d->hash && !strsame(d->id, tok)) || !strsame(d->name, tok))) { r->od[c] &= ~RRDR_HIDDEN; // since the user needs this dimension diff --git a/src/simple_pattern.c b/src/simple_pattern.c index 7e442429..6bed5585 100644 --- a/src/simple_pattern.c +++ b/src/simple_pattern.c @@ -147,7 +147,7 @@ static inline int match_pattern(struct simple_pattern *m, const char *str, size_ break; case SIMPLE_PATTERN_SUFFIX: - if(unlikely(strcmp(&str[len - m->len], m->match) == 0)) { + if(unlikely(strsame(&str[len - m->len], m->match) == 0)) { if(!m->child) return 1; return 0; } @@ -155,7 +155,7 @@ static inline int match_pattern(struct simple_pattern *m, const char *str, size_ case SIMPLE_PATTERN_EXACT: default: - if(unlikely(strcmp(str, m->match) == 0)) { + if(unlikely(strsame(str, m->match) == 0)) { if(!m->child) return 1; return 0; } diff --git a/src/sys_fs_cgroup.c b/src/sys_fs_cgroup.c index 2eea6054..ec67cbea 100644 --- a/src/sys_fs_cgroup.c +++ b/src/sys_fs_cgroup.c @@ -54,88 +54,16 @@ static char *cgroups_rename_script = PLUGINS_DIR "/cgroup-name.sh"; static uint32_t Read_hash = 0; static uint32_t Write_hash = 0; -static uint32_t Sync_hash = 0; -static uint32_t Async_hash = 0; -static uint32_t Total_hash = 0; static uint32_t user_hash = 0; static uint32_t system_hash = 0; -static uint32_t cache_hash = 0; -static uint32_t rss_hash = 0; -static uint32_t rss_huge_hash = 0; -static uint32_t mapped_file_hash = 0; -static uint32_t writeback_hash = 0; -static uint32_t dirty_hash = 0; -static uint32_t swap_hash = 0; -static uint32_t pgpgin_hash = 0; -static uint32_t pgpgout_hash = 0; -static uint32_t pgfault_hash = 0; -static uint32_t pgmajfault_hash = 0; -static uint32_t inactive_anon_hash = 0; -static uint32_t active_anon_hash = 0; -static uint32_t inactive_file_hash = 0; -static uint32_t active_file_hash = 0; -static uint32_t unevictable_hash = 0; -static uint32_t hierarchical_memory_limit_hash = 0; -static uint32_t total_cache_hash = 0; -static uint32_t total_rss_hash = 0; -static uint32_t total_rss_huge_hash = 0; -static uint32_t total_mapped_file_hash = 0; -static uint32_t total_writeback_hash = 0; -static uint32_t total_dirty_hash = 0; -static uint32_t total_swap_hash = 0; -static uint32_t total_pgpgin_hash = 0; -static uint32_t total_pgpgout_hash = 0; -static uint32_t total_pgfault_hash = 0; -static uint32_t total_pgmajfault_hash = 0; -static uint32_t total_inactive_anon_hash = 0; -static uint32_t total_active_anon_hash = 0; -static uint32_t total_inactive_file_hash = 0; -static uint32_t total_active_file_hash = 0; -static uint32_t total_unevictable_hash = 0; void read_cgroup_plugin_configuration() { system_page_size = sysconf(_SC_PAGESIZE); Read_hash = simple_hash("Read"); Write_hash = simple_hash("Write"); - Sync_hash = simple_hash("Sync"); - Async_hash = simple_hash("Async"); - Total_hash = simple_hash("Total"); user_hash = simple_hash("user"); system_hash = simple_hash("system"); - cache_hash = simple_hash("cache"); - rss_hash = simple_hash("rss"); - rss_huge_hash = simple_hash("rss_huge"); - mapped_file_hash = simple_hash("mapped_file"); - writeback_hash = simple_hash("writeback"); - dirty_hash = simple_hash("dirty"); - swap_hash = simple_hash("swap"); - pgpgin_hash = simple_hash("pgpgin"); - pgpgout_hash = simple_hash("pgpgout"); - pgfault_hash = simple_hash("pgfault"); - pgmajfault_hash = simple_hash("pgmajfault"); - inactive_anon_hash = simple_hash("inactive_anon"); - active_anon_hash = simple_hash("active_anon"); - inactive_file_hash = simple_hash("inactive_file"); - active_file_hash = simple_hash("active_file"); - unevictable_hash = simple_hash("unevictable"); - hierarchical_memory_limit_hash = simple_hash("hierarchical_memory_limit"); - total_cache_hash = simple_hash("total_cache"); - total_rss_hash = simple_hash("total_rss"); - total_rss_huge_hash = simple_hash("total_rss_huge"); - total_mapped_file_hash = simple_hash("total_mapped_file"); - total_writeback_hash = simple_hash("total_writeback"); - total_dirty_hash = simple_hash("total_dirty"); - total_swap_hash = simple_hash("total_swap"); - total_pgpgin_hash = simple_hash("total_pgpgin"); - total_pgpgout_hash = simple_hash("total_pgpgout"); - total_pgfault_hash = simple_hash("total_pgfault"); - total_pgmajfault_hash = simple_hash("total_pgmajfault"); - total_inactive_anon_hash = simple_hash("total_inactive_anon"); - total_active_anon_hash = simple_hash("total_active_anon"); - total_inactive_file_hash = simple_hash("total_inactive_file"); - total_active_file_hash = simple_hash("total_active_file"); - total_unevictable_hash = simple_hash("total_unevictable"); cgroup_update_every = (int)config_get_number("plugin:cgroups", "update every", rrd_update_every); if(cgroup_update_every < rrd_update_every) @@ -443,8 +371,6 @@ struct cgroup { RRDDIM *rd_mem_detailed_rss; RRDDIM *rd_mem_detailed_mapped; RRDDIM *rd_mem_detailed_writeback; - RRDDIM *rd_mem_detailed_dirty; - RRDDIM *rd_mem_detailed_swap; RRDDIM *rd_mem_detailed_pgpgin; RRDDIM *rd_mem_detailed_pgpgout; RRDDIM *rd_mem_detailed_pgfault; @@ -499,10 +425,10 @@ static inline void cgroup_read_cpuacct_stat(struct cpuacct_stat *cp) { char *s = procfile_lineword(ff, i, 0); uint32_t hash = simple_hash(s); - if(unlikely(hash == user_hash && !strcmp(s, "user"))) + if(unlikely(hash == user_hash && !strsame(s, "user"))) cp->user = str2ull(procfile_lineword(ff, i, 1)); - else if(unlikely(hash == system_hash && !strcmp(s, "system"))) + else if(unlikely(hash == system_hash && !strsame(s, "system"))) cp->system = str2ull(procfile_lineword(ff, i, 1)); } @@ -530,7 +456,7 @@ static inline void cgroup_read_cpuacct_usage(struct cpuacct_usage *ca) { } if(unlikely(procfile_lines(ff) < 1)) { - error("File '%s' should have 1+ lines but has %u.", ca->filename, procfile_lines(ff)); + error("File '%s' should have 1+ lines but has %zu.", ca->filename, procfile_lines(ff)); ca->updated = 0; return; } @@ -609,20 +535,20 @@ static inline void cgroup_read_blkio(struct blkio *io) { char *s = procfile_lineword(ff, i, 1); uint32_t hash = simple_hash(s); - if(unlikely(hash == Read_hash && !strcmp(s, "Read"))) + if(unlikely(hash == Read_hash && !strsame(s, "Read"))) io->Read += str2ull(procfile_lineword(ff, i, 2)); - else if(unlikely(hash == Write_hash && !strcmp(s, "Write"))) + else if(unlikely(hash == Write_hash && !strsame(s, "Write"))) io->Write += str2ull(procfile_lineword(ff, i, 2)); /* - else if(unlikely(hash == Sync_hash && !strcmp(s, "Sync"))) + else if(unlikely(hash == Sync_hash && !strsame(s, "Sync"))) io->Sync += str2ull(procfile_lineword(ff, i, 2)); - else if(unlikely(hash == Async_hash && !strcmp(s, "Async"))) + else if(unlikely(hash == Async_hash && !strsame(s, "Async"))) io->Async += str2ull(procfile_lineword(ff, i, 2)); - else if(unlikely(hash == Total_hash && !strcmp(s, "Total"))) + else if(unlikely(hash == Total_hash && !strsame(s, "Total"))) io->Total += str2ull(procfile_lineword(ff, i, 2)); */ } @@ -921,7 +847,7 @@ static inline struct cgroup *cgroup_add(const char *id) { if(cg->enabled) { struct cgroup *t; for (t = cgroup_root; t; t = t->next) { - if (t != cg && t->enabled && t->hash_chart == cg->hash_chart && !strcmp(t->chart_id, cg->chart_id)) { + if (t != cg && t->enabled && t->hash_chart == cg->hash_chart && !strsame(t->chart_id, cg->chart_id)) { if (!strncmp(t->chart_id, "/system.slice/", 14) && !strncmp(cg->chart_id, "/init.scope/system.slice/", 25)) { error("Control group with chart id '%s' already exists with id '%s' and is enabled. Swapping them by enabling cgroup with id '%s' and disabling cgroup with id '%s'.", cg->chart_id, t->id, cg->id, t->id); @@ -989,7 +915,7 @@ static inline struct cgroup *cgroup_find(const char *id) { struct cgroup *cg; for(cg = cgroup_root; cg ; cg = cg->next) { - if(hash == cg->hash && strcmp(id, cg->id) == 0) + if(hash == cg->hash && strsame(id, cg->id) == 0) break; } @@ -1109,7 +1035,7 @@ static inline void cleanup_all_cgroups() { { struct cgroup *t; for(t = cgroup_root; t ; t = t->next) { - if(t != cg && t->available && !t->enabled && t->options & CGROUP_OPTIONS_DISABLED_DUPLICATE && t->hash_chart == cg->hash_chart && !strcmp(t->chart_id, cg->chart_id)) { + if(t != cg && t->available && !t->enabled && t->options & CGROUP_OPTIONS_DISABLED_DUPLICATE && t->hash_chart == cg->hash_chart && !strsame(t->chart_id, cg->chart_id)) { debug(D_CGROUP, "Enabling duplicate of cgroup '%s' with id '%s', because the original with id '%s' stopped.", t->chart_id, t->id, cg->id); t->enabled = 1; t->options &= ~CGROUP_OPTIONS_DISABLED_DUPLICATE; diff --git a/src/web_buffer.c b/src/web_buffer.c index bc05f0d8..899e5c09 100644 --- a/src/web_buffer.c +++ b/src/web_buffer.c @@ -21,7 +21,7 @@ static inline void _buffer_overflow_check(BUFFER *b, const char *file, const cha b->len = b->size; } - if(b->buffer[b->size] != '\0' || strcmp(&b->buffer[b->size + 1], BUFFER_OVERFLOW_EOF)) { + if(b->buffer[b->size] != '\0' || strsame(&b->buffer[b->size + 1], BUFFER_OVERFLOW_EOF)) { error("BUFFER: detected overflow at line %lu, at function %s() of file '%s'.", line, function, file); buffer_overflow_init(b); } diff --git a/src/web_buffer_svg.c b/src/web_buffer_svg.c index 36185991..dba9bdd1 100644 --- a/src/web_buffer_svg.c +++ b/src/web_buffer_svg.c @@ -290,7 +290,7 @@ static inline int verdana11_width(char *s) { *d = '\0'; w -= VERDANA_KERNING; w += VERDANA_PADDING; - return ceil(w); + return (int)ceil(w); } static inline size_t escape_xmlz(char *dst, const char *src, size_t len) { @@ -369,25 +369,25 @@ cleanup: } static inline const char *fix_units(const char *units) { - if(!units || !*units || !strcmp(units, "empty") || !strcmp(units, "null")) return ""; - if(!strcmp(units, "percentage") || !strcmp(units, "percent") || !strcmp(units, "pcent")) return "%"; + if(!units || !*units || !strsame(units, "empty") || !strsame(units, "null")) return ""; + if(!strsame(units, "percentage") || !strsame(units, "percent") || !strsame(units, "pcent")) return "%"; return units; } static inline const char *color_map(const char *color) { // colors from: // https://github.com/badges/shields/blob/master/colorscheme.json - if(!strcmp(color, "brightgreen")) return "#4c1"; - else if(!strcmp(color, "green")) return "#97CA00"; - else if(!strcmp(color, "yellow")) return "#dfb317"; - else if(!strcmp(color, "yellowgreen")) return "#a4a61d"; - else if(!strcmp(color, "orange")) return "#fe7d37"; - else if(!strcmp(color, "red")) return "#e05d44"; - else if(!strcmp(color, "blue")) return "#007ec6"; - else if(!strcmp(color, "grey")) return "#555"; - else if(!strcmp(color, "gray")) return "#555"; - else if(!strcmp(color, "lightgrey")) return "#9f9f9f"; - else if(!strcmp(color, "lightgray")) return "#9f9f9f"; + if(!strsame(color, "brightgreen")) return "#4c1"; + else if(!strsame(color, "green")) return "#97CA00"; + else if(!strsame(color, "yellow")) return "#dfb317"; + else if(!strsame(color, "yellowgreen")) return "#a4a61d"; + else if(!strsame(color, "orange")) return "#fe7d37"; + else if(!strsame(color, "red")) return "#e05d44"; + else if(!strsame(color, "blue")) return "#007ec6"; + else if(!strsame(color, "grey")) return "#555"; + else if(!strsame(color, "gray")) return "#555"; + else if(!strsame(color, "lightgrey")) return "#9f9f9f"; + else if(!strsame(color, "lightgray")) return "#9f9f9f"; return color; } @@ -466,7 +466,7 @@ static inline void calc_colorz(const char *color, char *final, size_t len, calcu *dv = '\0'; if(value_is_null) { - if(!*value_buffer || !strcmp(value_buffer, "null")) + if(!*value_buffer || !strsame(value_buffer, "null")) break; } else { @@ -525,7 +525,7 @@ void buffer_svg(BUFFER *wb, const char *label, calculated_number value, const ch if(unlikely(isalnum(*units))) separator = " "; - if(unlikely(!strcmp(units, "seconds"))) { + if(unlikely(!strsame(units, "seconds"))) { size_t s = (size_t)value; size_t d = s / 86400; s = s % 86400; @@ -542,7 +542,7 @@ void buffer_svg(BUFFER *wb, const char *label, calculated_number value, const ch snprintfz(value_string, VALUE_STRING_SIZE, "%02zu:%02zu:%02zu", h, m, s); } - else if(unlikely(!strcmp(units, "minutes"))) { + else if(unlikely(!strsame(units, "minutes"))) { size_t m = (size_t)value; size_t d = m / (60 * 24); m = m % (60 * 24); @@ -556,7 +556,7 @@ void buffer_svg(BUFFER *wb, const char *label, calculated_number value, const ch snprintfz(value_string, VALUE_STRING_SIZE, "%zuh %zum", h, m); } - else if(unlikely(!strcmp(units, "hours"))) { + else if(unlikely(!strsame(units, "hours"))) { size_t h = (size_t)value; size_t d = h / 24; h = h % 24; diff --git a/src/web_client.c b/src/web_client.c index 4b6ccf64..bd047913 100644 --- a/src/web_client.c +++ b/src/web_client.c @@ -544,29 +544,29 @@ uint32_t web_client_api_request_v1_data_options(char *o) while(o && *o && (tok = mystrsep(&o, ", |"))) { if(!*tok) continue; - if(!strcmp(tok, "nonzero")) + if(!strsame(tok, "nonzero")) ret |= RRDR_OPTION_NONZERO; - else if(!strcmp(tok, "flip") || !strcmp(tok, "reversed") || !strcmp(tok, "reverse")) + else if(!strsame(tok, "flip") || !strsame(tok, "reversed") || !strsame(tok, "reverse")) ret |= RRDR_OPTION_REVERSED; - else if(!strcmp(tok, "jsonwrap")) + else if(!strsame(tok, "jsonwrap")) ret |= RRDR_OPTION_JSON_WRAP; - else if(!strcmp(tok, "min2max")) + else if(!strsame(tok, "min2max")) ret |= RRDR_OPTION_MIN2MAX; - else if(!strcmp(tok, "ms") || !strcmp(tok, "milliseconds")) + else if(!strsame(tok, "ms") || !strsame(tok, "milliseconds")) ret |= RRDR_OPTION_MILLISECONDS; - else if(!strcmp(tok, "abs") || !strcmp(tok, "absolute") || !strcmp(tok, "absolute_sum") || !strcmp(tok, "absolute-sum")) + else if(!strsame(tok, "abs") || !strsame(tok, "absolute") || !strsame(tok, "absolute_sum") || !strsame(tok, "absolute-sum")) ret |= RRDR_OPTION_ABSOLUTE; - else if(!strcmp(tok, "seconds")) + else if(!strsame(tok, "seconds")) ret |= RRDR_OPTION_SECONDS; - else if(!strcmp(tok, "null2zero")) + else if(!strsame(tok, "null2zero")) ret |= RRDR_OPTION_NULL2ZERO; - else if(!strcmp(tok, "objectrows")) + else if(!strsame(tok, "objectrows")) ret |= RRDR_OPTION_OBJECTSROWS; - else if(!strcmp(tok, "google_json")) + else if(!strsame(tok, "google_json")) ret |= RRDR_OPTION_GOOGLE_JSON; - else if(!strcmp(tok, "percentage")) + else if(!strsame(tok, "percentage")) ret |= RRDR_OPTION_PERCENTAGE; - else if(!strcmp(tok, "unaligned")) + else if(!strsame(tok, "unaligned")) ret |= RRDR_OPTION_NOT_ALIGNED; } @@ -575,37 +575,37 @@ uint32_t web_client_api_request_v1_data_options(char *o) uint32_t web_client_api_request_v1_data_format(char *name) { - if(!strcmp(name, DATASOURCE_FORMAT_DATATABLE_JSON)) // datatable + if(!strsame(name, DATASOURCE_FORMAT_DATATABLE_JSON)) // datatable return DATASOURCE_DATATABLE_JSON; - else if(!strcmp(name, DATASOURCE_FORMAT_DATATABLE_JSONP)) // datasource + else if(!strsame(name, DATASOURCE_FORMAT_DATATABLE_JSONP)) // datasource return DATASOURCE_DATATABLE_JSONP; - else if(!strcmp(name, DATASOURCE_FORMAT_JSON)) // json + else if(!strsame(name, DATASOURCE_FORMAT_JSON)) // json return DATASOURCE_JSON; - else if(!strcmp(name, DATASOURCE_FORMAT_JSONP)) // jsonp + else if(!strsame(name, DATASOURCE_FORMAT_JSONP)) // jsonp return DATASOURCE_JSONP; - else if(!strcmp(name, DATASOURCE_FORMAT_SSV)) // ssv + else if(!strsame(name, DATASOURCE_FORMAT_SSV)) // ssv return DATASOURCE_SSV; - else if(!strcmp(name, DATASOURCE_FORMAT_CSV)) // csv + else if(!strsame(name, DATASOURCE_FORMAT_CSV)) // csv return DATASOURCE_CSV; - else if(!strcmp(name, DATASOURCE_FORMAT_TSV) || !strcmp(name, "tsv-excel")) // tsv + else if(!strsame(name, DATASOURCE_FORMAT_TSV) || !strsame(name, "tsv-excel")) // tsv return DATASOURCE_TSV; - else if(!strcmp(name, DATASOURCE_FORMAT_HTML)) // html + else if(!strsame(name, DATASOURCE_FORMAT_HTML)) // html return DATASOURCE_HTML; - else if(!strcmp(name, DATASOURCE_FORMAT_JS_ARRAY)) // array + else if(!strsame(name, DATASOURCE_FORMAT_JS_ARRAY)) // array return DATASOURCE_JS_ARRAY; - else if(!strcmp(name, DATASOURCE_FORMAT_SSV_COMMA)) // ssvcomma + else if(!strsame(name, DATASOURCE_FORMAT_SSV_COMMA)) // ssvcomma return DATASOURCE_SSV_COMMA; - else if(!strcmp(name, DATASOURCE_FORMAT_CSV_JSON_ARRAY)) // csvjsonarray + else if(!strsame(name, DATASOURCE_FORMAT_CSV_JSON_ARRAY)) // csvjsonarray return DATASOURCE_CSV_JSON_ARRAY; return DATASOURCE_JSON; @@ -613,16 +613,16 @@ uint32_t web_client_api_request_v1_data_format(char *name) uint32_t web_client_api_request_v1_data_google_format(char *name) { - if(!strcmp(name, "json")) + if(!strsame(name, "json")) return DATASOURCE_DATATABLE_JSONP; - else if(!strcmp(name, "html")) + else if(!strsame(name, "html")) return DATASOURCE_HTML; - else if(!strcmp(name, "csv")) + else if(!strsame(name, "csv")) return DATASOURCE_CSV; - else if(!strcmp(name, "tsv-excel")) + else if(!strsame(name, "tsv-excel")) return DATASOURCE_TSV; return DATASOURCE_JSON; @@ -655,19 +655,19 @@ const char *group_method2string(int group) { int web_client_api_request_v1_data_group(char *name, int def) { - if(!strcmp(name, "average")) + if(!strsame(name, "average")) return GROUP_AVERAGE; - else if(!strcmp(name, "min")) + else if(!strsame(name, "min")) return GROUP_MIN; - else if(!strcmp(name, "max")) + else if(!strsame(name, "max")) return GROUP_MAX; - else if(!strcmp(name, "sum")) + else if(!strsame(name, "sum")) return GROUP_SUM; - else if(!strcmp(name, "incremental-sum")) + else if(!strsame(name, "incremental-sum")) return GROUP_INCREMENTAL_SUM; return def; @@ -681,8 +681,8 @@ int web_client_api_request_v1_alarms(struct web_client *w, char *url) char *value = mystrsep(&url, "?&"); if (!value || !*value) continue; - if(!strcmp(value, "all")) all = 1; - else if(!strcmp(value, "active")) all = 0; + if(!strsame(value, "all")) all = 1; + else if(!strsame(value, "active")) all = 0; } buffer_flush(w->response.data); @@ -703,7 +703,7 @@ int web_client_api_request_v1_alarm_log(struct web_client *w, char *url) if(!name || !*name) continue; if(!value || !*value) continue; - if(!strcmp(name, "after")) after = strtoul(value, NULL, 0); + if(!strsame(name, "after")) after = strtoul(value, NULL, 0); } buffer_flush(w->response.data); @@ -730,7 +730,7 @@ int web_client_api_request_single_chart(struct web_client *w, char *url, void ca // name and value are now the parameters // they are not null and not empty - if(!strcmp(name, "chart")) chart = value; + if(!strsame(name, "chart")) chart = value; //else { /// buffer_sprintf(w->response.data, "Unknown parameter '%s' in request.", name); // goto cleanup; @@ -786,10 +786,10 @@ int web_client_api_request_v1_allmetrics(struct web_client *w, char *url) if(!name || !*name) continue; if(!value || !*value) continue; - if(!strcmp(name, "format")) { - if(!strcmp(value, ALLMETRICS_FORMAT_SHELL)) + if(!strsame(name, "format")) { + if(!strsame(value, ALLMETRICS_FORMAT_SHELL)) format = ALLMETRICS_SHELL; - else if(!strcmp(value, ALLMETRICS_FORMAT_PROMETHEUS)) + else if(!strsame(value, ALLMETRICS_FORMAT_PROMETHEUS)) format = ALLMETRICS_PROMETHEUS; else format = 0; @@ -858,32 +858,32 @@ int web_client_api_request_v1_badge(struct web_client *w, char *url) { // name and value are now the parameters // they are not null and not empty - if(!strcmp(name, "chart")) chart = value; - else if(!strcmp(name, "dimension") || !strcmp(name, "dim") || !strcmp(name, "dimensions") || !strcmp(name, "dims")) { + if(!strsame(name, "chart")) chart = value; + else if(!strsame(name, "dimension") || !strsame(name, "dim") || !strsame(name, "dimensions") || !strsame(name, "dims")) { if(!dimensions) dimensions = buffer_create(100); buffer_strcat(dimensions, "|"); buffer_strcat(dimensions, value); } - else if(!strcmp(name, "after")) after_str = value; - else if(!strcmp(name, "before")) before_str = value; - else if(!strcmp(name, "points")) points_str = value; - else if(!strcmp(name, "group")) { + else if(!strsame(name, "after")) after_str = value; + else if(!strsame(name, "before")) before_str = value; + else if(!strsame(name, "points")) points_str = value; + else if(!strsame(name, "group")) { group = web_client_api_request_v1_data_group(value, GROUP_AVERAGE); } - else if(!strcmp(name, "options")) { + else if(!strsame(name, "options")) { options |= web_client_api_request_v1_data_options(value); } - else if(!strcmp(name, "label")) label = value; - else if(!strcmp(name, "units")) units = value; - else if(!strcmp(name, "label_color")) label_color = value; - else if(!strcmp(name, "value_color")) value_color = value; - else if(!strcmp(name, "multiply")) multiply_str = value; - else if(!strcmp(name, "divide")) divide_str = value; - else if(!strcmp(name, "refresh")) refresh_str = value; - else if(!strcmp(name, "precision")) precision_str = value; - else if(!strcmp(name, "alarm")) alarm = value; + else if(!strsame(name, "label")) label = value; + else if(!strsame(name, "units")) units = value; + else if(!strsame(name, "label_color")) label_color = value; + else if(!strsame(name, "value_color")) value_color = value; + else if(!strsame(name, "multiply")) multiply_str = value; + else if(!strsame(name, "divide")) divide_str = value; + else if(!strsame(name, "refresh")) refresh_str = value; + else if(!strsame(name, "precision")) precision_str = value; + else if(!strsame(name, "alarm")) alarm = value; } if(!chart || !*chart) { @@ -924,7 +924,7 @@ int web_client_api_request_v1_badge(struct web_client *w, char *url) { int refresh = 0; if(refresh_str && *refresh_str) { - if(!strcmp(refresh_str, "auto")) { + if(!strsame(refresh_str, "auto")) { if(rc) refresh = rc->update_every; else if(options & RRDR_OPTION_NOT_ALIGNED) refresh = st->update_every; @@ -1121,31 +1121,31 @@ int web_client_api_request_v1_data(struct web_client *w, char *url) // name and value are now the parameters // they are not null and not empty - if(!strcmp(name, "chart")) chart = value; - else if(!strcmp(name, "dimension") || !strcmp(name, "dim") || !strcmp(name, "dimensions") || !strcmp(name, "dims")) { + if(!strsame(name, "chart")) chart = value; + else if(!strsame(name, "dimension") || !strsame(name, "dim") || !strsame(name, "dimensions") || !strsame(name, "dims")) { if(!dimensions) dimensions = buffer_create(100); buffer_strcat(dimensions, "|"); buffer_strcat(dimensions, value); } - else if(!strcmp(name, "after")) after_str = value; - else if(!strcmp(name, "before")) before_str = value; - else if(!strcmp(name, "points")) points_str = value; - else if(!strcmp(name, "group")) { + else if(!strsame(name, "after")) after_str = value; + else if(!strsame(name, "before")) before_str = value; + else if(!strsame(name, "points")) points_str = value; + else if(!strsame(name, "group")) { group = web_client_api_request_v1_data_group(value, GROUP_AVERAGE); } - else if(!strcmp(name, "format")) { + else if(!strsame(name, "format")) { format = web_client_api_request_v1_data_format(value); } - else if(!strcmp(name, "options")) { + else if(!strsame(name, "options")) { options |= web_client_api_request_v1_data_options(value); } - else if(!strcmp(name, "callback")) { + else if(!strsame(name, "callback")) { responseHandler = value; } - else if(!strcmp(name, "filename")) { + else if(!strsame(name, "filename")) { outFileName = value; } - else if(!strcmp(name, "tqx")) { + else if(!strsame(name, "tqx")) { // parse Google Visualization API options // https://developers.google.com/chart/interactive/docs/dev/implementing_data_source char *tqx_name, *tqx_value; @@ -1158,21 +1158,21 @@ int web_client_api_request_v1_data(struct web_client *w, char *url) if(!tqx_name || !*tqx_name) continue; if(!tqx_value || !*tqx_value) continue; - if(!strcmp(tqx_name, "version")) + if(!strsame(tqx_name, "version")) google_version = tqx_value; - else if(!strcmp(tqx_name, "reqId")) + else if(!strsame(tqx_name, "reqId")) google_reqId = tqx_value; - else if(!strcmp(tqx_name, "sig")) { + else if(!strsame(tqx_name, "sig")) { google_sig = tqx_value; google_timestamp = strtoul(google_sig, NULL, 0); } - else if(!strcmp(tqx_name, "out")) { + else if(!strsame(tqx_name, "out")) { google_out = tqx_value; format = web_client_api_request_v1_data_google_format(google_out); } - else if(!strcmp(tqx_name, "responseHandler")) + else if(!strsame(tqx_name, "responseHandler")) responseHandler = tqx_value; - else if(!strcmp(tqx_name, "outFileName")) + else if(!strsame(tqx_name, "outFileName")) outFileName = tqx_value; } } @@ -1314,42 +1314,42 @@ int web_client_api_request_v1_registry(struct web_client *w, char *url) uint32_t hash = simple_hash(name); - if(hash == hash_action && !strcmp(name, "action")) { + if(hash == hash_action && !strsame(name, "action")) { uint32_t vhash = simple_hash(value); - if(vhash == hash_access && !strcmp(value, "access")) action = 'A'; - else if(vhash == hash_hello && !strcmp(value, "hello")) action = 'H'; - else if(vhash == hash_delete && !strcmp(value, "delete")) action = 'D'; - else if(vhash == hash_search && !strcmp(value, "search")) action = 'S'; - else if(vhash == hash_switch && !strcmp(value, "switch")) action = 'W'; + if(vhash == hash_access && !strsame(value, "access")) action = 'A'; + else if(vhash == hash_hello && !strsame(value, "hello")) action = 'H'; + else if(vhash == hash_delete && !strsame(value, "delete")) action = 'D'; + else if(vhash == hash_search && !strsame(value, "search")) action = 'S'; + else if(vhash == hash_switch && !strsame(value, "switch")) action = 'W'; #ifdef NETDATA_INTERNAL_CHECKS else error("unknown registry action '%s'", value); #endif /* NETDATA_INTERNAL_CHECKS */ } /* - else if(hash == hash_redirects && !strcmp(name, "redirects")) + else if(hash == hash_redirects && !strsame(name, "redirects")) redirects = atoi(value); */ - else if(hash == hash_machine && !strcmp(name, "machine")) + else if(hash == hash_machine && !strsame(name, "machine")) machine_guid = value; - else if(hash == hash_url && !strcmp(name, "url")) + else if(hash == hash_url && !strsame(name, "url")) machine_url = value; else if(action == 'A') { - if(hash == hash_name && !strcmp(name, "name")) + if(hash == hash_name && !strsame(name, "name")) url_name = value; } else if(action == 'D') { - if(hash == hash_delete_url && !strcmp(name, "delete_url")) + if(hash == hash_delete_url && !strsame(name, "delete_url")) delete_url = value; } else if(action == 'S') { - if(hash == hash_for && !strcmp(name, "for")) + if(hash == hash_for && !strsame(name, "for")) search_machine_guid = value; } else if(action == 'W') { - if(hash == hash_to && !strcmp(name, "to")) + if(hash == hash_to && !strsame(name, "to")) to_person_guid = value; } #ifdef NETDATA_INTERNAL_CHECKS @@ -1440,31 +1440,31 @@ int web_client_api_request_v1(struct web_client *w, char *url) { debug(D_WEB_CLIENT, "%llu: Searching for API v1 command '%s'.", w->id, tok); uint32_t hash = simple_hash(tok); - if(hash == hash_data && !strcmp(tok, "data")) + if(hash == hash_data && !strsame(tok, "data")) return web_client_api_request_v1_data(w, url); - else if(hash == hash_chart && !strcmp(tok, "chart")) + else if(hash == hash_chart && !strsame(tok, "chart")) return web_client_api_request_v1_chart(w, url); - else if(hash == hash_charts && !strcmp(tok, "charts")) + else if(hash == hash_charts && !strsame(tok, "charts")) return web_client_api_request_v1_charts(w, url); - else if(hash == hash_registry && !strcmp(tok, "registry")) + else if(hash == hash_registry && !strsame(tok, "registry")) return web_client_api_request_v1_registry(w, url); - else if(hash == hash_badge && !strcmp(tok, "badge.svg")) + else if(hash == hash_badge && !strsame(tok, "badge.svg")) return web_client_api_request_v1_badge(w, url); - else if(hash == hash_alarms && !strcmp(tok, "alarms")) + else if(hash == hash_alarms && !strsame(tok, "alarms")) return web_client_api_request_v1_alarms(w, url); - else if(hash == hash_alarm_log && !strcmp(tok, "alarm_log")) + else if(hash == hash_alarm_log && !strsame(tok, "alarm_log")) return web_client_api_request_v1_alarm_log(w, url); - else if(hash == hash_alarm_variables && !strcmp(tok, "alarm_variables")) + else if(hash == hash_alarm_variables && !strsame(tok, "alarm_variables")) return web_client_api_request_v1_alarm_variables(w, url); - else if(hash == hash_raw && !strcmp(tok, "allmetrics")) + else if(hash == hash_raw && !strsame(tok, "allmetrics")) return web_client_api_request_v1_allmetrics(w, url); else { @@ -1487,7 +1487,7 @@ int web_client_api_request(struct web_client *w, char *url) char *tok = mystrsep(&url, "/?&"); if(tok && *tok) { debug(D_WEB_CLIENT, "%llu: Searching for API version '%s'.", w->id, tok); - if(strcmp(tok, "v1") == 0) + if(strsame(tok, "v1") == 0) return web_client_api_request_v1(w, url); else { buffer_flush(w->response.data); @@ -1564,9 +1564,9 @@ int web_client_api_old_data_request(struct web_client *w, char *url, int datasou // parse the grouping method required tok = mystrsep(&url, "/"); if(tok && *tok) { - if(strcmp(tok, "max") == 0) group_method = GROUP_MAX; - else if(strcmp(tok, "average") == 0) group_method = GROUP_AVERAGE; - else if(strcmp(tok, "sum") == 0) group_method = GROUP_SUM; + if(strsame(tok, "max") == 0) group_method = GROUP_MAX; + else if(strsame(tok, "average") == 0) group_method = GROUP_AVERAGE; + else if(strsame(tok, "sum") == 0) group_method = GROUP_SUM; else debug(D_WEB_CLIENT, "%llu: Unknown group method '%s'", w->id, tok); } } @@ -1585,7 +1585,7 @@ int web_client_api_old_data_request(struct web_client *w, char *url, int datasou if(url) { // parse nonzero tok = mystrsep(&url, "/"); - if(tok && *tok && strcmp(tok, "nonzero") == 0) nonzero = 1; + if(tok && *tok && strsame(tok, "nonzero") == 0) nonzero = 1; } w->response.data->contenttype = CT_APPLICATION_JSON; @@ -1606,26 +1606,26 @@ int web_client_api_old_data_request(struct web_client *w, char *url, int datasou tok = mystrsep(&args, "&"); if(tok && *tok) { char *name = mystrsep(&tok, "="); - if(name && *name && strcmp(name, "tqx") == 0) { + if(name && *name && strsame(name, "tqx") == 0) { char *key = mystrsep(&tok, ":"); char *value = mystrsep(&tok, ";"); if(key && value && *key && *value) { - if(strcmp(key, "version") == 0) + if(strsame(key, "version") == 0) google_version = value; - else if(strcmp(key, "reqId") == 0) + else if(strsame(key, "reqId") == 0) google_reqId = value; - else if(strcmp(key, "sig") == 0) + else if(strsame(key, "sig") == 0) google_sig = value; - else if(strcmp(key, "out") == 0) + else if(strsame(key, "out") == 0) google_out = value; - else if(strcmp(key, "responseHandler") == 0) + else if(strsame(key, "responseHandler") == 0) google_responseHandler = value; - else if(strcmp(key, "outFileName") == 0) + else if(strsame(key, "outFileName") == 0) google_outFileName = value; } } @@ -1640,7 +1640,7 @@ int web_client_api_old_data_request(struct web_client *w, char *url, int datasou last_timestamp_in_data = strtoul(google_sig, NULL, 0); // check the client wants json - if(strcmp(google_out, "json") != 0) { + if(strsame(google_out, "json") != 0) { buffer_sprintf(w->response.data, "%s({version:'%s',reqId:'%s',status:'error',errors:[{reason:'invalid_query',message:'output format is not supported',detailed_message:'the format %s requested is not supported by netdata.'}]});", google_responseHandler, google_version, google_reqId, google_out); @@ -2012,11 +2012,11 @@ void web_client_process(struct web_client *w) { uint32_t hash = simple_hash(tok); debug(D_WEB_CLIENT, "%llu: Processing command '%s'.", w->id, tok); - if(hash == hash_api && strcmp(tok, "api") == 0) { + if(hash == hash_api && strsame(tok, "api") == 0) { // the client is requesting api access code = web_client_api_request(w, url); } - else if(hash == hash_netdata_conf && strcmp(tok, "netdata.conf") == 0) { + else if(hash == hash_netdata_conf && strsame(tok, "netdata.conf") == 0) { code = 200; debug(D_WEB_CLIENT_ACCESS, "%llu: Sending netdata.conf ...", w->id); @@ -2024,15 +2024,15 @@ void web_client_process(struct web_client *w) { buffer_flush(w->response.data); generate_config(w->response.data, 0); } - else if(hash == hash_data && strcmp(tok, WEB_PATH_DATA) == 0) { // "data" + else if(hash == hash_data && strsame(tok, WEB_PATH_DATA) == 0) { // "data" // the client is requesting rrd data -- OLD API code = web_client_api_old_data_request(w, url, DATASOURCE_JSON); } - else if(hash == hash_datasource && strcmp(tok, WEB_PATH_DATASOURCE) == 0) { // "datasource" + else if(hash == hash_datasource && strsame(tok, WEB_PATH_DATASOURCE) == 0) { // "datasource" // the client is requesting google datasource -- OLD API code = web_client_api_old_data_request(w, url, DATASOURCE_DATATABLE_JSONP); } - else if(hash == hash_graph && strcmp(tok, WEB_PATH_GRAPH) == 0) { // "graph" + else if(hash == hash_graph && strsame(tok, WEB_PATH_GRAPH) == 0) { // "graph" // the client is requesting an rrd graph -- OLD API // get the name of the data to show @@ -2063,7 +2063,7 @@ void web_client_process(struct web_client *w) { buffer_strcat(w->response.data, "Graph name?\r\n"); } } - else if(hash == hash_list && strcmp(tok, "list") == 0) { + else if(hash == hash_list && strsame(tok, "list") == 0) { // OLD API code = 200; @@ -2075,7 +2075,7 @@ void web_client_process(struct web_client *w) { for ( ; st ; st = st->next ) buffer_sprintf(w->response.data, "%s\n", st->name); } - else if(hash == hash_all_json && strcmp(tok, "all.json") == 0) { + else if(hash == hash_all_json && strsame(tok, "all.json") == 0) { // OLD API code = 200; debug(D_WEB_CLIENT_ACCESS, "%llu: Sending JSON list of all monitors of RRD_STATS...", w->id); @@ -2085,7 +2085,7 @@ void web_client_process(struct web_client *w) { rrd_stats_all_json(w->response.data); } #ifdef NETDATA_INTERNAL_CHECKS - else if(hash == hash_exit && strcmp(tok, "exit") == 0) { + else if(hash == hash_exit && strsame(tok, "exit") == 0) { code = 200; w->response.data->contenttype = CT_TEXT_PLAIN; buffer_flush(w->response.data); @@ -2098,7 +2098,7 @@ void web_client_process(struct web_client *w) { error("web request to exit received."); netdata_cleanup_and_exit(0); } - else if(hash == hash_debug && strcmp(tok, "debug") == 0) { + else if(hash == hash_debug && strsame(tok, "debug") == 0) { buffer_flush(w->response.data); // get the name of the data to show @@ -2130,7 +2130,7 @@ void web_client_process(struct web_client *w) { buffer_strcat(w->response.data, "debug which chart?\r\n"); } } - else if(hash == hash_mirror && strcmp(tok, "mirror") == 0) { + else if(hash == hash_mirror && strsame(tok, "mirror") == 0) { code = 200; debug(D_WEB_CLIENT_ACCESS, "%llu: Mirroring...", w->id); diff --git a/src/web_server.c b/src/web_server.c index 8e942a59..20b25f0a 100644 --- a/src/web_server.c +++ b/src/web_server.c @@ -256,7 +256,7 @@ static inline int bind_to_one(const char *definition, int default_port, int list *e = '\0'; } - if(!*ip || *ip == '*' || !strcmp(ip, "any") || !strcmp(ip, "all")) + if(!*ip || *ip == '*' || !strsame(ip, "any") || !strsame(ip, "all")) ip = NULL; if(!*port) port = buffer2; -- 2.39.2