X-Git-Url: https://git.octo.it/?p=collectd.git;a=blobdiff_plain;f=src%2Fcollectdctl.c;h=df83b50b3f97c9c6bd6749bfb31aebc043e6ff35;hp=8c884796403edfa9c6d69aec38421d6dbad359e7;hb=48efd3deb4c9139fd060ff3d289896e9031bcc7c;hpb=51181b899668ad2c232a152d6e5e787c4eb049cc diff --git a/src/collectdctl.c b/src/collectdctl.c index 8c884796..df83b50b 100644 --- a/src/collectdctl.c +++ b/src/collectdctl.c @@ -22,72 +22,89 @@ **/ #if HAVE_CONFIG_H -# include "config.h" +#include "config.h" #endif -#include -#include +#include #include +#include #include #include +#include #include #include #if NAN_STATIC_DEFAULT -# include +#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 */ +#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 +#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/collectd/client.h" +#include "collectd/client.h" #ifndef PREFIX -# define PREFIX "/opt/" PACKAGE_NAME +#define PREFIX "/opt/" PACKAGE_NAME #endif #ifndef LOCALSTATEDIR -# define LOCALSTATEDIR PREFIX "/var" +#define LOCALSTATEDIR PREFIX "/var" #endif -#define DEFAULT_SOCK LOCALSTATEDIR"/run/"PACKAGE_NAME"-unixsock" +#define DEFAULT_SOCK LOCALSTATEDIR "/run/" PACKAGE_NAME "-unixsock" extern char *optarg; -extern int optind; +extern int optind; + +/* ssnprintf returns zero on success, one if truncation occurred + and a negative integer onerror. */ +static int _ssnprintf(char *str, size_t sz, const char *format, ...) { + va_list ap; + va_start(ap, format); -__attribute__((noreturn)) -static void exit_usage (const char *name, int status) { - fprintf ((status == 0) ? stdout : stderr, + int ret = vsnprintf(str, sz, format, ap); + + va_end(ap); + + if (ret < 0) { + return ret; + } + return (size_t)ret >= sz; +} /* int _ssnprintf */ + +__attribute__((noreturn)) static void exit_usage(const char *name, int status) { + fprintf( + (status == 0) ? stdout : stderr, "Usage: %s [options] [cmd options]\n\n" "Available options:\n" " -s Path to collectd's UNIX socket.\n" - " Default: "DEFAULT_SOCK"\n" + " Default: " DEFAULT_SOCK "\n" "\n -h Display this help and exit.\n" @@ -104,19 +121,20 @@ static void exit_usage (const char *name, int status) { " [/][-]/[-]\n\n" - "Hostname defaults to the local hostname if omitted (e.g., uptime/uptime).\n" + "Hostname defaults to the local hostname if omitted (e.g., " + "uptime/uptime).\n" "No error is returned if the specified identifier does not exist.\n" - "\n"PACKAGE_NAME" "PACKAGE_VERSION", http://collectd.org/\n" + "\n" PACKAGE_NAME " " PACKAGE_VERSION ", http://collectd.org/\n" "by Florian octo Forster \n" - "for contributions see `AUTHORS'\n" - , name); - exit (status); + "for contributions see `AUTHORS'\n", + name); + exit(status); } /* Count the number of occurrences of the character 'chr' * in the specified string. */ -static int count_chars (const char *str, char chr) { +static int count_chars(const char *str, char chr) { int count = 0; while (*str != '\0') { @@ -129,110 +147,105 @@ static int count_chars (const char *str, char chr) { return count; } /* count_chars */ -static int array_grow (void **array, size_t *array_len, size_t elem_size) -{ +static int array_grow(void **array, size_t *array_len, size_t elem_size) { void *tmp; - assert ((array != NULL) && (array_len != NULL)); + assert((array != NULL) && (array_len != NULL)); - tmp = realloc (*array, (*array_len + 1) * elem_size); + tmp = realloc(*array, (*array_len + 1) * elem_size); if (tmp == NULL) { - fprintf (stderr, "ERROR: Failed to allocate memory.\n"); - return (-1); + fprintf(stderr, "ERROR: Failed to allocate memory.\n"); + return -1; } *array = tmp; ++(*array_len); - return (0); + return 0; } /* array_grow */ -static int parse_identifier (lcc_connection_t *c, - const char *value, lcc_identifier_t *ident) -{ +static int parse_identifier(lcc_connection_t *c, const char *value, + lcc_identifier_t *ident) { char hostname[1024]; char ident_str[1024] = ""; - int n_slashes; + int n_slashes; int status; - n_slashes = count_chars (value, '/'); + n_slashes = count_chars(value, '/'); if (n_slashes == 1) { /* The user has omitted the hostname part of the identifier * (there is only one '/' in the identifier) * Let's add the local hostname */ - if (gethostname (hostname, sizeof (hostname)) != 0) { - fprintf (stderr, "ERROR: Failed to get local hostname: %s", - strerror (errno)); - return (-1); + if (gethostname(hostname, sizeof(hostname)) != 0) { + fprintf(stderr, "ERROR: Failed to get local hostname: %s", + strerror(errno)); + return -1; } - hostname[sizeof (hostname) - 1] = '\0'; + hostname[sizeof(hostname) - 1] = '\0'; - snprintf (ident_str, sizeof (ident_str), "%s/%s", hostname, value); + _ssnprintf(ident_str, sizeof(ident_str), "%s/%s", hostname, value); + ident_str[sizeof(ident_str) - 1] = '\0'; + } else { + strncpy(ident_str, value, sizeof(ident_str)); ident_str[sizeof(ident_str) - 1] = '\0'; - } - else { - strncpy (ident_str, value, sizeof (ident_str)); - ident_str[sizeof (ident_str) - 1] = '\0'; } - status = lcc_string_to_identifier (c, ident, ident_str); + status = lcc_string_to_identifier(c, ident, ident_str); if (status != 0) { - fprintf (stderr, "ERROR: Failed to parse identifier ``%s'': %s.\n", - ident_str, lcc_strerror(c)); - return (-1); + fprintf(stderr, "ERROR: Failed to parse identifier ``%s'': %s.\n", + ident_str, lcc_strerror(c)); + return -1; } - return (0); + return 0; } /* parse_identifier */ -static int getval (lcc_connection_t *c, int argc, char **argv) -{ +static int getval(lcc_connection_t *c, int argc, char **argv) { lcc_identifier_t ident; - size_t ret_values_num = 0; - gauge_t *ret_values = NULL; - char **ret_values_names = NULL; + size_t ret_values_num = 0; + gauge_t *ret_values = NULL; + char **ret_values_names = NULL; int status; - assert (strcasecmp (argv[0], "getval") == 0); + assert(strcasecmp(argv[0], "getval") == 0); if (argc != 2) { - fprintf (stderr, "ERROR: getval: Missing identifier.\n"); - return (-1); + fprintf(stderr, "ERROR: getval: Missing identifier.\n"); + return -1; } - status = parse_identifier (c, argv[1], &ident); + status = parse_identifier(c, argv[1], &ident); if (status != 0) - return (status); - -#define BAIL_OUT(s) \ - do { \ - if (ret_values != NULL) \ - free (ret_values); \ - if (ret_values_names != NULL) { \ - for (size_t i = 0; i < ret_values_num; ++i) \ - free (ret_values_names[i]); \ - free (ret_values_names); \ - } \ - ret_values_num = 0; \ - return (s); \ + return status; + +#define BAIL_OUT(s) \ + do { \ + if (ret_values != NULL) \ + free(ret_values); \ + if (ret_values_names != NULL) { \ + for (size_t i = 0; i < ret_values_num; ++i) \ + free(ret_values_names[i]); \ + free(ret_values_names); \ + } \ + ret_values_num = 0; \ + return s; \ } while (0) - status = lcc_getval (c, &ident, - &ret_values_num, &ret_values, &ret_values_names); + status = + lcc_getval(c, &ident, &ret_values_num, &ret_values, &ret_values_names); if (status != 0) { - fprintf (stderr, "ERROR: %s\n", lcc_strerror (c)); - BAIL_OUT (-1); + fprintf(stderr, "ERROR: %s\n", lcc_strerror(c)); + BAIL_OUT(-1); } for (size_t i = 0; i < ret_values_num; ++i) - printf ("%s=%e\n", ret_values_names[i], ret_values[i]); - BAIL_OUT (0); + printf("%s=%e\n", ret_values_names[i], ret_values[i]); + BAIL_OUT(0); #undef BAIL_OUT } /* getval */ -static int flush (lcc_connection_t *c, int argc, char **argv) -{ +static int flush(lcc_connection_t *c, int argc, char **argv) { int timeout = -1; lcc_identifier_t *identifiers = NULL; @@ -243,242 +256,234 @@ static int flush (lcc_connection_t *c, int argc, char **argv) int status; - assert (strcasecmp (argv[0], "flush") == 0); - -#define BAIL_OUT(s) \ - do { \ - if (identifiers != NULL) \ - free (identifiers); \ - identifiers_num = 0; \ - if (plugins != NULL) \ - free (plugins); \ - plugins_num = 0; \ - return (s); \ + assert(strcasecmp(argv[0], "flush") == 0); + +#define BAIL_OUT(s) \ + do { \ + if (identifiers != NULL) \ + free(identifiers); \ + identifiers_num = 0; \ + if (plugins != NULL) \ + free(plugins); \ + plugins_num = 0; \ + return s; \ } while (0) for (int i = 1; i < argc; ++i) { char *key, *value; - key = argv[i]; - value = strchr (argv[i], (int)'='); + key = argv[i]; + value = strchr(argv[i], (int)'='); - if (! value) { - fprintf (stderr, "ERROR: flush: Invalid option ``%s''.\n", argv[i]); - BAIL_OUT (-1); + if (!value) { + fprintf(stderr, "ERROR: flush: Invalid option ``%s''.\n", argv[i]); + BAIL_OUT(-1); } *value = '\0'; ++value; - if (strcasecmp (key, "timeout") == 0) { + if (strcasecmp(key, "timeout") == 0) { char *endptr = NULL; - timeout = (int) strtol (value, &endptr, 0); + timeout = (int)strtol(value, &endptr, 0); if (endptr == value) { - fprintf (stderr, "ERROR: Failed to parse timeout as number: %s.\n", - value); - BAIL_OUT (-1); - } - else if ((endptr != NULL) && (*endptr != '\0')) { - fprintf (stderr, "WARNING: Ignoring trailing garbage after timeout: " - "%s.\n", endptr); + fprintf(stderr, "ERROR: Failed to parse timeout as number: %s.\n", + value); + BAIL_OUT(-1); + } else if ((endptr != NULL) && (*endptr != '\0')) { + fprintf(stderr, + "WARNING: Ignoring trailing garbage after timeout: " + "%s.\n", + endptr); } - } - else if (strcasecmp (key, "plugin") == 0) { - status = array_grow ((void *)&plugins, &plugins_num, - sizeof (*plugins)); + } else if (strcasecmp(key, "plugin") == 0) { + status = array_grow((void *)&plugins, &plugins_num, sizeof(*plugins)); if (status != 0) - BAIL_OUT (status); + BAIL_OUT(status); plugins[plugins_num - 1] = value; - } - else if (strcasecmp (key, "identifier") == 0) { - status = array_grow ((void *)&identifiers, &identifiers_num, - sizeof (*identifiers)); + } else if (strcasecmp(key, "identifier") == 0) { + status = array_grow((void *)&identifiers, &identifiers_num, + sizeof(*identifiers)); if (status != 0) - BAIL_OUT (status); + BAIL_OUT(status); - memset (identifiers + (identifiers_num - 1), 0, sizeof (*identifiers)); - status = parse_identifier (c, value, - identifiers + (identifiers_num - 1)); + memset(identifiers + (identifiers_num - 1), 0, sizeof(*identifiers)); + status = parse_identifier(c, value, identifiers + (identifiers_num - 1)); if (status != 0) - BAIL_OUT (status); - } - else { - fprintf (stderr, "ERROR: flush: Unknown option `%s'.\n", key); - BAIL_OUT (-1); + BAIL_OUT(status); + } else { + fprintf(stderr, "ERROR: flush: Unknown option `%s'.\n", key); + BAIL_OUT(-1); } } if (plugins_num == 0) { - status = array_grow ((void *)&plugins, &plugins_num, sizeof (*plugins)); + status = array_grow((void *)&plugins, &plugins_num, sizeof(*plugins)); if (status != 0) - BAIL_OUT (status); + BAIL_OUT(status); - assert (plugins_num == 1); + assert(plugins_num == 1); plugins[0] = NULL; } for (size_t i = 0; i < plugins_num; ++i) { if (identifiers_num == 0) { - status = lcc_flush (c, plugins[i], NULL, timeout); + status = lcc_flush(c, plugins[i], NULL, timeout); if (status != 0) - fprintf (stderr, "ERROR: Failed to flush plugin `%s': %s.\n", - (plugins[i] == NULL) ? "(all)" : plugins[i], lcc_strerror (c)); - } - else { + fprintf(stderr, "ERROR: Failed to flush plugin `%s': %s.\n", + (plugins[i] == NULL) ? "(all)" : plugins[i], lcc_strerror(c)); + } else { for (size_t j = 0; j < identifiers_num; ++j) { - status = lcc_flush (c, plugins[i], identifiers + j, timeout); + status = lcc_flush(c, plugins[i], identifiers + j, timeout); if (status != 0) { char id[1024]; - lcc_identifier_to_string (c, id, sizeof (id), identifiers + j); - fprintf (stderr, "ERROR: Failed to flush plugin `%s', " - "identifier `%s': %s.\n", - (plugins[i] == NULL) ? "(all)" : plugins[i], - id, lcc_strerror (c)); + lcc_identifier_to_string(c, id, sizeof(id), identifiers + j); + fprintf(stderr, + "ERROR: Failed to flush plugin `%s', " + "identifier `%s': %s.\n", + (plugins[i] == NULL) ? "(all)" : plugins[i], id, + lcc_strerror(c)); } } } } - BAIL_OUT (0); + BAIL_OUT(0); #undef BAIL_OUT } /* flush */ -static int listval (lcc_connection_t *c, int argc, char **argv) -{ - lcc_identifier_t *ret_ident = NULL; - size_t ret_ident_num = 0; +static int listval(lcc_connection_t *c, int argc, char **argv) { + lcc_identifier_t *ret_ident = NULL; + size_t ret_ident_num = 0; int status; - assert (strcasecmp (argv[0], "listval") == 0); + assert(strcasecmp(argv[0], "listval") == 0); if (argc != 1) { - fprintf (stderr, "ERROR: listval: Does not accept any arguments.\n"); - return (-1); + fprintf(stderr, "ERROR: listval: Does not accept any arguments.\n"); + return -1; } -#define BAIL_OUT(s) \ - do { \ - if (ret_ident != NULL) \ - free (ret_ident); \ - ret_ident_num = 0; \ - return (s); \ +#define BAIL_OUT(s) \ + do { \ + if (ret_ident != NULL) \ + free(ret_ident); \ + ret_ident_num = 0; \ + return s; \ } while (0) - status = lcc_listval (c, &ret_ident, &ret_ident_num); + status = lcc_listval(c, &ret_ident, &ret_ident_num); if (status != 0) { - fprintf (stderr, "ERROR: %s\n", lcc_strerror (c)); - BAIL_OUT (status); + fprintf(stderr, "ERROR: %s\n", lcc_strerror(c)); + BAIL_OUT(status); } for (size_t i = 0; i < ret_ident_num; ++i) { char id[1024]; - status = lcc_identifier_to_string (c, id, sizeof (id), ret_ident + i); + status = lcc_identifier_to_string(c, id, sizeof(id), ret_ident + i); if (status != 0) { - fprintf (stderr, "ERROR: listval: Failed to convert returned " - "identifier to a string: %s\n", lcc_strerror (c)); + fprintf(stderr, + "ERROR: listval: Failed to convert returned " + "identifier to a string: %s\n", + lcc_strerror(c)); continue; } - printf ("%s\n", id); + printf("%s\n", id); } - BAIL_OUT (0); + BAIL_OUT(0); #undef BAIL_OUT } /* listval */ -static int putval (lcc_connection_t *c, int argc, char **argv) -{ +static int putval(lcc_connection_t *c, int argc, char **argv) { lcc_value_list_t vl = LCC_VALUE_LIST_INIT; /* 64 ought to be enough for anybody ;-) */ value_t values[64]; - int values_types[64]; - size_t values_len = 0; + int values_types[64]; + size_t values_len = 0; int status; - assert (strcasecmp (argv[0], "putval") == 0); + assert(strcasecmp(argv[0], "putval") == 0); if (argc < 3) { - fprintf (stderr, "ERROR: putval: Missing identifier " - "and/or value list.\n"); - return (-1); + fprintf(stderr, "ERROR: putval: Missing identifier " + "and/or value list.\n"); + return -1; } - vl.values = values; + vl.values = values; vl.values_types = values_types; - status = parse_identifier (c, argv[1], &vl.identifier); + status = parse_identifier(c, argv[1], &vl.identifier); if (status != 0) - return (status); + return status; for (int i = 2; i < argc; ++i) { char *tmp; - tmp = strchr (argv[i], (int)'='); + tmp = strchr(argv[i], (int)'='); if (tmp != NULL) { /* option */ - char *key = argv[i]; + char *key = argv[i]; char *value = tmp; *value = '\0'; ++value; - if (strcasecmp (key, "interval") == 0) { + if (strcasecmp(key, "interval") == 0) { char *endptr; - vl.interval = strtol (value, &endptr, 0); + vl.interval = strtol(value, &endptr, 0); if (endptr == value) { - fprintf (stderr, "ERROR: Failed to parse interval as number: %s.\n", - value); - return (-1); + fprintf(stderr, "ERROR: Failed to parse interval as number: %s.\n", + value); + return -1; + } else if ((endptr != NULL) && (*endptr != '\0')) { + fprintf(stderr, + "WARNING: Ignoring trailing garbage after " + "interval: %s.\n", + endptr); } - else if ((endptr != NULL) && (*endptr != '\0')) { - fprintf (stderr, "WARNING: Ignoring trailing garbage after " - "interval: %s.\n", endptr); - } - } - else { - fprintf (stderr, "ERROR: putval: Unknown option `%s'.\n", key); - return (-1); + } else { + fprintf(stderr, "ERROR: putval: Unknown option `%s'.\n", key); + return -1; } - } - else { /* value list */ + } else { /* value list */ char *value; - tmp = strchr (argv[i], (int)':'); + tmp = strchr(argv[i], (int)':'); if (tmp == NULL) { - fprintf (stderr, "ERROR: putval: Invalid value list: %s.\n", - argv[i]); - return (-1); + fprintf(stderr, "ERROR: putval: Invalid value list: %s.\n", argv[i]); + return -1; } *tmp = '\0'; ++tmp; - if (strcasecmp (argv[i], "N") == 0) { + if (strcasecmp(argv[i], "N") == 0) { vl.time = 0; - } - else { + } else { char *endptr; - vl.time = strtol (argv[i], &endptr, 0); + vl.time = strtol(argv[i], &endptr, 0); if (endptr == argv[i]) { - fprintf (stderr, "ERROR: Failed to parse time as number: %s.\n", - argv[i]); - return (-1); - } - else if ((endptr != NULL) && (*endptr != '\0')) { - fprintf (stderr, "ERROR: Garbage after time: %s.\n", endptr); - return (-1); + fprintf(stderr, "ERROR: Failed to parse time as number: %s.\n", + argv[i]); + return -1; + } else if ((endptr != NULL) && (*endptr != '\0')) { + fprintf(stderr, "ERROR: Garbage after time: %s.\n", endptr); + return -1; } } @@ -487,7 +492,7 @@ static int putval (lcc_connection_t *c, int argc, char **argv) while (value != NULL) { char *dot, *endptr; - tmp = strchr (value, (int)':'); + tmp = strchr(value, (int)':'); if (tmp != NULL) { *tmp = '\0'; @@ -498,55 +503,52 @@ static int putval (lcc_connection_t *c, int argc, char **argv) * much sense imho -- the server might have different types defined * anyway. Also, lcc uses the type information for formatting the * number only, so the real meaning does not matter. -tokkee */ - dot = strchr (value, (int)'.'); + dot = strchr(value, (int)'.'); endptr = NULL; - if (strcasecmp (value, "U") == 0) { + if (strcasecmp(value, "U") == 0) { values[values_len].gauge = NAN; values_types[values_len] = LCC_TYPE_GAUGE; - } - else if (dot) { /* floating point value */ - values[values_len].gauge = strtod (value, &endptr); + } else if (dot) { /* floating point value */ + values[values_len].gauge = strtod(value, &endptr); values_types[values_len] = LCC_TYPE_GAUGE; - } - else { /* integer */ - values[values_len].counter = (counter_t) strtoull (value, &endptr, 0); + } else { /* integer */ + values[values_len].counter = (counter_t)strtoull(value, &endptr, 0); values_types[values_len] = LCC_TYPE_COUNTER; } ++values_len; if (endptr == value) { - fprintf (stderr, "ERROR: Failed to parse value as number: %s.\n", - argv[i]); - return (-1); - } - else if ((endptr != NULL) && (*endptr != '\0')) { - fprintf (stderr, "ERROR: Garbage after value: %s.\n", endptr); - return (-1); + fprintf(stderr, "ERROR: Failed to parse value as number: %s.\n", + argv[i]); + return -1; + } else if ((endptr != NULL) && (*endptr != '\0')) { + fprintf(stderr, "ERROR: Garbage after value: %s.\n", endptr); + return -1; } value = tmp; } - assert (values_len >= 1); + assert(values_len >= 1); vl.values_len = values_len; - status = lcc_putval (c, &vl); + status = lcc_putval(c, &vl); if (status != 0) { - fprintf (stderr, "ERROR: %s\n", lcc_strerror (c)); - return (-1); + fprintf(stderr, "ERROR: %s\n", lcc_strerror(c)); + return -1; } } } if (values_len == 0) { - fprintf (stderr, "ERROR: putval: Missing value list(s).\n"); - return (-1); + fprintf(stderr, "ERROR: putval: Missing value list(s).\n"); + return -1; } - return (0); + return 0; } /* putval */ -int main (int argc, char **argv) { - char address[1024] = "unix:"DEFAULT_SOCK; +int main(int argc, char **argv) { + char address[1024] = "unix:" DEFAULT_SOCK; lcc_connection_t *c; @@ -555,55 +557,52 @@ int main (int argc, char **argv) { while (42) { int opt; - opt = getopt (argc, argv, "s:h"); + opt = getopt(argc, argv, "s:h"); if (opt == -1) break; switch (opt) { - case 's': - snprintf (address, sizeof (address), "unix:%s", optarg); - address[sizeof (address) - 1] = '\0'; - break; - case 'h': - exit_usage (argv[0], 0); - default: - exit_usage (argv[0], 1); + case 's': + _ssnprintf(address, sizeof(address), "unix:%s", optarg); + address[sizeof(address) - 1] = '\0'; + break; + case 'h': + exit_usage(argv[0], 0); + default: + exit_usage(argv[0], 1); } } if (optind >= argc) { - fprintf (stderr, "%s: missing command\n", argv[0]); - exit_usage (argv[0], 1); + fprintf(stderr, "%s: missing command\n", argv[0]); + exit_usage(argv[0], 1); } c = NULL; - status = lcc_connect (address, &c); + status = lcc_connect(address, &c); if (status != 0) { - fprintf (stderr, "ERROR: Failed to connect to daemon at %s: %s.\n", - address, strerror (errno)); - return (1); + fprintf(stderr, "ERROR: Failed to connect to daemon at %s: %s.\n", address, + strerror(errno)); + return 1; } - if (strcasecmp (argv[optind], "getval") == 0) - status = getval (c, argc - optind, argv + optind); - else if (strcasecmp (argv[optind], "flush") == 0) - status = flush (c, argc - optind, argv + optind); - else if (strcasecmp (argv[optind], "listval") == 0) - status = listval (c, argc - optind, argv + optind); - else if (strcasecmp (argv[optind], "putval") == 0) - status = putval (c, argc - optind, argv + optind); + if (strcasecmp(argv[optind], "getval") == 0) + status = getval(c, argc - optind, argv + optind); + else if (strcasecmp(argv[optind], "flush") == 0) + status = flush(c, argc - optind, argv + optind); + else if (strcasecmp(argv[optind], "listval") == 0) + status = listval(c, argc - optind, argv + optind); + else if (strcasecmp(argv[optind], "putval") == 0) + status = putval(c, argc - optind, argv + optind); else { - fprintf (stderr, "%s: invalid command: %s\n", argv[0], argv[optind]); - return (1); + fprintf(stderr, "%s: invalid command: %s\n", argv[0], argv[optind]); + return 1; } - LCC_DESTROY (c); + LCC_DESTROY(c); if (status != 0) - return (status); - return (0); + return status; + return 0; } /* main */ - -/* vim: set sw=2 ts=2 tw=78 expandtab : */ -