X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fvarnish.c;h=7c5a9ef07fa980adc102d57356da3b9b4b50259c;hb=c99e3a4d169ada9299c73e20662d17debdc32e1f;hp=99485a1493906c546de5f6e32b5f5c22b8c5ba2b;hpb=79963d13c1884d1d92667cc502ad20758b084a12;p=collectd.git diff --git a/src/varnish.c b/src/varnish.c index 99485a14..7c5a9ef0 100644 --- a/src/varnish.c +++ b/src/varnish.c @@ -94,46 +94,39 @@ static int varnish_submit(const char *plugin_instance, /* {{{ */ vl.values = &value; vl.values_len = 1; - sstrncpy(vl.host, hostname_g, sizeof(vl.host)); - sstrncpy(vl.plugin, "varnish", sizeof(vl.plugin)); if (plugin_instance == NULL) plugin_instance = "default"; - - ssnprintf(vl.plugin_instance, sizeof(vl.plugin_instance), "%s-%s", - plugin_instance, category); + snprintf(vl.plugin_instance, sizeof(vl.plugin_instance), "%s-%s", + plugin_instance, category); sstrncpy(vl.type, type, sizeof(vl.type)); if (type_instance != NULL) sstrncpy(vl.type_instance, type_instance, sizeof(vl.type_instance)); - return (plugin_dispatch_values(&vl)); + return plugin_dispatch_values(&vl); } /* }}} int varnish_submit */ static int varnish_submit_gauge(const char *plugin_instance, /* {{{ */ const char *category, const char *type, const char *type_instance, uint64_t gauge_value) { - value_t value; - - value.gauge = (gauge_t)gauge_value; - - return ( - varnish_submit(plugin_instance, category, type, type_instance, value)); + return varnish_submit(plugin_instance, category, type, type_instance, + (value_t){ + .gauge = (gauge_t)gauge_value, + }); } /* }}} int varnish_submit_gauge */ static int varnish_submit_derive(const char *plugin_instance, /* {{{ */ const char *category, const char *type, const char *type_instance, uint64_t derive_value) { - value_t value; - - value.derive = (derive_t)derive_value; - - return ( - varnish_submit(plugin_instance, category, type, type_instance, value)); + return varnish_submit(plugin_instance, category, type, type_instance, + (value_t){ + .derive = (derive_t)derive_value, + }); } /* }}} int varnish_submit_derive */ #if HAVE_VARNISH_V3 || HAVE_VARNISH_V4 @@ -146,7 +139,7 @@ static int varnish_monitor(void *priv, const char *name; if (pt == NULL) - return (0); + return 0; conf = priv; @@ -155,14 +148,14 @@ static int varnish_monitor(void *priv, name = pt->desc->name; if (strcmp(class, "MAIN") != 0) - return (0); + return 0; #elif HAVE_VARNISH_V3 class = pt->class; name = pt->name; if (strcmp(class, "") != 0) - return (0); + return 0; #endif val = *(const volatile uint64_t *)pt->ptr; @@ -640,7 +633,7 @@ static int varnish_monitor(void *priv, } #endif - return (0); + return 0; } /* }}} static int varnish_monitor */ #else /* if HAVE_VARNISH_V2 */ @@ -992,7 +985,7 @@ static int varnish_read(user_data_t *ud) /* {{{ */ user_config_t *conf; if ((ud == NULL) || (ud->data == NULL)) - return (EINVAL); + return EINVAL; conf = ud->data; @@ -1010,7 +1003,7 @@ static int varnish_read(user_data_t *ud) /* {{{ */ ERROR("varnish plugin: VSM_n_Arg (\"%s\") failed " "with status %i.", conf->instance, status); - return (-1); + return -1; } } @@ -1023,7 +1016,7 @@ static int varnish_read(user_data_t *ud) /* {{{ */ VSM_Delete(vd); ERROR("varnish plugin: Unable to open connection."); - return (-1); + return -1; } #if HAVE_VARNISH_V3 @@ -1035,7 +1028,7 @@ static int varnish_read(user_data_t *ud) /* {{{ */ VSM_Delete(vd); ERROR("varnish plugin: Unable to get statistics."); - return (-1); + return -1; } #if HAVE_VARNISH_V3 @@ -1045,7 +1038,7 @@ static int varnish_read(user_data_t *ud) /* {{{ */ #endif VSM_Delete(vd); - return (0); + return 0; } /* }}} */ #else /* if HAVE_VARNISH_V2 */ static int varnish_read(user_data_t *ud) /* {{{ */ @@ -1055,7 +1048,7 @@ static int varnish_read(user_data_t *ud) /* {{{ */ user_config_t *conf; if ((ud == NULL) || (ud->data == NULL)) - return (EINVAL); + return EINVAL; conf = ud->data; @@ -1063,12 +1056,12 @@ static int varnish_read(user_data_t *ud) /* {{{ */ if (stats == NULL) { ERROR("Varnish plugin : unable to load statistics"); - return (-1); + return -1; } varnish_monitor(conf, stats); - return (0); + return 0; } /* }}} */ #endif @@ -1086,7 +1079,7 @@ static void varnish_config_free(void *ptr) /* {{{ */ static int varnish_config_apply_default(user_config_t *conf) /* {{{ */ { if (conf == NULL) - return (EINVAL); + return EINVAL; conf->collect_backend = 1; conf->collect_cache = 1; @@ -1121,7 +1114,7 @@ static int varnish_config_apply_default(user_config_t *conf) /* {{{ */ conf->collect_vsm = 0; #endif - return (0); + return 0; } /* }}} int varnish_config_apply_default */ static int varnish_init(void) /* {{{ */ @@ -1129,37 +1122,37 @@ static int varnish_init(void) /* {{{ */ user_config_t *conf; if (have_instance) - return (0); + return 0; conf = calloc(1, sizeof(*conf)); if (conf == NULL) - return (ENOMEM); + return ENOMEM; /* Default settings: */ conf->instance = NULL; varnish_config_apply_default(conf); - user_data_t ud = {.data = conf, .free_func = varnish_config_free}; - - plugin_register_complex_read(/* group = */ "varnish", - /* name = */ "varnish/localhost", - /* callback = */ varnish_read, - /* interval = */ 0, - /* user data = */ &ud); + plugin_register_complex_read( + /* group = */ "varnish", + /* name = */ "varnish/localhost", + /* callback = */ varnish_read, + /* interval = */ 0, + &(user_data_t){ + .data = conf, .free_func = varnish_config_free, + }); - return (0); + return 0; } /* }}} int varnish_init */ static int varnish_config_instance(const oconfig_item_t *ci) /* {{{ */ { user_config_t *conf; - user_data_t ud; char callback_name[DATA_MAX_NAME_LEN]; conf = calloc(1, sizeof(*conf)); if (conf == NULL) - return (ENOMEM); + return ENOMEM; conf->instance = NULL; varnish_config_apply_default(conf); @@ -1170,7 +1163,7 @@ static int varnish_config_instance(const oconfig_item_t *ci) /* {{{ */ status = cf_util_get_string(ci, &conf->instance); if (status != 0) { sfree(conf); - return (status); + return status; } assert(conf->instance != NULL); @@ -1182,7 +1175,7 @@ static int varnish_config_instance(const oconfig_item_t *ci) /* {{{ */ WARNING("Varnish plugin: \"Instance\" blocks accept only " "one argument."); sfree(conf); - return (EINVAL); + return EINVAL; } for (int i = 0; i < ci->children_num; i++) { @@ -1302,24 +1295,24 @@ static int varnish_config_instance(const oconfig_item_t *ci) /* {{{ */ "instance \"%s\". Disabling this instance.", (conf->instance == NULL) ? "localhost" : conf->instance); sfree(conf); - return (EINVAL); + return EINVAL; } - ssnprintf(callback_name, sizeof(callback_name), "varnish/%s", - (conf->instance == NULL) ? "localhost" : conf->instance); + snprintf(callback_name, sizeof(callback_name), "varnish/%s", + (conf->instance == NULL) ? "localhost" : conf->instance); - ud.data = conf; - ud.free_func = varnish_config_free; - - plugin_register_complex_read(/* group = */ "varnish", - /* name = */ callback_name, - /* callback = */ varnish_read, - /* interval = */ 0, - /* user data = */ &ud); + plugin_register_complex_read( + /* group = */ "varnish", + /* name = */ callback_name, + /* callback = */ varnish_read, + /* interval = */ 0, + &(user_data_t){ + .data = conf, .free_func = varnish_config_free, + }); have_instance = 1; - return (0); + return 0; } /* }}} int varnish_config_instance */ static int varnish_config(oconfig_item_t *ci) /* {{{ */ @@ -1336,7 +1329,7 @@ static int varnish_config(oconfig_item_t *ci) /* {{{ */ } } - return (0); + return 0; } /* }}} int varnish_config */ void module_register(void) /* {{{ */ @@ -1344,5 +1337,3 @@ void module_register(void) /* {{{ */ plugin_register_complex_config("varnish", varnish_config); plugin_register_init("varnish", varnish_init); } /* }}} */ - -/* vim: set sw=8 noet fdm=marker : */