summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (from parent 1: 87e53c9)
raw | patch | inline | side by side (from parent 1: 87e53c9)
author | Florian Forster <octo@collectd.org> | |
Mon, 28 Nov 2016 21:23:24 +0000 (22:23 +0100) | ||
committer | Florian Forster <octo@collectd.org> | |
Mon, 28 Nov 2016 21:29:53 +0000 (22:29 +0100) |
src/utils_cmds.h | patch | blob | history | |
src/utils_format_graphite_test.c | patch | blob | history | |
src/utils_mount.c | patch | blob | history |
diff --git a/src/utils_cmds.h b/src/utils_cmds.h
index 205e89a0496df73a7b4cb80bc6ce511445113ff3..26d5338dec396b336e5ed9153392abe1b02581fc 100644 (file)
--- a/src/utils_cmds.h
+++ b/src/utils_cmds.h
#include <stdarg.h>
typedef enum {
- CMD_UNKNOWN = 0,
- CMD_FLUSH = 1,
- CMD_GETVAL = 2,
- CMD_LISTVAL = 3,
- CMD_PUTVAL = 4,
+ CMD_UNKNOWN = 0,
+ CMD_FLUSH = 1,
+ CMD_GETVAL = 2,
+ CMD_LISTVAL = 3,
+ CMD_PUTVAL = 4,
} cmd_type_t;
-#define CMD_TO_STRING(type) \
- ((type) == CMD_FLUSH) ? "FLUSH" \
- : ((type) == CMD_GETVAL) ? "GETVAL" \
- : ((type) == CMD_LISTVAL) ? "LISTVAL" \
- : ((type) == CMD_PUTVAL) ? "PUTVAL" \
- : "UNKNOWN"
+#define CMD_TO_STRING(type) \
+ ((type) == CMD_FLUSH) ? "FLUSH" : ((type) == CMD_GETVAL) \
+ ? "GETVAL" \
+ : ((type) == CMD_LISTVAL) \
+ ? "LISTVAL" \
+ : ((type) == CMD_PUTVAL) \
+ ? "PUTVAL" \
+ : "UNKNOWN"
typedef struct {
- double timeout;
+ double timeout;
- char **plugins;
- size_t plugins_num;
- identifier_t *identifiers;
- size_t identifiers_num;
+ char **plugins;
+ size_t plugins_num;
+ identifier_t *identifiers;
+ size_t identifiers_num;
} cmd_flush_t;
typedef struct {
- char *raw_identifier;
- identifier_t identifier;
+ char *raw_identifier;
+ identifier_t identifier;
} cmd_getval_t;
typedef struct {
} cmd_listval_t;
typedef struct {
- /* The raw identifier as provided by the user. */
- char *raw_identifier;
+ /* The raw identifier as provided by the user. */
+ char *raw_identifier;
- /* An array of the fully parsed identifier and all value lists, and their
- * options as provided by the user. */
- value_list_t *vl;
- size_t vl_num;
+ /* An array of the fully parsed identifier and all value lists, and their
+ * options as provided by the user. */
+ value_list_t *vl;
+ size_t vl_num;
} cmd_putval_t;
/*
* The representation of a fully parsed command.
*/
typedef struct {
- cmd_type_t type;
- union {
- cmd_flush_t flush;
- cmd_getval_t getval;
- cmd_listval_t listval;
- cmd_putval_t putval;
- } cmd;
+ cmd_type_t type;
+ union {
+ cmd_flush_t flush;
+ cmd_getval_t getval;
+ cmd_listval_t listval;
+ cmd_putval_t putval;
+ } cmd;
} cmd_t;
/*
* Optional settings for tuning the parser behavior.
*/
typedef struct {
- /* identifier_default_host: If non-NULL, the hostname is optional and will
- * default to the specified value. */
- char *identifier_default_host;
+ /* identifier_default_host: If non-NULL, the hostname is optional and will
+ * default to the specified value. */
+ char *identifier_default_host;
} cmd_options_t;
/*
* Status codes describing the parse result.
*/
typedef enum {
- CMD_OK = 0,
- CMD_ERROR = -1,
- CMD_PARSE_ERROR = -2,
- CMD_UNKNOWN_COMMAND = -3,
+ CMD_OK = 0,
+ CMD_ERROR = -1,
+ CMD_PARSE_ERROR = -2,
+ CMD_UNKNOWN_COMMAND = -3,
- /* Not necessarily fatal errors. */
- CMD_NO_OPTION = 1,
+ /* Not necessarily fatal errors. */
+ CMD_NO_OPTION = 1,
} cmd_status_t;
/*
* as the first argument.
*/
typedef struct {
- void (*cb) (void *, cmd_status_t, const char *, va_list);
- void *ud;
+ void (*cb)(void *, cmd_status_t, const char *, va_list);
+ void *ud;
} cmd_error_handler_t;
/*
* DESCRIPTION
* Reports an error via the specified error handler (if set).
*/
-void cmd_error (cmd_status_t status, cmd_error_handler_t *err,
- const char *format, ...);
+void cmd_error(cmd_status_t status, cmd_error_handler_t *err,
+ const char *format, ...);
/*
* NAME
* RETURN VALUE
* CMD_OK on success or the respective error code otherwise.
*/
-cmd_status_t cmd_parse (char *buffer, cmd_t *ret_cmd,
- const cmd_options_t *opts, cmd_error_handler_t *err);
+cmd_status_t cmd_parse(char *buffer, cmd_t *ret_cmd, const cmd_options_t *opts,
+ cmd_error_handler_t *err);
-cmd_status_t cmd_parsev (size_t argc, char **argv, cmd_t *ret_cmd,
- const cmd_options_t *opts, cmd_error_handler_t *err);
+cmd_status_t cmd_parsev(size_t argc, char **argv, cmd_t *ret_cmd,
+ const cmd_options_t *opts, cmd_error_handler_t *err);
-void cmd_destroy (cmd_t *cmd);
+void cmd_destroy(cmd_t *cmd);
/*
* NAME
* CMD_NO_OPTION if `field' does not represent an option at all (missing
* equal sign).
*/
-cmd_status_t cmd_parse_option (char *field,
- char **ret_key, char **ret_value, cmd_error_handler_t *err);
+cmd_status_t cmd_parse_option(char *field, char **ret_key, char **ret_value,
+ cmd_error_handler_t *err);
/*
* NAME
* `ap' Variable argument list providing the arguments for the format
* string.
*/
-void cmd_error_fh (void *ud, cmd_status_t status,
- const char *format, va_list ap);
+void cmd_error_fh(void *ud, cmd_status_t status, const char *format,
+ va_list ap);
#endif /* UTILS_CMDS_H */
index f349db1f12362a09440c11c431203159bf198f4c..415a283e0103127246a02461c4cbc7680edc12b2 100644 (file)
#include "collectd.h"
+#include "common.h" /* for STATIC_ARRAY_SIZE */
#include "testing.h"
#include "utils_format_graphite.h"
-#include "common.h" /* for STATIC_ARRAY_SIZE */
static data_set_t ds_single = {
.type = "single",
};
*/
-DEF_TEST(metric_name)
-{
+DEF_TEST(metric_name) {
struct {
char *plugin_instance;
char *type_instance;
unsigned int flags;
char *want_name;
} cases[] = {
- {
- .want_name = "example@com.test.single",
- },
- /* plugin and type instances */
- {
- .plugin_instance = "foo",
- .type_instance = "bar",
- .want_name = "example@com.test-foo.single-bar",
- },
- {
- .plugin_instance = NULL,
- .type_instance = "bar",
- .want_name = "example@com.test.single-bar",
- },
- {
- .plugin_instance = "foo",
- .type_instance = NULL,
- .want_name = "example@com.test-foo.single",
- },
- /* special chars */
- {
- .plugin_instance = "foo (test)",
- .type_instance = "test: \"hello\"",
- .want_name = "example@com.test-foo@@test@.single-test@@@hello@",
- },
- /* flag GRAPHITE_SEPARATE_INSTANCES */
- {
- .plugin_instance = "foo",
- .type_instance = "bar",
- .flags = GRAPHITE_SEPARATE_INSTANCES,
- .want_name = "example@com.test.foo.single.bar",
- },
- /* flag GRAPHITE_ALWAYS_APPEND_DS */
- {
- .plugin_instance = "foo",
- .type_instance = "bar",
- .flags = GRAPHITE_ALWAYS_APPEND_DS,
- .want_name = "example@com.test-foo.single-bar.value",
- },
- /* flag GRAPHITE_PRESERVE_SEPARATOR */
- {
- .plugin_instance = "f.o.o",
- .type_instance = "b.a.r",
- .flags = 0,
- .want_name = "example@com.test-f@o@o.single-b@a@r",
- },
- {
- .plugin_instance = "f.o.o",
- .type_instance = "b.a.r",
- .flags = GRAPHITE_PRESERVE_SEPARATOR,
- .want_name = "example.com.test-f.o.o.single-b.a.r",
- },
- /* prefix and suffix */
- {
- .prefix = "foo.",
- .suffix = ".bar",
- .want_name = "foo.example@com.bar.test.single",
- },
- {
- .prefix = NULL,
- .suffix = ".bar",
- .want_name = "example@com.bar.test.single",
- },
- {
- .prefix = "foo.",
- .suffix = NULL,
- .want_name = "foo.example@com.test.single",
- },
+ {
+ .want_name = "example@com.test.single",
+ },
+ /* plugin and type instances */
+ {
+ .plugin_instance = "foo",
+ .type_instance = "bar",
+ .want_name = "example@com.test-foo.single-bar",
+ },
+ {
+ .plugin_instance = NULL,
+ .type_instance = "bar",
+ .want_name = "example@com.test.single-bar",
+ },
+ {
+ .plugin_instance = "foo",
+ .type_instance = NULL,
+ .want_name = "example@com.test-foo.single",
+ },
+ /* special chars */
+ {
+ .plugin_instance = "foo (test)",
+ .type_instance = "test: \"hello\"",
+ .want_name = "example@com.test-foo@@test@.single-test@@@hello@",
+ },
+ /* flag GRAPHITE_SEPARATE_INSTANCES */
+ {
+ .plugin_instance = "foo",
+ .type_instance = "bar",
+ .flags = GRAPHITE_SEPARATE_INSTANCES,
+ .want_name = "example@com.test.foo.single.bar",
+ },
+ /* flag GRAPHITE_ALWAYS_APPEND_DS */
+ {
+ .plugin_instance = "foo",
+ .type_instance = "bar",
+ .flags = GRAPHITE_ALWAYS_APPEND_DS,
+ .want_name = "example@com.test-foo.single-bar.value",
+ },
+ /* flag GRAPHITE_PRESERVE_SEPARATOR */
+ {
+ .plugin_instance = "f.o.o",
+ .type_instance = "b.a.r",
+ .flags = 0,
+ .want_name = "example@com.test-f@o@o.single-b@a@r",
+ },
+ {
+ .plugin_instance = "f.o.o",
+ .type_instance = "b.a.r",
+ .flags = GRAPHITE_PRESERVE_SEPARATOR,
+ .want_name = "example.com.test-f.o.o.single-b.a.r",
+ },
+ /* prefix and suffix */
+ {
+ .prefix = "foo.",
+ .suffix = ".bar",
+ .want_name = "foo.example@com.bar.test.single",
+ },
+ {
+ .prefix = NULL,
+ .suffix = ".bar",
+ .want_name = "example@com.bar.test.single",
+ },
+ {
+ .prefix = "foo.",
+ .suffix = NULL,
+ .want_name = "foo.example@com.test.single",
+ },
};
for (size_t i = 0; i < STATIC_ARRAY_SIZE(cases); i++) {
value_list_t vl = {
- .values = &(value_t){.gauge = 42},
- .values_len = 1,
- .time = TIME_T_TO_CDTIME_T_STATIC(1480063672),
- .interval = TIME_T_TO_CDTIME_T_STATIC(10),
- .host = "example.com",
- .plugin = "test",
- .type = "single",
+ .values = &(value_t){.gauge = 42},
+ .values_len = 1,
+ .time = TIME_T_TO_CDTIME_T_STATIC(1480063672),
+ .interval = TIME_T_TO_CDTIME_T_STATIC(10),
+ .host = "example.com",
+ .plugin = "test",
+ .type = "single",
};
char want[1024];
snprintf(want, sizeof(want), "%s 42 1480063672\r\n", cases[i].want_name);
if (cases[i].plugin_instance != NULL)
- sstrncpy (vl.plugin_instance, cases[i].plugin_instance, sizeof (vl.plugin_instance));
+ sstrncpy(vl.plugin_instance, cases[i].plugin_instance,
+ sizeof(vl.plugin_instance));
if (cases[i].type_instance != NULL)
- sstrncpy (vl.type_instance, cases[i].type_instance, sizeof (vl.type_instance));
+ sstrncpy(vl.type_instance, cases[i].type_instance,
+ sizeof(vl.type_instance));
char got[1024];
- EXPECT_EQ_INT(0, format_graphite(got, sizeof(got), &ds_single, &vl, cases[i].prefix, cases[i].suffix, '@', cases[i].flags));
+ EXPECT_EQ_INT(0, format_graphite(got, sizeof(got), &ds_single, &vl,
+ cases[i].prefix, cases[i].suffix, '@',
+ cases[i].flags));
EXPECT_EQ_STR(want, got);
}
return 0;
}
-int main (void)
-{
+int main(void) {
RUN_TEST(metric_name);
END_TEST;
diff --git a/src/utils_mount.c b/src/utils_mount.c
index 660e0852d4b7eeaeab55b665d74484f1a4adf28d..87f26df04f44b8319f5470e1f15ce9e5cd11f9ab 100644 (file)
--- a/src/utils_mount.c
+++ b/src/utils_mount.c
return (first);
} /* static cu_mount_t *cu_mount_gen_getmntent (void) */
- /* #endif HAVE_TWO_GETMNTENT || HAVE_GEN_GETMNTENT || HAVE_SUN_GETMNTENT */
+/* #endif HAVE_TWO_GETMNTENT || HAVE_GEN_GETMNTENT || HAVE_SUN_GETMNTENT */
#elif HAVE_SEQ_GETMNTENT
#warn "This version of `getmntent' hat not yet been implemented!"