コード例 #1
0
ファイル: log.c プロジェクト: PerilousApricot/ibp_server
void mlog_load(char *fname)
{
  char *group_index, *group_level;
  char *name, *value, *logname;
  int n, default_level;
  inip_file_t *fd;
  inip_group_t *g;
  inip_element_t *ele;


  if (_log_lock == NULL) _log_init();

  group_index = "log_index";
  group_level = "log_level";

  //** Open the file
  fd = inip_read(fname);
  if (fd == NULL) {
     log_printf(0, "Error loading module definitions!  fname=%s\n", fname);
     return;
  }

  default_level = inip_get_integer(fd, group_level, "default", 0);
//printf("mlog_load: inital ll=%d\n", _log_level);
  _log_level = inip_get_integer(fd, group_level, "start_level", _log_level);
//printf("mlog_load: new ll=%d\n", _log_level);
  for (n=0; n<_mlog_size; n++) _mlog_table[n] = default_level;
  logname = inip_get_string(fd, group_level, "output", "stdout");
  open_log(logname);
  _log_maxsize = inip_get_integer(fd, group_level, "size", 100*1024*1024);

  //** Load the mappings
  g = inip_find_group(fd, group_index);
  if (g == NULL) {
     log_printf(1, "Missing %s group!\n", group_index);
     inip_destroy(fd);
     return;
  }

  ele = inip_first_element(g);
  while (ele != NULL) {
     name = inip_get_element_key(ele);
     value = inip_get_element_value(ele);

     n = (value != NULL) ? atoi(value) : -1;

     if ((n>=0) && (n<_mlog_size)) {
        _mlog_file_table[n] = strdup(name);
        _mlog_table[n] = inip_get_integer(fd, group_level, name, _mlog_table[n]);
//printf("mlog_load: mi=%d key=%s val=%d\n", n, name, _mlog_table[n]);
     } else {
       log_printf(0, "Invalid index: %s=%d  should be between 0..%d!  Skipping option\n", name, n, _mlog_size);
     }

     //** Move to the next segmnet to load
     ele = inip_next_element(ele);
  }

  inip_destroy(fd);
}
コード例 #2
0
ファイル: rs_space.c プロジェクト: accre/lstore-lio
rs_space_t rs_space(char *config)
{
    inip_file_t *fd;
    inip_group_t *grp;
    inip_element_t *ele;
    char *key, *value;
    int64_t nfree, nused, ntotal;
    int status;
    rs_space_t space;

    memset(&space, 0, sizeof(space));

    if (config == NULL) return(space);

    fd = inip_read_text(config); assert(fd);

    grp = inip_first_group(fd);
    while (grp != NULL) {
        key = inip_get_group(grp);
        if (strcmp("rid", key) == 0) {  //** Found a resource
            space.n_rids_total++;

            ele = inip_first_element(grp);
            status = nfree = nused = ntotal = 0;
            while (ele != NULL) {
                key = inip_get_element_key(ele);
                value = inip_get_element_value(ele);
                if (strcmp(key, "space_free") == 0) {  //** Space free
                    nfree = string_get_integer(value);
                    if (nfree > 0) space.n_rids_free++;
                } else if (strcmp(key, "space_used") == 0) {  //** Space used
                    nused = string_get_integer(value);
                } else if (strcmp(key, "space_total") == 0) {  //** total space
                    ntotal = string_get_integer(value);
                } else if (strcmp(key, "status") == 0) {  //** Status
                    status = string_get_integer(value);
                    if ((status >= 0) && (status<=2)) {
                        space.n_rids_status[status]++;
                    }
                }

                ele = inip_next_element(ele);
            }

            //** Always add it to the totals
            space.used_total += nused;
            space.free_total += nfree;
            space.total_total += ntotal;

            //** If up add it to the available space
            if (status == RS_STATUS_UP) {
                space.used_up += nused;
                space.free_up += nfree;
                space.total_up += ntotal;
            }
        }

        grp = inip_next_group(grp);
    }

    inip_destroy(fd);

    return(space);
}