user_data_t
From collectd Wiki
The value_list_t data structure is used to pass custom information to callback functions, such as read callbacks. The struct contains a void pointer to the actual data and a function pointer. If the function pointer is not NULL, it will be used to free the user data when the callback is not longer used.
[edit] Definition of the struct
The structure is defined in src/plugin.h as follows:
struct user_data_s { void *data; void (*free_func) (void *); }; typedef struct user_data_s user_data_t;
[edit] Example
static int my_config (oconfig_item_t *ci) { my_config_t *my_cfg; … /* configure and fill in "my_cfg" */ … if (all_went_well) { user_data_t ud; memset (&ud, 0, sizeof (ud)); ud.data = (void *) my_cfg; ud.free_func = my_config_free; plugin_register_complex_read ("my_read", /* callback = */ my_read, /* interval = */ NULL, /* userdata = */ &ud); } /* if (all_went_well) */ return (0); } /* int my_config */
This example shows how to pass a pointer my_cfg to the callback function my_read. If the callback is deleted, the struct is freed using the my_config_free function.
For real-world examples take a look at src/mysql.c and src/netapp.c.

