Changeset 71803743714376fc12fb54b3506df6a4c17a8828

Show
Ignore:
Timestamp:
08/04/08 02:12:25 (6 years ago)
Author:
Theo Schlossnagle <jesus@omniti.com>
git-committer:
Theo Schlossnagle <jesus@omniti.com> 1217815945 +0000
git-parent:

[3be398539c4bcd0e77acf4390c6dda1635329b58]

git-author:
Theo Schlossnagle <jesus@omniti.com> 1217815945 +0000
Message:

oh my word... basic function, refs #49

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • src/noit_check.c

    r5e653fe r7180374  
    2727 
    2828static noit_hash_table polls = NOIT_HASH_EMPTY; 
     29static noit_skiplist watchlist = { 0 }; 
    2930static noit_skiplist polls_by_name = { 0 }; 
    3031static u_int32_t __config_load_generation = 0; 
     
    6263  if((rv = strcmp(ac->name, bc->name)) != 0) return rv; 
    6364  return 0; 
     65} 
     66static int __watchlist_compare(const void *a, const void *b) { 
     67  const noit_check_t *ac = a; 
     68  const noit_check_t *bc = b; 
     69  int rv; 
     70  if((rv = memcmp(ac->checkid, bc->checkid, sizeof(ac->checkid))) != 0) return rv; 
     71  if(ac->period < bc->period) return -1; 
     72  if(ac->period == bc->period) return 0; 
     73  return 1; 
    6474} 
    6575int 
     
    198208} 
    199209 
     210int 
     211noit_check_activate(noit_check_t *check) { 
     212  noit_module_t *mod; 
     213  mod = noit_module_lookup(check->module); 
     214  if(mod && mod->initiate_check && !NOIT_CHECK_LIVE(check)) { 
     215    if((check->flags & NP_DISABLED) == 0) { 
     216      mod->initiate_check(mod, check, 0, NULL); 
     217      return 1; 
     218    } 
     219    else 
     220      noitL(noit_debug, "Skipping %s`%s, disabled.\n", 
     221            check->target, check->name); 
     222  } 
     223  else { 
     224    noitL(noit_stderr, "Cannot find module '%s'\n", check->module); 
     225    check->flags |= NP_DISABLED; 
     226  } 
     227  return 0; 
     228} 
     229 
    200230void 
    201231noit_poller_initiate() { 
     
    206236  while(noit_hash_next(&polls, &iter, (const char **)key_id, &klen, 
    207237                       (void **)&check)) { 
    208     noit_module_t *mod; 
    209     mod = noit_module_lookup(check->module); 
    210     if(mod && mod->initiate_check) { 
    211       if(NOIT_CHECK_LIVE(check)) 
    212         continue; 
    213       if((check->flags & NP_DISABLED) == 0) { 
    214         mod->initiate_check(mod, check, 0, NULL); 
    215       } 
    216       else 
    217         noitL(noit_debug, "Skipping %s`%s, disabled.\n", 
    218               check->target, check->name); 
    219     } 
    220     else { 
    221       noitL(noit_stderr, "Cannot find module '%s'\n", check->module); 
    222       check->flags |= NP_DISABLED; 
    223     } 
     238    noit_check_activate(check); 
    224239  } 
    225240} 
     
    321336  noit_skiplist_set_compare(&polls_by_name, __check_name_compare, 
    322337                            __check_name_compare); 
     338  noit_skiplist_init(&watchlist); 
     339  noit_skiplist_set_compare(&watchlist, __watchlist_compare, 
     340                            __watchlist_compare); 
    323341  register_console_check_commands(); 
    324342  noit_poller_reload(NULL); 
     343} 
     344 
     345noit_check_t * 
     346noit_check_clone(uuid_t in) { 
     347  noit_check_t *checker, *new_check; 
     348  if(noit_hash_retrieve(&polls, 
     349                        (char *)in, UUID_SIZE, 
     350                        (void **)&checker) == 0) { 
     351    return NULL; 
     352  } 
     353  if(checker->oncheck) { 
     354    return NULL; 
     355  } 
     356  new_check = calloc(1, sizeof(*new_check)); 
     357  memcpy(new_check, checker, sizeof(*new_check)); 
     358  new_check->target = strdup(new_check->target); 
     359  new_check->module = strdup(new_check->module); 
     360  new_check->name = strdup(new_check->name); 
     361  new_check->filterset = strdup(new_check->filterset); 
     362  new_check->flags = 0; 
     363  new_check->fire_event = NULL; 
     364  memset(&new_check->last_fire_time, 0, sizeof(new_check->last_fire_time)); 
     365  memset(&new_check->stats, 0, sizeof(new_check->stats)); 
     366  new_check->closure = NULL; 
     367  new_check->config = calloc(1, sizeof(*new_check->config)); 
     368  noit_hash_merge_as_dict(new_check->config, checker->config); 
     369  return new_check; 
     370} 
     371 
     372noit_check_t * 
     373noit_check_watch(uuid_t in, int period) { 
     374  /* First look for a copy that is being watched */ 
     375  noit_check_t n, *f; 
     376 
     377  uuid_copy(n.checkid, in); 
     378  n.period = period; 
     379 
     380  f = noit_skiplist_find(&watchlist, &n, NULL); 
     381  if(f) return f; 
     382  f = noit_check_clone(in); 
     383  if(!f) return NULL; 
     384  f->period = period; 
     385  f->timeout = period - 1; 
     386  f->flags |= NP_TRANSIENT; 
     387  noit_skiplist_insert(&watchlist, f); 
     388  return f; 
     389} 
     390 
     391noit_check_t * 
     392noit_check_get_watch(uuid_t in, int period) { 
     393  noit_check_t n, *f; 
     394 
     395  uuid_copy(n.checkid, in); 
     396  n.period = period; 
     397 
     398  f = noit_skiplist_find(&watchlist, &n, NULL); 
     399  return f; 
     400} 
     401 
     402void 
     403noit_check_transient_add_feed(noit_check_t *check, const char *feed) { 
     404  char *feedcopy; 
     405  if(!check->feeds) { 
     406    check->feeds = calloc(1, sizeof(*check->feeds)); 
     407    noit_skiplist_init(check->feeds); 
     408    noit_skiplist_set_compare(check->feeds, 
     409                              (noit_skiplist_comparator_t)strcmp, 
     410                              (noit_skiplist_comparator_t)strcmp); 
     411  } 
     412  feedcopy = strdup(feed); 
     413  /* No error on failure -- it's already there */ 
     414  if(noit_skiplist_insert(check->feeds, feedcopy) == NULL) free(feedcopy); 
     415} 
     416void 
     417noit_check_transient_remove_feed(noit_check_t *check, const char *feed) { 
     418  if(!check->feeds) return; 
     419  if(feed) noit_skiplist_remove(check->feeds, feed, free); 
     420  if(check->feeds->size == 0) { 
     421    noit_skiplist_remove(&watchlist, check, NULL); 
     422    noit_skiplist_destroy(check->feeds, free); 
     423    free(check->feeds); 
     424    check->feeds = NULL; 
     425    if(check->flags & NP_TRANSIENT) { 
     426      noitL(noit_debug, "check %s`%s @ %dms has no more listeners.\n", 
     427            check->target, check->name, check->period); 
     428      check->flags |= NP_KILLED; 
     429    } 
     430  } 
    325431} 
    326432 
     
    385491  new_check->flags = (new_check->flags & ~mask) | flags; 
    386492 
    387   /* This remove could fail -- no big deal */ 
    388   noit_skiplist_remove(&polls_by_name, new_check, NULL); 
    389  
    390   /* This insert could fail.. which means we have a conflict on 
    391    * target`name.  That should result in the check being disabled. */ 
    392   if(!noit_skiplist_insert(&polls_by_name, new_check)) { 
    393     noitL(noit_stderr, "Check %s`%s disabled due to naming conflict\n", 
    394           new_check->target, new_check->name); 
    395     new_check->flags |= NP_DISABLED; 
     493  if(!(new_check->flags & NP_TRANSIENT)) { 
     494    /* This remove could fail -- no big deal */ 
     495    noit_skiplist_remove(&polls_by_name, new_check, NULL); 
     496 
     497    /* This insert could fail.. which means we have a conflict on 
     498     * target`name.  That should result in the check being disabled. */ 
     499    if(!noit_skiplist_insert(&polls_by_name, new_check)) { 
     500      noitL(noit_stderr, "Check %s`%s disabled due to naming conflict\n", 
     501            new_check->target, new_check->name); 
     502      new_check->flags |= NP_DISABLED; 
     503    } 
    396504  } 
    397505  noit_check_log_check(new_check); 
  • src/noit_check.h

    r5e653fe r7180374  
    1414#include "eventer/eventer.h" 
    1515#include "utils/noit_hash.h" 
     16#include "utils/noit_skiplist.h" 
    1617#include "noit_conf.h" 
    1718#include "noit_console.h" 
     
    3435 */ 
    3536 
    36 #define NP_RUNNING  0x00000001 
    37 #define NP_KILLED   0x00000002 
    38 #define NP_DISABLED 0x00000004 
    39 #define NP_UNCONFIG 0x00000008 
     37#define NP_RUNNING   0x00000001 
     38#define NP_KILLED    0x00000002 
     39#define NP_DISABLED  0x00000004 
     40#define NP_UNCONFIG  0x00000008 
     41#define NP_TRANSIENT 0x00000010 
    4042 
    4143#define NP_UNKNOWN '0'             /* stats_t.{available,state} */ 
     
    98100  u_int32_t period;            /* period of checks in milliseconds */ 
    99101  u_int32_t timeout;           /* timeout of check in milliseconds */ 
    100   u_int32_t flags;             /* NP_KILLED, NP_RUNNING */ 
     102  u_int32_t flags;             /* NP_KILLED, NP_RUNNING, NP_TRANSIENT */ 
    101103 
    102104  dep_list_t *causal_checks; 
     
    109111  u_int32_t generation;        /* This can roll, we don't care */ 
    110112  void *closure; 
     113 
     114  noit_skiplist *feeds; 
    111115} noit_check_t; 
    112116 
     
    152156 
    153157API_EXPORT(int) 
     158  noit_check_activate(noit_check_t *check); 
     159 
     160API_EXPORT(int) 
    154161  noit_poller_deschedule(uuid_t in); 
    155162 
     
    178185  noit_stats_snprint_metric(char *b, int l, metric_t *m); 
    179186 
     187API_EXPORT(noit_check_t *) 
     188  noit_check_clone(uuid_t in); 
     189API_EXPORT(noit_check_t *) 
     190  noit_check_watch(uuid_t in, int period); 
     191API_EXPORT(noit_check_t *) 
     192  noit_check_get_watch(uuid_t in, int period); 
     193API_EXPORT(void) 
     194  noit_check_transient_add_feed(noit_check_t *check, const char *feed); 
     195API_EXPORT(void) 
     196  noit_check_transient_remove_feed(noit_check_t *check, const char *feed); 
     197 
    180198/* These are from noit_check_log.c */ 
    181199API_EXPORT(void) noit_check_log_check(noit_check_t *check); 
  • src/noit_check_log.c

    r70451c5 r7180374  
    3333#define SECPART(a) ((unsigned long)(a)->tv_sec) 
    3434#define MSECPART(a) ((unsigned long)((a)->tv_usec / 1000)) 
     35 
     36static void 
     37handle_extra_feeds(noit_check_t *check, 
     38                   void (*log_f)(noit_log_stream_t ls, noit_check_t *check)) { 
     39  noit_log_stream_t ls; 
     40  noit_skiplist_node *curr, *next; 
     41  const char *feed_name; 
     42 
     43  if(!check->feeds) return; 
     44  curr = next = noit_skiplist_getlist(check->feeds); 
     45  while(curr) { 
     46    /* We advance next here (before we try to use curr). 
     47     * We may need to remove the node we're looking at and that would 
     48     * disturb the iterator, so advance in advance. */ 
     49    noit_skiplist_next(check->feeds, &next); 
     50    feed_name = (char *)curr->data; 
     51    ls = noit_log_stream_find(feed_name); 
     52    if(ls) log_f(ls, check); 
     53    else { 
     54      noit_skiplisti_remove(check->feeds, curr, free); 
     55    } 
     56    curr = next; 
     57  } 
     58  /* We're done... we may have destroyed the last feed. 
     59   * that combined with transience means we should kill the check */ 
     60  noit_check_transient_remove_feed(check, NULL); 
     61} 
     62 
     63static void 
     64_noit_check_log_check(noit_log_stream_t ls, 
     65                      noit_check_t *check) { 
     66  struct timeval __now; 
     67  char uuid_str[37]; 
     68 
     69  uuid_unparse_lower(check->checkid, uuid_str); 
     70  gettimeofday(&__now, NULL); 
     71  noitL(ls, "C\t%lu.%03lu\t%s\t%s\t%s\t%s\n", 
     72        SECPART(&__now), MSECPART(&__now), 
     73        uuid_str, check->target, check->module, check->name); 
     74} 
     75 
    3576void 
    3677noit_check_log_check(noit_check_t *check) { 
    37   struct timeval __now; 
     78  handle_extra_feeds(check, _noit_check_log_check); 
     79  if(!(check->flags & NP_TRANSIENT)) { 
     80    SETUP_LOG(check, return); 
     81    _noit_check_log_check(check_log, check); 
     82  } 
     83
     84 
     85static void 
     86_noit_check_log_status(noit_log_stream_t ls, 
     87                       noit_check_t *check) { 
     88  stats_t *c; 
    3889  char uuid_str[37]; 
    39   SETUP_LOG(check, return); 
    40  
    41   gettimeofday(&__now, NULL); 
     90 
    4291  uuid_unparse_lower(check->checkid, uuid_str); 
    43   noitL(check_log, "C\t%lu.%03lu\t%s\t%s\t%s\t%s\n", 
    44         SECPART(&__now), MSECPART(&__now), uuid_str, 
    45         check->target, check->module, check->name); 
     92  c = &check->stats.current; 
     93  noitL(ls, "S\t%lu.%03lu\t%s\t%c\t%c\t%d\t%s\n", 
     94        SECPART(&c->whence), MSECPART(&c->whence), uuid_str, 
     95        (char)c->state, (char)c->available, c->duration, c->status); 
    4696} 
    4797void 
    4898noit_check_log_status(noit_check_t *check) { 
    49   char uuid_str[37]; 
    50   stats_t *c; 
    51   SETUP_LOG(status, return); 
    52  
    53   uuid_unparse_lower(check->checkid, uuid_str); 
    54   c = &check->stats.current; 
    55   noitL(status_log, "S\t%lu.%03lu\t%s\t%c\t%c\t%d\t%s\n", 
    56         SECPART(&c->whence), MSECPART(&c->whence), uuid_str, 
    57         (char)c->state, (char)c->available, c->duration, c->status); 
    58 
    59 void 
    60 noit_check_log_metrics(noit_check_t *check) { 
     99  handle_extra_feeds(check, _noit_check_log_status); 
     100  if(!(check->flags & NP_TRANSIENT)) { 
     101    SETUP_LOG(status, return); 
     102    _noit_check_log_status(status_log, check); 
     103  } 
     104
     105static void 
     106_noit_check_log_metrics(noit_log_stream_t ls, noit_check_t *check) { 
    61107  char uuid_str[37]; 
    62108  noit_hash_iter iter = NOIT_HASH_ITER_ZERO; 
     
    65111  metric_t *m; 
    66112  stats_t *c; 
    67   SETUP_LOG(metrics, return); 
    68113 
    69114  uuid_unparse_lower(check->checkid, uuid_str); 
     
    74119 
    75120    if(!m->metric_value.s) { /* they are all null */ 
    76       noitL(metrics_log, "M\t%lu.%03lu\t%s\t%s\t%c\t[[null]]\n", 
     121      noitL(ls, "M\t%lu.%03lu\t%s\t%s\t%c\t[[null]]\n", 
    77122            SECPART(&c->whence), MSECPART(&c->whence), uuid_str, 
    78123            m->metric_name, m->metric_type); 
     
    81126      switch(m->metric_type) { 
    82127        case METRIC_INT32: 
    83           noitL(metrics_log, "M\t%lu.%03lu\t%s\t%s\t%c\t%d\n", 
     128          noitL(ls, "M\t%lu.%03lu\t%s\t%s\t%c\t%d\n", 
    84129                SECPART(&c->whence), MSECPART(&c->whence), uuid_str, 
    85130                m->metric_name, m->metric_type, *(m->metric_value.i)); 
    86131          break; 
    87132        case METRIC_UINT32: 
    88           noitL(metrics_log, "M\t%lu.%03lu\t%s\t%s\t%c\t%u\n", 
     133          noitL(ls, "M\t%lu.%03lu\t%s\t%s\t%c\t%u\n", 
    89134                SECPART(&c->whence), MSECPART(&c->whence), uuid_str, 
    90135                m->metric_name, m->metric_type, *(m->metric_value.I)); 
    91136          break; 
    92137        case METRIC_INT64: 
    93           noitL(metrics_log, "M\t%lu.%03lu\t%s\t%s\t%c\t%lld\n", 
     138          noitL(ls, "M\t%lu.%03lu\t%s\t%s\t%c\t%lld\n", 
    94139                SECPART(&c->whence), MSECPART(&c->whence), uuid_str, 
    95140                m->metric_name, m->metric_type, *(m->metric_value.l)); 
    96141          break; 
    97142        case METRIC_UINT64: 
    98           noitL(metrics_log, "M\t%lu.%03lu\t%s\t%s\t%c\t%llu\n", 
     143          noitL(ls, "M\t%lu.%03lu\t%s\t%s\t%c\t%llu\n", 
    99144                SECPART(&c->whence), MSECPART(&c->whence), uuid_str, 
    100145                m->metric_name, m->metric_type, *(m->metric_value.L)); 
    101146          break; 
    102147        case METRIC_DOUBLE: 
    103           noitL(metrics_log, "M\t%lu.%03lu\t%s\t%s\t%c\t%.12e\n", 
     148          noitL(ls, "M\t%lu.%03lu\t%s\t%s\t%c\t%.12e\n", 
    104149                SECPART(&c->whence), MSECPART(&c->whence), uuid_str, 
    105150                m->metric_name, m->metric_type, *(m->metric_value.n)); 
    106151          break; 
    107152        case METRIC_STRING: 
    108           noitL(metrics_log, "M\t%lu.%03lu\t%s\t%s\t%c\t%s\n", 
     153          noitL(ls, "M\t%lu.%03lu\t%s\t%s\t%c\t%s\n", 
    109154                SECPART(&c->whence), MSECPART(&c->whence), uuid_str, 
    110155                m->metric_name, m->metric_type, m->metric_value.s); 
     
    117162  } 
    118163} 
     164void 
     165noit_check_log_metrics(noit_check_t *check) { 
     166  handle_extra_feeds(check, _noit_check_log_metrics); 
     167  if(!(check->flags & NP_TRANSIENT)) { 
     168    SETUP_LOG(metrics, return); 
     169    _noit_check_log_metrics(metrics_log, check); 
     170  } 
     171} 
     172 
    119173int 
    120174noit_stats_snprint_metric(char *b, int l, metric_t *m) { 
  • src/noit_conf_checks.c

    r70451c5 r7180374  
    305305    } 
    306306    goto out; 
     307  } 
     308 out: 
     309  if(pobj) xmlXPathFreeObject(pobj); 
     310  return 0; 
     311} 
     312static int 
     313noit_console_watch_check(noit_console_closure_t ncct, 
     314                         int argc, char **argv, 
     315                         noit_console_state_t *state, void *closure) { 
     316  int i, cnt; 
     317  int adding = (int)closure; 
     318  int period = 0; 
     319  char xpath[1024]; 
     320  xmlXPathObjectPtr pobj = NULL; 
     321  xmlXPathContextPtr xpath_ctxt = NULL; 
     322 
     323  noit_conf_xml_xpath(NULL, &xpath_ctxt); 
     324  if(argc < 1 || argc > 2) { 
     325    nc_printf(ncct, "requires one or two arguments\n"); 
     326    return -1; 
     327  } 
     328  /* An alternate period */ 
     329  if(argc == 2) period = atoi(argv[1]); 
     330 
     331  if(noit_console_mkcheck_xpath(xpath, sizeof(xpath), NULL, 
     332                                argc ? argv[0] : NULL)) { 
     333    nc_printf(ncct, "ERROR: could not find check '%s'\n", argv[0]); 
     334    return -1; 
     335  } 
     336 
     337  pobj = xmlXPathEval((xmlChar *)xpath, xpath_ctxt); 
     338  if(!pobj || pobj->type != XPATH_NODESET || 
     339     xmlXPathNodeSetIsEmpty(pobj->nodesetval)) { 
     340    nc_printf(ncct, "no checks found\n"); 
     341    goto out; 
     342  } 
     343  cnt = xmlXPathNodeSetGetLength(pobj->nodesetval); 
     344  for(i=0; i<cnt; i++) { 
     345    uuid_t checkid; 
     346    noit_check_t *check; 
     347    xmlNodePtr node; 
     348    char *uuid_conf; 
     349 
     350    node = (noit_conf_section_t)xmlXPathNodeSetItem(pobj->nodesetval, i); 
     351    uuid_conf = (char *)xmlGetProp(node, (xmlChar *)"uuid"); 
     352    if(!uuid_conf || uuid_parse(uuid_conf, checkid)) { 
     353      nc_printf(ncct, "%s has invalid or missing UUID!\n", 
     354                (char *)xmlGetNodePath(node) + strlen("/noit")); 
     355      continue; 
     356    } 
     357    if(period == 0) { 
     358      check = noit_poller_lookup(checkid); 
     359      if(!check) continue; 
     360      if(adding) noit_check_transient_add_feed(check, ncct->feed_path); 
     361      else noit_check_transient_remove_feed(check, ncct->feed_path); 
     362    } 
     363    else { 
     364      if(adding) { 
     365        check = noit_check_watch(checkid, period); 
     366        /* This check must be watched from the console */ 
     367        noit_check_transient_add_feed(check, ncct->feed_path); 
     368        /* Note the check */ 
     369        noit_check_log_check(check); 
     370        /* kick it off, if it isn't running already */ 
     371        if(!NOIT_CHECK_LIVE(check)) noit_check_activate(check); 
     372      } 
     373      else { 
     374        check = noit_check_get_watch(checkid, period); 
     375        if(check) noit_check_transient_remove_feed(check, ncct->feed_path); 
     376      } 
     377    } 
    307378  } 
    308379 out: 
     
    12261297static 
    12271298void register_console_config_commands() { 
    1228   cmd_info_t *showcmd
     1299  cmd_info_t *showcmd, *nocmd
    12291300  noit_console_state_t *tl, *_conf_state, *_conf_t_state, 
    12301301                       *_conf_t_check_state, 
     
    12761347  ADD_CMD(showcmd->dstate, "check", noit_console_show_check, NULL, NULL); 
    12771348 
     1349  ADD_CMD(tl, "watch", noit_console_watch_check, NULL, (void *)1); 
     1350 
     1351  nocmd = noit_console_state_get_cmd(tl, "no"); 
     1352  ADD_CMD(nocmd->dstate, "watch", noit_console_watch_check, NULL, (void *)0); 
     1353 
    12781354  DELEGATE_CMD(_conf_t_state, "write", _write_state); 
    12791355  DELEGATE_CMD(_conf_t_state, "attribute", _attr_state); 
  • src/noit_console.c

    r137f7c6 r7180374  
    156156void 
    157157noit_console_closure_free(noit_console_closure_t ncct) { 
     158  noit_log_stream_t lf; 
    158159  if(ncct->el) el_end(ncct->el); 
    159160  if(ncct->hist) history_end(ncct->hist); 
     
    168169    ncct->state_stack = tmp->last; 
    169170    free(tmp); 
     171  } 
     172  lf = noit_log_stream_find(ncct->feed_path); 
     173  noit_log_stream_remove(ncct->feed_path); 
     174  if(lf) { 
     175    noit_log_stream_free(lf); 
    170176  } 
    171177  free(ncct); 
     
    234240 
    235241void 
    236 noit_console_init() { 
    237   el_multi_init(); 
    238   signal(SIGTTOU, SIG_IGN); 
    239   eventer_name_callback("noit_console", noit_console_handler); 
    240 } 
    241  
    242 void 
    243242noit_console_dispatch(eventer_t e, const char *buffer, 
    244243                      noit_console_closure_t ncct) { 
     
    313312socket_error: 
    314313    /* Exceptions cause us to simply snip the connection */ 
     314 
     315    /* This removes the log feed which is important to do before calling close */ 
    315316    eventer_remove_fd(e->fd); 
    316     e->opset->close(e->fd, &newmask, e); 
    317317    if(ncct) noit_console_closure_free(ncct); 
    318318    if(ac) acceptor_closure_free(ac); 
     319    e->opset->close(e->fd, &newmask, e); 
    319320    return 0; 
    320321  } 
     
    350351      noit_console_state_init(ncct); 
    351352    } 
     353    snprintf(ncct->feed_path, sizeof(ncct->feed_path), "console/%d", e->fd); 
     354    noit_log_stream_new(ncct->feed_path, "noit_console", ncct->feed_path, 
     355                        ncct, NULL); 
    352356    noit_console_motd(e, ac, ncct); 
    353357    ncct->initialized = 1; 
     
    416420} 
    417421 
     422static int 
     423noit_console_logio_open(noit_log_stream_t ls) { 
     424  return 0; 
     425} 
     426static int 
     427noit_console_logio_reopen(noit_log_stream_t ls) { 
     428  /* no op */ 
     429  return 0; 
     430} 
     431static int 
     432noit_console_logio_write(noit_log_stream_t ls, const void *buf, size_t len) { 
     433  noit_console_closure_t ncct = ls->op_ctx; 
     434  int rv, rlen, mask; 
     435  if(!ncct) return 0; 
     436  rlen = nc_write(ls->op_ctx, buf, len); 
     437  while((rv = noit_console_continue_sending(ncct, &mask)) == -1 && errno == EINTR); 
     438  if(rv == -1 && errno == EAGAIN) { 
     439    ncct->e->mask = mask | EVENTER_EXCEPTION; 
     440    eventer_update(ncct->e); 
     441  } 
     442  return rlen; 
     443} 
     444static int 
     445noit_console_logio_close(noit_log_stream_t ls) { 
     446  ls->op_ctx = NULL; 
     447  return 0; 
     448} 
     449static logops_t noit_console_logio_ops = { 
     450  noit_console_logio_open, 
     451  noit_console_logio_reopen, 
     452  noit_console_logio_write, 
     453  noit_console_logio_close, 
     454}; 
     455 
     456void 
     457noit_console_init() { 
     458  el_multi_init(); 
     459  signal(SIGTTOU, SIG_IGN); 
     460  noit_register_logops("noit_console", &noit_console_logio_ops); 
     461  eventer_name_callback("noit_console", noit_console_handler); 
     462} 
     463 
  • src/noit_console.h

    r4d6b73a r7180374  
    6666typedef struct __noit_console_closure { 
    6767  int initialized; 
     68  char feed_path[128]; 
    6869  eventer_t e;           /* The event it is attached to.  This 
    6970                          * is needed so it can write itself out */ 
  • src/noit_console_state.c

    r4d6b73a r7180374  
    338338  static noit_console_state_t *_top_level_state = NULL; 
    339339  if(!_top_level_state) { 
    340     static noit_console_state_t *show_state; 
     340    static noit_console_state_t *no_state; 
    341341    _top_level_state = noit_console_state_alloc(); 
    342342    noit_console_state_add_cmd(_top_level_state, &console_command_exit); 
    343     show_state = noit_console_state_alloc(); 
    344343    noit_console_state_add_cmd(_top_level_state, 
    345       NCSCMD("show", noit_console_state_delegate, show_state, NULL)); 
     344      NCSCMD("show", noit_console_state_delegate, 
     345             noit_console_state_alloc(), NULL)); 
     346    no_state = noit_console_state_alloc(); 
     347    noit_console_state_add_cmd(_top_level_state, 
     348      NCSCMD("no", noit_console_state_delegate, 
     349             no_state, NULL)); 
     350 
    346351    noit_console_state_add_cmd(_top_level_state, &console_command_shutdown); 
    347352    noit_console_state_add_cmd(_top_level_state, &console_command_restart); 
  • src/utils/noit_skiplist.c

    r2f47438 r7180374  
    375375  while(noit_skiplist_pop(sl->index, noit_skiplisti_destroy) != NULL); 
    376376  noit_skiplist_remove_all(sl, myfree); 
    377   free(sl); 
    378377} 
    379378void *noit_skiplist_pop(noit_skiplist * a, noit_freefunc_t myfree)