Ejemplo n.º 1
0
int rotate_log(struct rotator *rr,char *filename) {
  char *dir,*base,*oldname,*newname;
  DIR *dirh;
  struct dirent des,*de;
  struct array *names;
  struct assoc *changes,*orders;
  int order,i,n;

  dirbasename(filename,&dir,&base);
  log_debug(("Rotating in '%s'",dir));
  dirh = opendir(dir);
  if(!dirh) {
    log_error(("Could not rotate log file"));
    return 1;
  }
  names = array_create(type_free,0);
  changes = assoc_create(0,0,type_free,0);
  orders = assoc_create(0,0,type_free,0);
  while(1) {
    if(readdir_r(dirh,&des,&de)) {
      log_error(("Problem reading directory during log rotation"));
      break;
    }
    if(!de) { break; }
    order = matching_file(rr,filename,de->d_name,&newname);
    if(order == MATCH_IGNORE) { continue; }
    if(order == MATCH_DELETE) {
      log_debug(("delete %s",de->d_name));
      unlink(de->d_name);
    } else {
      oldname = strdup(de->d_name);
      array_insert(names,oldname);
      assoc_set(changes,oldname,newname);
      assoc_set(orders,oldname,make_int(order));
    }
  }
  if(closedir(dirh)) {
    log_error(("Could not closedir during log rotation!"));
    /* But continue: what else to do? */
  }
  array_sort(names,sort_names,orders);
  n = array_length(names);
  for(i=0;i<n;i++) {
    oldname = array_index(names,i);
    newname = assoc_lookup(changes,oldname);
    log_warn(("name=%s -> %s",oldname,newname));
    rename_file(rr,dir,oldname,newname);
  }
  assoc_release(changes);
  assoc_release(orders);
  array_release(names);
  free(dir);
  free(base);
  return 0;
}
Ejemplo n.º 2
0
/* copy ctx->sum->pool[i] to stp */
rstatus_t
stats_pool_copy(struct context *ctx, struct stats_pool *stp, struct hash_table **sit)
{
    rstatus_t status;
    uint32_t i, j, k;
    uint64_t idx_data;
    struct stats *st =  ctx->stats;
    struct array *sum = &st->sum;

    struct stats_pool *istp;
    struct stats_metric *stm_src, *stm_dst;
    struct stats_server *sts_src, *sts_dst;
    for (i = 0;i < array_n(sum); i++) {
        /* get pool from array sum */
        istp = array_get(sum, i);
        /* find the pool */
        if (string_compare(&stp->name, &istp->name) == 0) {
            /* copy the metric array */
            for (j = 0;j < array_n(&istp->metric);j++) {
                stm_src = array_get(&istp->metric, j);
                stm_dst = array_push(&stp->metric);

                stats_metric_copy(stm_dst, stm_src);
            }
            /* copy the server array */
            for (j = 0;j < array_n(&istp->server);j++) {
                sts_src = array_get(&istp->server, j);

                /* add server idx to hashtable */
                idx_data = j + 1;
                status = assoc_set(*sit, (char *)sts_src->name.data,
                                   strlen((char *)sts_src->name.data),
                                   (void *)idx_data); // TODO trick here. avoid assert
                if (status != NC_OK) {
                    return status;
                }

                sts_dst = array_push(&stp->server);

                /*init dst server metric */
                status = array_init(&sts_dst->metric, STATS_SERVER_NFIELD,
                                    sizeof(struct stats_metric));
                if (status != NC_OK) {
                    return status;
                }
                string_init(&sts_dst->name);
                string_duplicate(&sts_dst->name, &sts_src->name);

                /* copy the metric array in one server */
                log_debug(LOG_VVVERB, "array_n server->metric is %d", array_n(&sts_src->metric));
                for (k = 0;k < array_n(&sts_src->metric); k++) {
                    log_debug(LOG_VVVERB,"server->metric %d", k);
                    stm_src = array_get(&sts_src->metric, k);
                    stm_dst = array_push(&sts_dst->metric);

                    stats_metric_copy(stm_dst, stm_src);
                }
            }
        }
    }
    return NC_OK;
}
Ejemplo n.º 3
0
void run_ic_register(struct running *rr,char *type,ic_create_fn fn) {
  assoc_set(rr->ic_shop,type,fn);
}
Ejemplo n.º 4
0
rstatus_t
ffi_server_table_set(struct server_pool *pool, const char *name, struct server *server)
{
    return assoc_set(pool->server_table, name, strlen(name), server);
}