From: daryder Date: Fri, 4 Apr 2014 14:03:59 +0000 (-0400) Subject: Updated configuration layout X-Git-Tag: collectd-5.5.0~80^2~22 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=c9a85794d4cfa5792504d85f490f8f5d41eefced;p=collectd.git Updated configuration layout --- diff --git a/src/ceph.c b/src/ceph.c index e1653bf7..76c220e5 100644 --- a/src/ceph.c +++ b/src/ceph.c @@ -392,24 +392,82 @@ static int cc_handle_str(struct oconfig_item_s *item, char *dest, int dest_len) return 0; } +static int cc_add_daemon_config(oconfig_item_t *ci) +{ + int ret, i; + struct ceph_daemon *array, *nd, cd; + memset(&cd, 0, sizeof(struct ceph_daemon)); + + if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) + { + WARNING("ceph plugin: `Daemon' blocks need exactly one string argument."); + return (-1); + } + + ret = cc_handle_str(ci, cd.name, DATA_MAX_NAME_LEN); + if (ret) + return ret; + + for (i=0; i < ci->children_num; i++) + { + oconfig_item_t *child = ci->children + i; + + if (strcasecmp("SocketPath", child->key) == 0) + { + ret = cc_handle_str(child, cd.asok_path, sizeof(cd.asok_path)); + if (ret) + return ret; + } + else + { + WARNING("ceph plugin: ignoring unknown option %s", child->key); + } + } + if (cd.name[0] == '\0') + { + ERROR("ceph plugin: you must configure a daemon name.\n"); + return -EINVAL; + } + else if (cd.asok_path[0] == '\0') + { + ERROR("ceph plugin(name=%s): you must configure an administrative " + "socket path.\n", cd.name); + return -EINVAL; + } + else if (!((cd.asok_path[0] == '/') + || (cd.asok_path[0] == '.' && cd.asok_path[1] == '/'))) + { + ERROR("ceph plugin(name=%s): administrative socket paths must begin with " + "'/' or './' Can't parse: '%s'\n", cd.name, cd.asok_path); + return -EINVAL; + } + array = realloc(g_daemons, + sizeof(struct ceph_daemon *) * (g_num_daemons + 1)); + if (array == NULL) + { + /* The positive return value here indicates that this is a + * runtime error, not a configuration error. */ + return ENOMEM; + } + g_daemons = (struct ceph_daemon**) array; + nd = malloc(sizeof(struct ceph_daemon)); + if (!nd) + return ENOMEM; + memcpy(nd, &cd, sizeof(struct ceph_daemon)); + g_daemons[g_num_daemons++] = nd; + return 0; +} + static int ceph_config(oconfig_item_t *ci) { int ret, i; - struct ceph_daemon *array, *nd, cd; - memset(&cd, 0, sizeof(struct ceph_daemon)); for (i = 0; i < ci->children_num; ++i) { oconfig_item_t *child = ci->children + i; - if (strcasecmp("Name", child->key) == 0) + if (strcasecmp("Daemon", child->key) == 0) { - ret = cc_handle_str(child, cd.name, DATA_MAX_NAME_LEN); - if (ret) - return ret; - } - else if (strcasecmp("SocketPath", child->key) == 0) - { - ret = cc_handle_str(child, cd.asok_path, sizeof(cd.asok_path)); + ret = cc_add_daemon_config(child); if (ret) return ret; } @@ -418,38 +476,6 @@ static int ceph_config(oconfig_item_t *ci) WARNING("ceph plugin: ignoring unknown option %s", child->key); } } - if (cd.name[0] == '\0') - { - ERROR("ceph plugin: you must configure a daemon name.\n"); - return -EINVAL; - } - else if (cd.asok_path[0] == '\0') - { - ERROR("ceph plugin(name=%s): you must configure an administrative " - "socket path.\n", cd.name); - return -EINVAL; - } - else if (!((cd.asok_path[0] == '/') - || (cd.asok_path[0] == '.' && cd.asok_path[1] == '/'))) - { - ERROR("ceph plugin(name=%s): administrative socket paths must begin with " - "'/' or './' Can't parse: '%s'\n", cd.name, cd.asok_path); - return -EINVAL; - } - array = realloc(g_daemons, - sizeof(struct ceph_daemon *) * (g_num_daemons + 1)); - if (array == NULL) - { - /* The positive return value here indicates that this is a - * runtime error, not a configuration error. */ - return ENOMEM; - } - g_daemons = (struct ceph_daemon**) array; - nd = malloc(sizeof(struct ceph_daemon)); - if (!nd) - return ENOMEM; - memcpy(nd, &cd, sizeof(struct ceph_daemon)); - g_daemons[g_num_daemons++] = nd; return 0; }