X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fdaemon%2Fcommon.c;h=212d72c900b5d1c41b9df1e2a27bcb09e85f704b;hb=4979d8dcd6f097eb8fd4661086e28accd31ff905;hp=05b119901ce2bf9a606a4e07c1ed45b7c2d78ce7;hpb=f0d468892e1c173b226f739be48291981473b4fb;p=collectd.git diff --git a/src/daemon/common.c b/src/daemon/common.c index 05b11990..212d72c9 100644 --- a/src/daemon/common.c +++ b/src/daemon/common.c @@ -60,7 +60,7 @@ # include #endif -#ifdef HAVE_SYS_CAPABILITY_H +#if HAVE_CAPABILITY # include #endif @@ -68,6 +68,11 @@ extern kstat_ctl_t *kc; #endif +/* AIX doesn't have MSG_DONTWAIT */ +#ifndef MSG_DONTWAIT +# define MSG_DONTWAIT MSG_NONBLOCK +#endif + #if !HAVE_GETPWNAM_R static pthread_mutex_t getpwnam_r_lock = PTHREAD_MUTEX_INITIALIZER; #endif @@ -1124,7 +1129,7 @@ int parse_value (const char *value_orig, value_t *ret_value, int ds_type) } if (value == endptr) { - ERROR ("parse_value: Failed to parse string as %s: %s.", + ERROR ("parse_value: Failed to parse string as %s: \"%s\".", DS_TYPE_TO_STRING (ds_type), value); sfree (value); return -1; @@ -1673,51 +1678,25 @@ void strarray_free (char **array, size_t array_len) /* {{{ */ sfree (array); } /* }}} void strarray_free */ -#ifdef HAVE_SYS_CAPABILITY_H -int check_capability (int capability) /* {{{ */ +#if HAVE_CAPABILITY +int check_capability (int arg) /* {{{ */ { -#ifdef _LINUX_CAPABILITY_VERSION_3 - cap_user_header_t cap_header = calloc(1, sizeof (*cap_header)); - if (cap_header == NULL) - { - ERROR("check_capability: calloc failed"); - return (-1); - } + cap_value_t cap = (cap_value_t) arg; - cap_user_data_t cap_data = calloc(1, sizeof (*cap_data)); - if (cap_data == NULL) - { - ERROR("check_capability: calloc failed"); - sfree(cap_header); + if (!CAP_IS_SUPPORTED (cap)) return (-1); - } - cap_header->pid = getpid(); - cap_header->version = _LINUX_CAPABILITY_VERSION; - if (capget(cap_header, cap_data) < 0) - { - ERROR("check_capability: capget failed"); - sfree(cap_header); - sfree(cap_data); + int have_cap = cap_get_bound (cap); + if (have_cap != 1) return (-1); - } - if ((cap_data->effective & (1 << capability)) == 0) - { - sfree(cap_header); - sfree(cap_data); - return (-1); - } - else - { - sfree(cap_header); - sfree(cap_data); - return (0); - } + return (0); +} /* }}} int check_capability */ #else +int check_capability (__attribute__((unused)) int arg) /* {{{ */ +{ WARNING ("check_capability: unsupported capability implementation. " - "Some plugin(s) may require elevated privileges to work properly."); + "Some plugin(s) may require elevated privileges to work properly."); return (0); -#endif /* _LINUX_CAPABILITY_VERSION_3 */ } /* }}} int check_capability */ -#endif /* HAVE_SYS_CAPABILITY_H */ +#endif /* HAVE_CAPABILITY */