X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fdaemon%2Fcommon.h;h=9a9ae0d3fd30cc019af7da63eedefaa379f1cdd3;hb=afb38f31abd27d5b4ce08023f8bbbaeeb353c55f;hp=da21cad9a6f3a81f1120b466740a669ec009c231;hpb=dc2eb041159b967838a2eb658cb256bc846c5264;p=collectd.git diff --git a/src/daemon/common.h b/src/daemon/common.h index da21cad9..9a9ae0d3 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) @@ -148,10 +147,12 @@ int strsplit (char *string, char **fields, size_t size); * is equivalent to the Perl built-in `join'. * * PARAMETERS - * `dst' Buffer where the result is stored. + * `dst' Buffer where the result is stored. Can be NULL if you need to + * determine the required buffer size only. * `dst_len' Length of the destination buffer. No more than this many * bytes will be written to the memory pointed to by `dst', - * including the trailing null-byte. + * including the trailing null-byte. Must be zero if dst is + * NULL. * `fields' Array of strings to be joined. * `fields_num' Number of elements in the `fields' array. * `sep' String to be inserted between any two elements of `fields'. @@ -159,9 +160,10 @@ int strsplit (char *string, char **fields, size_t size); * Instead of passing "" (empty string) one can pass NULL. * * RETURN VALUE - * Returns the number of characters in `dst', NOT including the trailing - * null-byte. If an error occurred (empty array or `dst' too small) a value - * smaller than zero will be returned. + * Returns the number of characters in the resulting string, excluding a + * tailing null byte. If this value is greater than or equal to "dst_len", the + * result in "dst" is truncated (but still null terminated). On error a + * negative value is returned. */ int strjoin (char *dst, size_t dst_len, char **fields, size_t fields_num, const char *sep); @@ -224,8 +226,6 @@ int escape_string (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 @@ -357,13 +357,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); @@ -375,4 +378,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 */