Example #1
0
/* 
 * _forwarding_setup
 *
 * 'index' is the index of the message config and forwarding info.
 * 
 * Returns 0 success, -1 on error
 */
static int
_forwarding_setup(int index)
{
  hostlist_iterator_t itr = NULL;
  char *node;
  int rv = -1;

  assert(index >= 0 && index < conf.forward_message_config_len);

  /* We require a separate hostlist here b/c the hosts input by the
   * user and/or received by the remote hosts need to be mapped to a
   * single hostname.
   */
  if ((forwarding_info[index].fd = _forwarding_setup_socket(index)) < 0)
    goto cleanup;
  if (conf.forward_message_config[index].hosts)
    {
      forwarding_info[index].hosts = Hostlist_create(NULL);
      itr = Hostlist_iterator_create(conf.forward_message_config[index].hosts);
      while ((node = Hostlist_next(itr)))
        {
          char nodebuf[CEREBRO_MAX_NODENAME_LEN+1];
          char *nodeptr;

          if (found_clusterlist_module)
            {
              if (clusterlist_module_get_nodename(clusterlist_handle,
                                                  node,
                                                  nodebuf, 
                                                  CEREBRO_MAX_NODENAME_LEN+1) < 0)
                {
                  CEREBROD_DBG(("clusterlist_module_get_nodename: %s", nodebuf));
                  Hostlist_destroy(forwarding_info[index].hosts);
                  goto cleanup;
                }
              nodeptr = nodebuf;
            }
          else
            nodeptr = node;
              
          Hostlist_push(forwarding_info[index].hosts, nodeptr);
          
          free(node);
        }
    }
  else
    forwarding_info[index].hosts = NULL;
  Pthread_mutex_init(&(forwarding_info[index].lock), NULL);
  rv = 0;
 cleanup:
  if (itr)
    Hostlist_iterator_destroy(itr);
  return rv;
}
Example #2
0
/* 
 * _hostrange_data_destroy
 *
 * Free hostrange_data structures
 */
static void
_hostrange_data_destroy(void *data)
{
  struct hostrange_data *hd;

  assert(data);

  hd = (struct hostrange_data *)data;
  Hostlist_destroy(hd->hl);
  Free(hd->key);
  Free(hd);
}
Example #3
0
/* 
 * _cluster_nodes_output
 *
 * Output cluster nodes
 */
static void
_cluster_nodes_output(List l)
{
  struct node_metric_data *data = NULL;
  hostlist_t hl = NULL;
  ListIterator litr = NULL;

  assert(l);

  litr = List_iterator_create(l);

  if (output_type == CEREBRO_STAT_HOSTRANGE)
    hl = Hostlist_create(NULL);

  while ((data = list_next(litr)))
    {
      if (output_type == CEREBRO_STAT_NEWLINE)
        fprintf(stdout, "%s\n", data->nodename);
      if (output_type == CEREBRO_STAT_HOSTRANGE)
        Hostlist_push(hl, data->nodename);
    }

  if (output_type == CEREBRO_STAT_HOSTRANGE)
    {
      char hstr[CEREBRO_STAT_BUFLEN];

      Hostlist_sort(hl);
      Hostlist_uniq(hl);
      
      memset(hstr, '\0', CEREBRO_STAT_BUFLEN);
      Hostlist_ranged_string(hl, CEREBRO_STAT_BUFLEN, hstr);
      
      fprintf(stdout, "%s\n", hstr);
    }

  /* No need to destroy list iterator, caller will destroy List */
  if (hl)
    Hostlist_destroy(hl);
}