static void _eliminate_nodes (void) { if (cmd_args.common_args.eliminate) { ipmidetect_t id = NULL; int i; if (!(id = ipmidetect_handle_create ())) { IPMIPOWER_ERROR (("ipmidetect_handle_create: %s", strerror (errno))); exit (EXIT_FAILURE); } if (ipmidetect_load_data (id, NULL, 0, 0) < 0) { if (ipmidetect_errnum (id) == IPMIDETECT_ERR_CONNECT || ipmidetect_errnum (id) == IPMIDETECT_ERR_CONNECT_TIMEOUT) IPMIPOWER_ERROR (("Error connecting to ipmidetect daemon")); else IPMIPOWER_ERROR (("ipmidetect_load_data: %s", ipmidetect_errormsg (id))); exit (EXIT_FAILURE); } for (i = 0; i < ics_len; i++) { int ret; if ((ret = ipmidetect_is_node_detected (id, ics[i].hostname)) < 0) { if (ipmidetect_errnum (id) == IPMIDETECT_ERR_NOTFOUND) IPMIPOWER_ERROR (("Node '%s' unrecognized by ipmidetect", ics[i].hostname)); else IPMIPOWER_ERROR (("ipmidetect_is_node_detected: %s", ipmidetect_errormsg (id))); exit (EXIT_FAILURE); } if (!ret) ics[i].skip++; } ipmidetect_handle_destroy (id); } }
static int eliminate_nodes (char **hosts) { hostlist_t hl = NULL; hostlist_t hlnew = NULL; hostlist_iterator_t hitr = NULL; ipmidetect_t id = NULL; char *host = NULL; char hostbuf[HOSTLIST_BUFLEN + 1]; int rv = -1; assert (hosts); assert (*hosts); if (!(id = ipmidetect_handle_create ())) { fprintf (stderr, "ipmidetect_handle_create\n"); goto cleanup; } if (ipmidetect_load_data (id, NULL, 0, 0) < 0) { if (ipmidetect_errnum (id) == IPMIDETECT_ERR_CONNECT || ipmidetect_errnum (id) == IPMIDETECT_ERR_CONNECT_TIMEOUT) fprintf (stderr, "Error connecting to ipmidetect daemon\n"); else fprintf (stderr, "ipmidetect_load_data: %s\n", ipmidetect_errormsg (id)); goto cleanup; } if (!(hl = hostlist_create (*hosts))) { fprintf (stderr, "hostlist_create: %s\n", strerror (errno)); goto cleanup; } if (!(hlnew = hostlist_create (*hosts))) { fprintf (stderr, "hostlist_create: %s\n", strerror (errno)); goto cleanup; } if (!(hitr = hostlist_iterator_create (hl))) { fprintf (stderr, "hostlist_iterator_create: %s\n", strerror (errno)); goto cleanup; } while ((host = hostlist_next (hitr))) { int ret; if ((ret = ipmidetect_is_node_detected (id, host)) < 0) { if (ipmidetect_errnum (id) == IPMIDETECT_ERR_NOTFOUND) fprintf (stderr, "Node '%s' unrecognized by ipmidetect\n", host); else fprintf (stderr, "ipmidetect_is_node_detected: %s\n", ipmidetect_errormsg (id)); goto cleanup; } if (!ret) hostlist_delete (hlnew, host); free (host); } host = NULL; if (!hostlist_count (hlnew)) { rv = 0; goto cleanup; } memset (hostbuf, '\0', HOSTLIST_BUFLEN + 1); if (hostlist_ranged_string (hlnew, HOSTLIST_BUFLEN, hostbuf) < 0) { fprintf (stderr, "hostlist_ranged_string: truncation\n"); goto cleanup; } free (*hosts); if (!(*hosts = strdup (hostbuf))) { fprintf (stderr, "strdup: %s\n", strerror (errno)); goto cleanup; } rv = hostlist_count (hlnew); cleanup: if (id) ipmidetect_handle_destroy (id); if (hitr) hostlist_iterator_destroy (hitr); if (hl) hostlist_destroy (hl); if (hlnew) hostlist_destroy (hlnew); free (host); return (rv); }