X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fdaemon%2Fcommon.h;h=c3f7f5485cb5888ed7a95634e538ff9c35b82d46;hb=d061c270fabc5dba961cf2b94ebe968e9a89b899;hp=434ed019bc2d1a2359db6bbcf8d982fba98e091c;hpb=216c6246b73645ac093de15b87aedc9abc6ebc80;p=collectd.git diff --git a/src/daemon/common.h b/src/daemon/common.h index 434ed019..720e5f1b 100644 --- a/src/daemon/common.h +++ b/src/daemon/common.h @@ -29,6 +29,7 @@ #define COMMON_H #include "collectd.h" + #include "plugin.h" #if HAVE_PWD_H @@ -37,9 +38,7 @@ #define sfree(ptr) \ do { \ - if((ptr) != NULL) { \ - free(ptr); \ - } \ + free(ptr); \ (ptr) = NULL; \ } while (0) @@ -186,6 +185,27 @@ int strjoin (char *dst, size_t dst_len, char **fields, size_t fields_num, const */ int escape_slashes (char *buffer, size_t buffer_size); +/** + * NAME + * escape_string + * + * DESCRIPTION + * escape_string quotes and escapes a string to be usable with collectd's + * plain text protocol. "simple" strings are left as they are, for example if + * buffer is 'simple' before the call, it will remain 'simple'. However, if + * buffer contains 'more "complex"' before the call, the returned buffer will + * contain '"more \"complex\""'. + * + * If the buffer is too small to contain the escaped string, the string will + * be truncated. However, leading and trailing double quotes, as well as an + * ending null byte are guaranteed. + * + * RETURN VALUE + * Returns zero on success, even if the string was truncated. Non-zero on + * failure. + */ +int escape_string (char *buffer, size_t buffer_size); + /* * NAME * replace_special @@ -203,8 +223,6 @@ int escape_slashes (char *buffer, size_t buffer_size); */ void replace_special (char *buffer, size_t buffer_size); -int strsubstitute (char *str, char c_from, char c_to); - /* * NAME * strunescape @@ -336,13 +354,16 @@ counter_t counter_diff (counter_t old_value, counter_t new_value); int rate_to_value (value_t *ret_value, gauge_t rate, rate_to_value_state_t *state, int ds_type, cdtime_t t); -int value_to_rate (value_t *ret_rate, derive_t value, - value_to_rate_state_t *state, int ds_type, cdtime_t t); +int value_to_rate (gauge_t *ret_rate, value_t value, int ds_type, cdtime_t t, + value_to_rate_state_t *state); /* Converts a service name (a string) to a port number * (in the range [1-65535]). Returns less than zero on error. */ int service_name_to_port_number (const char *service_name); +/* Sets various, non-default, socket options */ +void set_sock_opts (int sockfd); + /** Parse a string to a derive_t value. Returns zero on success or non-zero on * failure. If failure is returned, ret_value is not touched. */ int strtoderive (const char *string, derive_t *ret_value); @@ -354,4 +375,12 @@ int strtogauge (const char *string, gauge_t *ret_value); int strarray_add (char ***ret_array, size_t *ret_array_len, char const *str); void strarray_free (char **array, size_t array_len); +#ifdef HAVE_SYS_CAPABILITY_H +/** Check if the current process benefits from the capability passed in + * argument. Returns zero if it does, less than zero if it doesn't or on error. + * See capabilities(7) for the list of possible capabilities. + * */ +int check_capability (int capability); +#endif /* HAVE_SYS_CAPABILITY_H */ + #endif /* COMMON_H */