Exemplo n.º 1
0
static int noit_fq_driver_init(noit_module_generic_t *self) {
  if(!nlerr) nlerr = noit_log_stream_find("error/fq_driver");
  if(!nlerr) nlerr = noit_error;
  stratcon_iep_mq_driver_register("fq", &mq_driver_fq);
  register_console_fq_commands();
  eventer_add_in_s_us(fq_status_checker, NULL, 0, 0);
  return 0;
}
Exemplo n.º 2
0
static int
fq_status_checker(eventer_t e, int mask, void *closure, struct timeval *now) {
  int i;
  for(i=0; i<global_fq_ctx.nhosts; i++) {
    fq_client_status(global_fq_ctx.client[i], process_fq_status,
                     (void *)&global_fq_ctx.stats[i]);
  }
  eventer_add_in_s_us(fq_status_checker, NULL, 5, 0);
}
Exemplo n.º 3
0
static int noit_fq_driver_init(mtev_dso_generic_t *self) {
  if(!nlerr) nlerr = mtev_log_stream_find("error/fq_driver");
  if(!nlerr) nlerr = mtev_error;
  mtev_hash_init(&filtered_checks_hash);
  stratcon_iep_mq_driver_register("fq", &mq_driver_fq);
  register_console_fq_commands();
  eventer_add_in_s_us(fq_status_checker, NULL, 0, 0);
  return 0;
}
Exemplo n.º 4
0
int
noit_check_etc_hosts_cache_refresh(eventer_t e, int mask, void *closure,
                                   struct timeval *now) {
  static struct stat last_stat;
  struct stat sb;
  struct hostent *ent;
  int reload = 0;

  memset(&sb, 0, sizeof(sb));
  stat("/etc/hosts", &sb);
#define CSTAT(f) (sb.f == last_stat.f)
  reload = ! (CSTAT(st_dev) && CSTAT(st_ino) && CSTAT(st_mode) && CSTAT(st_uid) &&
              CSTAT(st_gid) && CSTAT(st_size) && CSTAT(st_mtime));
  memcpy(&last_stat, &sb, sizeof(sb));

  if(reload) {
    mtev_hash_delete_all(&etc_hosts_cache, free, free);
    while(NULL != (ent = gethostent())) {
      int i = 0;
      char *name = ent->h_name;
      while(name) {
        void *vnode;
        static_host_node *node;
        if(!mtev_hash_retrieve(&etc_hosts_cache, name, strlen(name), &vnode)) {
          vnode = node = calloc(1, sizeof(*node));
          node->target = strdup(name);
          mtev_hash_store(&etc_hosts_cache, node->target, strlen(node->target), node);
        }
        node = vnode;
  
        if(ent->h_addrtype == AF_INET) {
          node->has_ip4 = 1;
          memcpy(&node->ip4, ent->h_addr_list[0], ent->h_length);
        }
        if(ent->h_addrtype == AF_INET6) {
          node->has_ip6 = 1;
          memcpy(&node->ip6, ent->h_addr_list[0], ent->h_length);
        }
        
        name = ent->h_aliases[i++];
      }
    }
    endhostent();
    mtevL(noit_debug, "reloaded %d /etc/hosts targets\n", mtev_hash_size(&etc_hosts_cache));
  }

  eventer_add_in_s_us(noit_check_etc_hosts_cache_refresh, NULL, 1, 0);
  return 0;
}
Exemplo n.º 5
0
void
noit_poller_init() {
  noit_check_tools_init();
  noit_skiplist_init(&polls_by_name);
  noit_skiplist_set_compare(&polls_by_name, __check_name_compare,
                            __check_name_compare);
  noit_skiplist_init(&watchlist);
  noit_skiplist_set_compare(&watchlist, __watchlist_compare,
                            __watchlist_compare);
  register_console_check_commands();
  eventer_name_callback("check_recycle_bin_processor",
                        check_recycle_bin_processor);
  eventer_add_in_s_us(check_recycle_bin_processor, NULL, 60, 0);
  noit_poller_reload(NULL);
}
Exemplo n.º 6
0
static int
noit_lua_general_init(noit_module_generic_t *self) {
  lua_general_conf_t *conf = get_config(self);
  lua_module_closure_t *lmc = &conf->lmc;

  if(!conf->module || !conf->function) {
    noitL(nlerr, "lua_general cannot be used without module and function config\n");
    return -1;
  }

  lmc->resume = lua_general_resume;
  lmc->lua_state = noit_lua_open(self->hdr.name, lmc, conf->script_dir);
  noitL(nldeb, "lua_general opening state -> %p\n", lmc->lua_state);
  if(lmc->lua_state == NULL) {
    noitL(noit_error, "lua_general could not add general functions\n");
    return -1;
  }
  luaL_openlib(lmc->lua_state, "noit", general_lua_funcs, 0);
  lmc->pending = calloc(1, sizeof(*lmc->pending));
  eventer_add_in_s_us(dispatch_general, self, 0, 0);
  return 0;
}
Exemplo n.º 7
0
int noit_check_resolver_loop(eventer_t e, int mask, void *c,
                             struct timeval *now) {
  noit_check_resolver_maintain();
  eventer_add_in_s_us(noit_check_resolver_loop, NULL, 1, 0);
  return 0;
}
Exemplo n.º 8
0
static int
mtev_lua_general_init(mtev_dso_generic_t *self) {
  const char * const *module;
  int (*f)(lua_State *);
  lua_general_conf_t *conf = get_config(self);
  lua_module_closure_t *lmc = pthread_getspecific(conf->key);

  if(lmc) return 0;

  if(!lmc) {
    lmc = calloc(1, sizeof(*lmc));
    lmc->self = self;
    mtev_hash_init(&lmc->state_coros);
    pthread_setspecific(conf->key, lmc);
  }

  if(!conf->module || !conf->function) {
    mtevL(nlerr, "lua_general cannot be used without module and function config\n");
    return -1;
  }

  lmc->resume = lua_general_resume;
  lmc->owner = pthread_self();
  lmc->eventer_id = eventer_is_loop(lmc->owner);
  lmc->lua_state = mtev_lua_open(self->hdr.name, lmc,
                                 conf->script_dir, conf->cpath);
  mtevL(nldeb, "lua_general opening state -> %p\n", lmc->lua_state);
  if(lmc->lua_state == NULL) {
    mtevL(mtev_error, "lua_general could not add general functions\n");
    return -1;
  }
  luaL_openlib(lmc->lua_state, "mtev", general_lua_funcs, 0);
  /* Load some preloads */

  for(module = conf->Cpreloads; module && *module; module++) {
    int len;
    char *symbol = NULL;
    len = strlen(*module) + strlen("luaopen_");
    symbol = malloc(len+1);
    if(!symbol) mtevL(nlerr, "Failed to preload %s: malloc error\n", *module);
    else {
      snprintf(symbol, len+1, "luaopen_%s", *module);
#ifdef RTLD_DEFAULT
      f = dlsym(RTLD_DEFAULT, symbol);
#else
      f = dlsym((void *)0, symbol);
#endif
      if(!f) mtevL(nlerr, "Failed to preload %s: %s not found\n", *module, symbol);
      else f(lmc->lua_state);
    }
    free(symbol);
  }

  lmc->pending = calloc(1, sizeof(*lmc->pending));
  mtev_hash_init(lmc->pending);

  if(conf->booted) return true;
  conf->booted = mtev_true;
  eventer_add_in_s_us(dispatch_general, self, 0, 0);

  if(conf->concurrent) {
    int i = 1;
    pthread_t tgt, thr;
    thr = eventer_choose_owner(i++);
    do {
      eventer_t e = eventer_in_s_us(dispatch_general, self, 0, 0);
      tgt = eventer_choose_owner(i++);
      eventer_set_owner(e, tgt);
      eventer_add(e);
    } while(!pthread_equal(thr,tgt));
  }
  return 0;
}