From: Florian Forster Date: Sat, 17 Nov 2012 07:25:01 +0000 (+0100) Subject: Merge branch 'ff/netlib' X-Git-Tag: collectd-5.2.0~18 X-Git-Url: https://git.octo.it/?p=collectd.git;a=commitdiff_plain;h=3faf514fd9b869cadda0f895e14e5036313c7781 Merge branch 'ff/netlib' Conflicts: src/collectdctl.c src/libcollectdclient/client.c src/libcollectdclient/collectd/client.h --- 3faf514fd9b869cadda0f895e14e5036313c7781 diff --cc configure.in index 4a159767,af584425..7c4ec3a2 --- a/configure.in +++ b/configure.in @@@ -5102,9 -4761,9 +5102,9 @@@ AC_SUBST(LCC_VERSION_PATCH AC_SUBST(LCC_VERSION_EXTRA) AC_SUBST(LCC_VERSION_STRING) - AC_CONFIG_FILES(src/libcollectdclient/lcc_features.h) + AC_CONFIG_FILES(src/libcollectdclient/collectd/lcc_features.h) -AC_OUTPUT(Makefile src/Makefile src/collectd.conf src/owniptc/Makefile src/libcollectdclient/Makefile src/libcollectdclient/libcollectdclient.pc src/liboconfig/Makefile bindings/Makefile bindings/java/Makefile) +AC_OUTPUT(Makefile src/Makefile src/collectd.conf src/libcollectdclient/Makefile src/libcollectdclient/libcollectdclient.pc src/liboconfig/Makefile bindings/Makefile bindings/java/Makefile) if test "x$with_librrd" = "xyes" \ && test "x$librrd_threadsafe" != "xyes" diff --cc src/collectd-nagios.c index 88a53023,2d59ea77..e31d95ca --- a/src/collectd-nagios.c +++ b/src/collectd-nagios.c @@@ -34,39 -46,9 +34,39 @@@ #include #include #include -#include + +#if NAN_STATIC_DEFAULT +# include +/* #endif NAN_STATIC_DEFAULT*/ +#elif NAN_STATIC_ISOC +# ifndef __USE_ISOC99 +# define DISABLE_ISOC99 1 +# define __USE_ISOC99 1 +# endif /* !defined(__USE_ISOC99) */ +# include +# if DISABLE_ISOC99 +# undef DISABLE_ISOC99 +# undef __USE_ISOC99 +# endif /* DISABLE_ISOC99 */ +/* #endif NAN_STATIC_ISOC */ +#elif NAN_ZERO_ZERO +# include +# ifdef NAN +# undef NAN +# endif +# define NAN (0.0 / 0.0) +# ifndef isnan +# define isnan(f) ((f) != (f)) +# endif /* !defined(isnan) */ +# ifndef isfinite +# define isfinite(f) (((f) - (f)) == 0.0) +# endif +# ifndef isinf +# define isinf(f) (!isfinite(f) && !isnan(f)) +# endif +#endif /* NAN_ZERO_ZERO */ - #include "libcollectdclient/client.h" + #include "libcollectdclient/collectd/client.h" #define RET_OKAY 0 #define RET_WARNING 1 diff --cc src/collectdctl.c index 61b7fc55,f16a70dd..0b8d0c1e --- a/src/collectdctl.c +++ b/src/collectdctl.c @@@ -33,39 -45,10 +33,39 @@@ #include #include -#include -#include "libcollectdclient/collectd/client.h" +#if NAN_STATIC_DEFAULT +# include +/* #endif NAN_STATIC_DEFAULT*/ +#elif NAN_STATIC_ISOC +# ifndef __USE_ISOC99 +# define DISABLE_ISOC99 1 +# define __USE_ISOC99 1 +# endif /* !defined(__USE_ISOC99) */ +# include +# if DISABLE_ISOC99 +# undef DISABLE_ISOC99 +# undef __USE_ISOC99 +# endif /* DISABLE_ISOC99 */ +/* #endif NAN_STATIC_ISOC */ +#elif NAN_ZERO_ZERO +# include +# ifdef NAN +# undef NAN +# endif +# define NAN (0.0 / 0.0) +# ifndef isnan +# define isnan(f) ((f) != (f)) +# endif /* !defined(isnan) */ +# ifndef isfinite +# define isfinite(f) (((f) - (f)) == 0.0) +# endif +# ifndef isinf +# define isinf(f) (!isfinite(f) && !isnan(f)) +# endif +#endif /* NAN_ZERO_ZERO */ - #include "libcollectdclient/client.h" ++#include "libcollectdclient/collectd/client.h" #define DEFAULT_SOCK LOCALSTATEDIR"/run/"PACKAGE_NAME"-unixsock" diff --cc src/libcollectdclient/client.c index 2adf6d48,abe3ed83..39875903 --- a/src/libcollectdclient/client.c +++ b/src/libcollectdclient/client.c @@@ -1105,17 -1069,33 +1058,47 @@@ int lcc_string_to_identifier (lcc_conne return (0); } /* }}} int lcc_string_to_identifier */ + int lcc_identifier_compare (const lcc_identifier_t *i0, /* {{{ */ + const lcc_identifier_t *i1) + { + int status; + + if ((i0 == NULL) && (i1 == NULL)) + return (0); + else if (i0 == NULL) + return (-1); + else if (i1 == NULL) + return (1); + + #define CMP_FIELD(f) do { \ + status = strcmp (i0->f, i1->f); \ + if (status != 0) \ + return (status); \ + } while (0); + + CMP_FIELD (host); + CMP_FIELD (plugin); + CMP_FIELD (plugin_instance); + CMP_FIELD (type); + CMP_FIELD (type_instance); + + #undef CMP_FIELD + + return (0); + } /* }}} int lcc_identifier_compare */ + +int lcc_sort_identifiers (lcc_connection_t *c, /* {{{ */ + lcc_identifier_t *idents, size_t idents_num) +{ + if (idents == NULL) + { + lcc_set_errno (c, EINVAL); + return (-1); + } + - qsort (idents, idents_num, sizeof (*idents), lcc_identifier_cmp); ++ qsort (idents, idents_num, sizeof (*idents), ++ (void *) lcc_identifier_compare); + return (0); +} /* }}} int lcc_sort_identifiers */ + /* vim: set sw=2 sts=2 et fdm=marker : */ diff --cc src/libcollectdclient/collectd/client.h index 00000000,1494c8d6..b2354ff4 mode 000000,100644..100644 --- a/src/libcollectdclient/collectd/client.h +++ b/src/libcollectdclient/collectd/client.h @@@ -1,0 -1,128 +1,130 @@@ + /** + * libcollectdclient - src/libcollectdclient/client.h + * Copyright (C) 2008 Florian octo Forster + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; only version 2 of the License is applicable. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * Authors: + * Florian octo Forster + **/ + + #ifndef LIBCOLLECTD_COLLECTDCLIENT_H + #define LIBCOLLECTD_COLLECTDCLIENT_H 1 + + #include "lcc_features.h" + + /* + * Includes (for data types) + */ + #if HAVE_STDINT_H + # include + #endif + #include + #include + + /* + * Defines + */ + #define LCC_NAME_LEN 64 + #define LCC_DEFAULT_PORT "25826" + + /* + * Types + */ + #define LCC_TYPE_COUNTER 0 + #define LCC_TYPE_GAUGE 1 + #define LCC_TYPE_DERIVE 2 + #define LCC_TYPE_ABSOLUTE 3 + + LCC_BEGIN_DECLS + + typedef uint64_t counter_t; + typedef double gauge_t; + typedef uint64_t derive_t; + typedef uint64_t absolute_t; + + union value_u + { + counter_t counter; + gauge_t gauge; + derive_t derive; + absolute_t absolute; + }; + typedef union value_u value_t; + + struct lcc_identifier_s + { + char host[LCC_NAME_LEN]; + char plugin[LCC_NAME_LEN]; + char plugin_instance[LCC_NAME_LEN]; + char type[LCC_NAME_LEN]; + char type_instance[LCC_NAME_LEN]; + }; + typedef struct lcc_identifier_s lcc_identifier_t; + #define LCC_IDENTIFIER_INIT { "localhost", "", "", "", "" } + + struct lcc_value_list_s + { + value_t *values; + int *values_types; + size_t values_len; + time_t time; + int interval; + lcc_identifier_t identifier; + }; + typedef struct lcc_value_list_s lcc_value_list_t; + #define LCC_VALUE_LIST_INIT { NULL, NULL, 0, 0, 0, LCC_IDENTIFIER_INIT } + + struct lcc_connection_s; + typedef struct lcc_connection_s lcc_connection_t; + + /* + * Functions + */ + int lcc_connect (const char *address, lcc_connection_t **ret_con); + int lcc_disconnect (lcc_connection_t *c); + #define LCC_DESTROY(c) do { lcc_disconnect (c); (c) = NULL; } while (0) + + int lcc_getval (lcc_connection_t *c, lcc_identifier_t *ident, + size_t *ret_values_num, gauge_t **ret_values, char ***ret_values_names); + + int lcc_putval (lcc_connection_t *c, const lcc_value_list_t *vl); + + int lcc_flush (lcc_connection_t *c, const char *plugin, + lcc_identifier_t *ident, int timeout); + + int lcc_listval (lcc_connection_t *c, + lcc_identifier_t **ret_ident, size_t *ret_ident_num); + + /* TODO: putnotif */ + + const char *lcc_strerror (lcc_connection_t *c); + + int lcc_identifier_to_string (lcc_connection_t *c, + char *string, size_t string_size, const lcc_identifier_t *ident); + int lcc_string_to_identifier (lcc_connection_t *c, + lcc_identifier_t *ident, const char *string); + + /* Compares the identifiers "i0" and "i1" and returns less than zero or greater + * than zero if "i0" is smaller than or greater than "i1", respectively. If + * "i0" and "i1" are identical, zero is returned. */ + int lcc_identifier_compare (const lcc_identifier_t *i0, + const lcc_identifier_t *i1); ++int lcc_sort_identifiers (lcc_connection_t *c, ++ lcc_identifier_t *idents, size_t idents_num); + + LCC_END_DECLS + + /* vim: set sw=2 sts=2 et : */ + #endif /* LIBCOLLECTD_COLLECTDCLIENT_H */