/* * === FUNCTION ====================================================================== * Name: parse_args * Description: * ===================================================================================== */ int parse_args(int argc, char **argv) { char *p_arg, *p_value; /* holds argument name and value pointers for tokenization */ unsigned int index; index = get_index_from_name("config"); /* test for a configuration file passed */ for(int i = 0; i < (argc - 1); ++i) { if(match(get_shortname(argv[i]), options[index].shortname)) { parse_config(argv[i + 1]); } else if(match(get_longname(argv[i]), options[index].longname)) { parse_config( } }
/* read the next line of the bootmodule, and return info about what to spawn in *si return: 1: line read succesfully 0: end of file reached -1: error */ static int prepare_spawn(size_t *bmpos, struct spawn_info *si) { assert(bmpos != NULL); assert(si != NULL); const char *bootmodules = gbootmodules; // find the start/end of the next line const char *start = &bootmodules[*bmpos]; const char *end = strchr(start, '\n'); if (end == NULL) { return 0; } else { *bmpos = end - bootmodules + 1; } // ignore arguments for name comparison const char *args = memchr(start, ' ', end - start); // where's the end of the full name? const char *nameend = args == NULL ? end : args; si->shortname = (char *)get_shortname(start, nameend, &si->shortnamelen); si->cmdargs = malloc(end - si->shortname + 1); if (si->cmdargs == NULL) { return -1; } si->name = malloc(nameend - start + 1); if (si->name == NULL) { free(si->cmdargs); return -1; } /* Get the command line arguments of the domain: args plus shortname */ memcpy(si->cmdargs, si->shortname, end - si->shortname); si->cmdargs[end - si->shortname] = '\0'; si->argc = spawn_tokenize_cmdargs(si->cmdargs, si->argv, ARRAY_LENGTH(si->argv)); if (si->argc >= MAX_CMDLINE_ARGS) { free(si->cmdargs); free(si->name); return -1; } /* grab a copy of the full name as a separate string */ memcpy(si->name, start, nameend - start); si->name[nameend - start] = '\0'; return 1; }
static int locate_hostfile (char *hostfile) { struct stat f; if (stat(hostfile, &f) == 0) { return 0; } if (config.short_name) { char *host = get_shortname(config.host); int hostfile_len = strlen(config.cachepath) + strlen(host) + 2; hostfile = realloc(hostfile, hostfile_len); snprintf(hostfile, hostfile_len, "%s/%s", config.cachepath, host); free(host); if (stat(hostfile, &f) == 0) { return 0; } } return -1; /* ultimately not found */ }
static int parse_xml_tree_to_cache(xmlNode *root, const char *cachepath, const char *cachefile) { xmlNode *node, *node2, *node3, *node4 = NULL; char *name, *units, *value, *grid, *cluster, *host; FILE *f; char filenamebuf[PATH_MAX]; int count; for (node = root->children; node; node = node->next) { if (!is_element(node, "GRID")) continue; /* skip non-element and non-cluster nodes */ grid = get_prop(node, "NAME"); debug("Found new grid: %s\n", grid); for (node2 = node->children; node2; node2 = node2->next) { if (!is_element(node2, "CLUSTER")) continue; /* skip non-element and non-cluster nodes */ cluster = get_prop(node2, "NAME"); debug("\tFound new cluster: %s\n", cluster); for (node3 = node2->children; node3; node3 = node3->next) { if (!is_element(node3, "HOST")) continue; /* skip non-element and non-host nodes */ host = get_prop(node3, "NAME"); if (config.short_name) { host = get_shortname(host); } debug("\t\tFound new host: %s\n", host); snprintf(filenamebuf, PATH_MAX, "%s/%s/%s/%s", cachepath, grid, cluster, host); if (config.short_name) { free(host); } if (create_abs_path(filenamebuf) < 0) return -1; count = 0; f = fopen(filenamebuf, "w"); if (f == NULL) return -1; value = get_prop(node3, "REPORTED"); fprintf(f, "#REPORTED, ,%s\n", value); for (node4 = node3->children; node4; node4 = node4->next) { if (!is_element(node4, "METRIC")) continue; /* skip non-element and non-metric nodes */ name = get_prop(node4, "NAME"); units = get_prop(node4, "UNITS"); value = get_prop(node4, "VAL"); debug("\t\t\tFound new metric: %s\n", name); fprintf(f, "%s,%s,%s\n", name, units, value); count++; } fclose(f); debug("\t\t\tWrote %d metrics to %s\n", count, filenamebuf); } } } return 0; }