Skip to content

Commit

Permalink
Auto-Merge pull request collectd#4243 from eero-t/gcc-pedantic
Browse files Browse the repository at this point in the history
Automatically merged due to "Automerge" label
  • Loading branch information
collectd-bot committed Jan 27, 2024
2 parents 08a2a01 + d9d5025 commit 77ffdb9
Show file tree
Hide file tree
Showing 10 changed files with 129 additions and 115 deletions.
17 changes: 7 additions & 10 deletions .gitignore
Expand Up @@ -13,13 +13,7 @@ Makefile.in
/install-sh
/libltdl/
/ltmain.sh
/m4/libtool.m4
/m4/ltargz.m4
/m4/ltdl.m4
/m4/lt~obsolete.m4
/m4/ltoptions.m4
/m4/ltsugar.m4
/m4/ltversion.m4
/m4/
/missing
/src/config.h.in

Expand All @@ -40,6 +34,7 @@ src/stamp-h1
.dirstamp
.libs/
.deps/
/collectd
/collectd-nagios
/collectd-tg
/collectdctl
Expand Down Expand Up @@ -87,12 +82,13 @@ bindings/perl/pm_to_blib
*.pyc

# backup stuff
*.bak
*~

# lint stuff
*.ln

#ide stuff
# IDE stuff
.vscode

# cscope stuff
Expand All @@ -103,5 +99,6 @@ test-suite.log
src/tests/
test_*

# src/daemon/...
/collectd
# coverage data
*.gcov
*.gcno
67 changes: 35 additions & 32 deletions src/daemon/plugin.c
Expand Up @@ -60,11 +60,14 @@

#include <dlfcn.h>

/* except for plugin_log_cb, all callback types return an int */
typedef int (*placeholder_cb_t)(void);

/*
* Private structures
*/
struct callback_func_s {
void *cf_callback;
placeholder_cb_t cf_callback;
user_data_t cf_udata;
plugin_ctx_t cf_ctx;
};
Expand Down Expand Up @@ -349,7 +352,7 @@ static int register_callback(llist_t **list, /* {{{ */
} /* }}} int register_callback */

static int create_register_callback(llist_t **list, /* {{{ */
const char *name, void *callback,
const char *name, placeholder_cb_t callback,
user_data_t const *ud) {

if (name == NULL || callback == NULL)
Expand Down Expand Up @@ -427,7 +430,7 @@ static int plugin_load_file(char const *file, bool global) {
return ENOENT;
}

void (*reg_handle)(void) = (void *)dlsym(dlh, "module_register");
void (*reg_handle)(void) = dlsym(dlh, "module_register");
if (reg_handle == NULL) {
ERROR("Couldn't find symbol \"module_register\" in \"%s\": %s\n", file,
dlerror());
Expand Down Expand Up @@ -519,13 +522,13 @@ static void *plugin_read_thread(void __attribute__((unused)) * args) {
old_ctx = plugin_set_ctx(rf->rf_ctx);

if (rf_type == RF_SIMPLE) {
int (*callback)(void) = (void *)rf->rf_callback;
int (*callback)(void) = rf->rf_callback;

status = (*callback)();
} else {
assert(rf_type == RF_COMPLEX);

plugin_read_cb callback = (void *)rf->rf_callback;
plugin_read_cb callback = (plugin_read_cb)rf->rf_callback;
status = (*callback)(&rf->rf_udata);
}

Expand Down Expand Up @@ -1055,8 +1058,8 @@ EXPORT int plugin_register_complex_config(const char *type,
return cf_register_complex(type, callback);
} /* int plugin_register_complex_config */

EXPORT int plugin_register_init(const char *name, int (*callback)(void)) {
return create_register_callback(&list_init, name, (void *)callback, NULL);
EXPORT int plugin_register_init(const char *name, plugin_init_cb callback) {
return create_register_callback(&list_init, name, callback, NULL);
} /* plugin_register_init */

static int plugin_compare_read_func(const void *arg0, const void *arg1) {
Expand Down Expand Up @@ -1147,7 +1150,7 @@ EXPORT int plugin_register_read(const char *name, int (*callback)(void)) {
return ENOMEM;
}

rf->rf_callback = (void *)callback;
rf->rf_callback = callback;
rf->rf_udata.data = NULL;
rf->rf_udata.free_func = NULL;
rf->rf_ctx = plugin_get_ctx();
Expand Down Expand Up @@ -1180,7 +1183,7 @@ EXPORT int plugin_register_complex_read(const char *group, const char *name,
return ENOMEM;
}

rf->rf_callback = (void *)callback;
rf->rf_callback = (placeholder_cb_t)callback;
if (group != NULL)
sstrncpy(rf->rf_group, group, sizeof(rf->rf_group));
else
Expand Down Expand Up @@ -1299,8 +1302,8 @@ EXPORT int plugin_register_flush(const char *name, plugin_flush_cb callback,
user_data_t const *ud) {
plugin_ctx_t ctx = plugin_get_ctx();

int status =
create_register_callback(&list_flush, name, (void *)callback, ud);
int status = create_register_callback(&list_flush, name,
(placeholder_cb_t)callback, ud);
if (status != 0) {
return status;
}
Expand Down Expand Up @@ -1347,7 +1350,8 @@ EXPORT int plugin_register_flush(const char *name, plugin_flush_cb callback,

EXPORT int plugin_register_missing(const char *name, plugin_missing_cb callback,
user_data_t const *ud) {
return create_register_callback(&list_missing, name, (void *)callback, ud);
return create_register_callback(&list_missing, name,
(placeholder_cb_t)callback, ud);
} /* int plugin_register_missing */

EXPORT int plugin_register_cache_event(const char *name,
Expand Down Expand Up @@ -1405,20 +1409,22 @@ EXPORT int plugin_register_cache_event(const char *name,
return 0;
} /* int plugin_register_cache_event */

EXPORT int plugin_register_shutdown(const char *name, int (*callback)(void)) {
return create_register_callback(&list_shutdown, name, (void *)callback, NULL);
EXPORT int plugin_register_shutdown(const char *name,
plugin_shutdown_cb callback) {
return create_register_callback(&list_shutdown, name, callback, NULL);
} /* int plugin_register_shutdown */

EXPORT int plugin_register_log(const char *name, plugin_log_cb callback,
user_data_t const *ud) {
return create_register_callback(&list_log, name, (void *)callback, ud);
return create_register_callback(&list_log, name, (placeholder_cb_t)callback,
ud);
} /* int plugin_register_log */

EXPORT int plugin_register_notification(const char *name,
plugin_notification_cb callback,
user_data_t const *ud) {
return create_register_callback(&list_notification, name, (void *)callback,
ud);
return create_register_callback(&list_notification, name,
(placeholder_cb_t)callback, ud);
} /* int plugin_register_log */

EXPORT int plugin_unregister_config(const char *name) {
Expand Down Expand Up @@ -1742,7 +1748,7 @@ EXPORT int plugin_init_all(void) {
while (le != NULL) {
callback_func_t *cf = le->value;
plugin_ctx_t old_ctx = plugin_set_ctx(cf->cf_ctx);
plugin_init_cb callback = (void *)cf->cf_callback;
plugin_init_cb callback = cf->cf_callback;
status = (*callback)();
plugin_set_ctx(old_ctx);

Expand Down Expand Up @@ -1806,10 +1812,10 @@ EXPORT int plugin_read_all_once(void) {
old_ctx = plugin_set_ctx(rf->rf_ctx);

if (rf->rf_type == RF_SIMPLE) {
int (*callback)(void) = (void *)rf->rf_callback;
int (*callback)(void) = rf->rf_callback;
status = (*callback)();
} else {
plugin_read_cb callback = (void *)rf->rf_callback;
plugin_read_cb callback = (plugin_read_cb)rf->rf_callback;
status = (*callback)(&rf->rf_udata);
}

Expand All @@ -1821,7 +1827,7 @@ EXPORT int plugin_read_all_once(void) {
}

sfree(rf->rf_name);
destroy_callback((void *)rf);
destroy_callback((callback_func_t *)rf);
}

return return_status;
Expand Down Expand Up @@ -1872,7 +1878,7 @@ EXPORT int plugin_flush(const char *plugin, cdtime_t timeout,

callback_func_t *cf = le->value;
plugin_ctx_t old_ctx = plugin_set_ctx(cf->cf_ctx);
plugin_flush_cb callback = (void *)cf->cf_callback;
plugin_flush_cb callback = (plugin_flush_cb)cf->cf_callback;

(*callback)(timeout, identifier, &cf->cf_udata);

Expand Down Expand Up @@ -1913,7 +1919,7 @@ EXPORT int plugin_shutdown_all(void) {
while (le != NULL) {
callback_func_t *cf = le->value;
plugin_ctx_t old_ctx = plugin_set_ctx(cf->cf_ctx);
plugin_shutdown_cb callback = (void *)cf->cf_callback;
plugin_shutdown_cb callback = cf->cf_callback;

/* Advance the pointer before calling the callback allows
* shutdown functions to unregister themselves. If done the
Expand Down Expand Up @@ -1954,7 +1960,7 @@ EXPORT int plugin_dispatch_missing(metric_family_t const *fam) /* {{{ */
while (le != NULL) {
callback_func_t *cf = le->value;
plugin_ctx_t old_ctx = plugin_set_ctx(cf->cf_ctx);
plugin_missing_cb callback = cf->cf_callback;
plugin_missing_cb callback = (plugin_missing_cb)cf->cf_callback;

int status = (*callback)(fam, &cf->cf_udata);
plugin_set_ctx(old_ctx);
Expand Down Expand Up @@ -2153,16 +2159,13 @@ EXPORT int plugin_dispatch_notification(const notification_t *notif) {

le = llist_head(list_notification);
while (le != NULL) {
callback_func_t *cf;
plugin_notification_cb callback;
int status;

/* do not switch plugin context; rather keep the context
* (interval) information of the calling plugin */

cf = le->value;
callback = cf->cf_callback;
status = (*callback)(notif, &cf->cf_udata);
callback_func_t *cf = le->value;
plugin_notification_cb callback = (plugin_notification_cb)cf->cf_callback;

int status = (*callback)(notif, &cf->cf_udata);
if (status != 0) {
WARNING("plugin_dispatch_notification: Notification "
"callback %s returned %i.",
Expand Down Expand Up @@ -2198,7 +2201,7 @@ EXPORT void plugin_log(int level, const char *format, ...) {
le = llist_head(list_log);
while (le != NULL) {
callback_func_t *cf = le->value;
plugin_log_cb callback = (void *)cf->cf_callback;
plugin_log_cb callback = (plugin_log_cb)cf->cf_callback;

/* do not switch plugin context; rather keep the context
* (interval) information of the calling plugin */
Expand Down
82 changes: 43 additions & 39 deletions src/daemon/utils_cache.c
Expand Up @@ -909,7 +909,7 @@ static meta_data_t *uc_get_meta(metric_t const *m) /* {{{ */
/* Sorry about this preprocessor magic, but it really makes this file much
* shorter.. */
#define UC_WRAP(wrap_function) \
{ \
do { \
pthread_mutex_lock(&cache_lock); \
errno = 0; \
meta_data_t *meta = uc_get_meta(m); \
Expand All @@ -920,23 +920,23 @@ static meta_data_t *uc_get_meta(metric_t const *m) /* {{{ */
int ret = wrap_function(meta, key); \
pthread_mutex_unlock(&cache_lock); \
return ret; \
}

int uc_meta_data_exists(metric_t const *m, const char *key)
UC_WRAP(meta_data_exists);

int uc_meta_data_delete(metric_t const *m, const char *key)
UC_WRAP(meta_data_delete);
} while (0)

int uc_meta_data_exists(metric_t const *m, const char *key) {
UC_WRAP(meta_data_exists);
}
int uc_meta_data_delete(metric_t const *m, const char *key) {
UC_WRAP(meta_data_delete);
}
/* The second argument is called `toc` in the API, but the macro expects
* `key`. */
int uc_meta_data_toc(metric_t const *m, char ***key) UC_WRAP(meta_data_toc);
int uc_meta_data_toc(metric_t const *m, char ***key) { UC_WRAP(meta_data_toc); }
#undef UC_WRAP

/* We need a new version of this macro because the following functions take
* two argumetns. gratituous semicolons added for formatting sanity*/
* two arguments. Gratuitous semicolons added for formatting sanity. */
#define UC_WRAP(wrap_function) \
{ \
do { \
pthread_mutex_lock(&cache_lock); \
errno = 0; \
meta_data_t *meta = uc_get_meta(m); \
Expand All @@ -947,37 +947,41 @@ int uc_meta_data_toc(metric_t const *m, char ***key) UC_WRAP(meta_data_toc);
int ret = wrap_function(meta, key, value); \
pthread_mutex_unlock(&cache_lock); \
return ret; \
}
int uc_meta_data_add_string(metric_t const *m, const char *key,
const char *value) UC_WRAP(meta_data_add_string);
} while (0)

int uc_meta_data_add_string(metric_t const *m, const char *key,
const char *value) {
UC_WRAP(meta_data_add_string);
}
int uc_meta_data_add_signed_int(metric_t const *m, const char *key,
int64_t value)
UC_WRAP(meta_data_add_signed_int);

int64_t value) {
UC_WRAP(meta_data_add_signed_int);
}
int uc_meta_data_add_unsigned_int(metric_t const *m, const char *key,
uint64_t value)
UC_WRAP(meta_data_add_unsigned_int);

int uc_meta_data_add_double(metric_t const *m, const char *key, double value)
UC_WRAP(meta_data_add_double);
int uc_meta_data_add_boolean(metric_t const *m, const char *key, bool value)
UC_WRAP(meta_data_add_boolean);

int uc_meta_data_get_string(metric_t const *m, const char *key, char **value)
UC_WRAP(meta_data_get_string);

uint64_t value) {
UC_WRAP(meta_data_add_unsigned_int);
}
int uc_meta_data_add_double(metric_t const *m, const char *key, double value) {
UC_WRAP(meta_data_add_double);
}
int uc_meta_data_add_boolean(metric_t const *m, const char *key, bool value) {
UC_WRAP(meta_data_add_boolean);
}
int uc_meta_data_get_string(metric_t const *m, const char *key, char **value) {
UC_WRAP(meta_data_get_string);
}
int uc_meta_data_get_signed_int(metric_t const *m, const char *key,
int64_t *value)
UC_WRAP(meta_data_get_signed_int);

int64_t *value) {
UC_WRAP(meta_data_get_signed_int);
}
int uc_meta_data_get_unsigned_int(metric_t const *m, const char *key,
uint64_t *value)
UC_WRAP(meta_data_get_unsigned_int);

int uc_meta_data_get_double(metric_t const *m, const char *key, double *value)
UC_WRAP(meta_data_get_double);

int uc_meta_data_get_boolean(metric_t const *m, const char *key, bool *value)
UC_WRAP(meta_data_get_boolean);
uint64_t *value) {
UC_WRAP(meta_data_get_unsigned_int);
}
int uc_meta_data_get_double(metric_t const *m, const char *key, double *value) {
UC_WRAP(meta_data_get_double);
}
int uc_meta_data_get_boolean(metric_t const *m, const char *key, bool *value) {
UC_WRAP(meta_data_get_boolean);
}
#undef UC_WRAP
2 changes: 1 addition & 1 deletion src/redfish.c
Expand Up @@ -275,7 +275,7 @@ static int redfish_preconfig(void) {
goto error;

/* Creating placeholder for queries */
ctx.queries = c_avl_create((void *)strcmp);
ctx.queries = c_avl_create((int (*)(const void *, const void *))strcmp);
if (ctx.services == NULL)
goto free_services;

Expand Down

0 comments on commit 77ffdb9

Please sign in to comment.