Changeset 833a45eed64e201e6831fcdd66cc1cad152c7fdd

Show
Ignore:
Timestamp:
02/10/08 21:45:19 (6 years ago)
Author:
Theo Schlossnagle <jesus@omniti.com>
git-committer:
Theo Schlossnagle <jesus@omniti.com> 1202679919 +0000
git-parent:

[e709e57b077e98a739f9352967497e00fa8a5fdf]

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

ls and section

Files:

Legend:

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

    rabfe586 r833a45e  
    436436                      noit_check_t *check) { 
    437437  char out[512]; 
     438  char uuid_str[41]; 
    438439  snprintf(out, sizeof(out), "%s/%s", check->target, check->name); 
    439   nc_printf(ncct, "%30s [%c%c%c]: %s\n", 
    440             out,  
    441             check->flags & NP_RUNNING  ? 'R' : ' ', 
    442             check->flags & NP_KILLED   ? 'K' : ' ', 
    443             check->flags & NP_DISABLED ? 'D' : ' ', 
    444             check->stats.current.status ? 
    445               check->stats.current.status : "unknown"); 
     440  uuid_unparse_lower(check->checkid, uuid_str); 
     441  nc_printf(ncct, "%s %s\n", uuid_str, out); 
     442  if(check->stats.current.status) 
     443    nc_printf(ncct, "\t%s\n", check->stats.current.status); 
    446444} 
    447445 
  • src/noit_conf.c

    rabfe586 r833a45e  
    7474  int i, cnt; 
    7575  noit_hash_table *table = NULL; 
    76   xmlXPathObjectPtr pobj
     76  xmlXPathObjectPtr pobj = NULL
    7777  xmlXPathContextPtr current_ctxt; 
    7878  xmlNodePtr current_node = (xmlNodePtr)section; 
     
    9999  } 
    100100 out: 
     101  if(pobj) xmlXPathFreeObject(pobj); 
    101102  if(current_ctxt && current_ctxt != xpath_ctxt) 
    102103    xmlXPathFreeContext(current_ctxt); 
     
    106107                                          const char *path) { 
    107108  noit_conf_section_t subsection = NULL; 
    108   xmlXPathObjectPtr pobj
     109  xmlXPathObjectPtr pobj = NULL
    109110  xmlXPathContextPtr current_ctxt; 
    110111  xmlNodePtr current_node = (xmlNodePtr)section; 
     
    121122  subsection = (noit_conf_section_t)xmlXPathNodeSetItem(pobj->nodesetval, 0); 
    122123 out: 
     124  if(pobj) xmlXPathFreeObject(pobj); 
    123125  if(current_ctxt && current_ctxt != xpath_ctxt) 
    124126    xmlXPathFreeContext(current_ctxt); 
     
    130132  int i; 
    131133  noit_conf_section_t *sections = NULL; 
    132   xmlXPathObjectPtr pobj
     134  xmlXPathObjectPtr pobj = NULL
    133135  xmlXPathContextPtr current_ctxt; 
    134136  xmlNodePtr current_node = (xmlNodePtr)section; 
     
    149151    sections[i] = (noit_conf_section_t)xmlXPathNodeSetItem(pobj->nodesetval, i); 
    150152 out: 
     153  if(pobj) xmlXPathFreeObject(pobj); 
    151154  if(current_ctxt && current_ctxt != xpath_ctxt) 
    152155    xmlXPathFreeContext(current_ctxt); 
     
    300303} 
    301304 
     305static int 
     306noit_console_config_cd(noit_console_closure_t ncct, 
     307                       int argc, char **argv, 
     308                       noit_console_state_t *state, void *closure) { 
     309  const char *err = "internal error"; 
     310  char *path, xpath[1024]; 
     311  noit_conf_t_userdata_t *info; 
     312  xmlXPathObjectPtr pobj = NULL; 
     313  xmlXPathContextPtr current_ctxt; 
     314  xmlNodePtr node = NULL; 
     315 
     316  if(argc != 1) { 
     317    nc_printf(ncct, "requires one argument\n"); 
     318    return -1; 
     319  } 
     320  info = noit_console_userdata_get(ncct, NOIT_CONF_T_USERDATA); 
     321  if(argv[0][0] == '/') 
     322    snprintf(xpath, sizeof(xpath), "/noit%s", argv[0]); 
     323  else { 
     324    snprintf(xpath, sizeof(xpath), "/noit%s/%s", info->path, argv[0]); 
     325  } 
     326  if(xpath[strlen(xpath)-1] == '/') xpath[strlen(xpath)-1] = '\0'; 
     327 
     328  current_ctxt = xpath_ctxt; 
     329  pobj = xmlXPathEval((xmlChar *)xpath, current_ctxt); 
     330  if(!pobj || pobj->type != XPATH_NODESET || 
     331     xmlXPathNodeSetIsEmpty(pobj->nodesetval)) { 
     332    err = "no such section"; 
     333    goto bad; 
     334  } 
     335  if(xmlXPathNodeSetGetLength(pobj->nodesetval) > 1) { 
     336    err = "ambiguous section"; 
     337    goto bad; 
     338  } 
     339 
     340  node = (noit_conf_section_t)xmlXPathNodeSetItem(pobj->nodesetval, 0); 
     341  path = (char *)xmlGetNodePath(node); 
     342  if(strncmp(path, "/noit/", strlen("/noit/")) && strcmp(path, "/noit")) { 
     343    err = "new path outside out tree"; 
     344    goto bad; 
     345  } 
     346  free(info->path); 
     347  if(!strcmp(path, "/noit")) 
     348    info->path = strdup("/"); 
     349  else 
     350    info->path = strdup((char *)xmlGetNodePath(node) + strlen("/noit")); 
     351  if(pobj) xmlXPathFreeObject(pobj); 
     352  return 0; 
     353 bad: 
     354  if(pobj) xmlXPathFreeObject(pobj); 
     355  nc_printf(ncct, "%s\n", err); 
     356  return -1; 
     357} 
     358static int 
     359noit_console_config_show(noit_console_closure_t ncct, 
     360                         int argc, char **argv, 
     361                         noit_console_state_t *state, void *closure) { 
     362  int i, cnt, cliplen = 0; 
     363  const char *path; 
     364  char xpath[1024]; 
     365  noit_conf_t_userdata_t *info; 
     366  xmlXPathObjectPtr pobj = NULL; 
     367  xmlXPathContextPtr current_ctxt; 
     368 
     369  if(argc > 1) { 
     370    nc_printf(ncct, "too many arguments\n"); 
     371    return -1; 
     372  } 
     373  if(argc == 1) { 
     374    path = argv[0]; 
     375  } 
     376  else { 
     377    info = noit_console_userdata_get(ncct, NOIT_CONF_T_USERDATA); 
     378    if(!info) { 
     379      nc_printf(ncct, "argument required when not in configuration mode\n"); 
     380      return -1; 
     381    } 
     382    path = info->path; 
     383  } 
     384  if(!master_config) { 
     385    nc_printf(ncct, "no config\n"); 
     386    return -1; 
     387  } 
     388 
     389  /* { / } is the only path that will end with a / 
     390   * in XPath { / / * } means something _entirely different than { / * } 
     391   * Ever notice how it is hard to describe xpath in C comments? 
     392   */ 
     393  cliplen = strlen("/noit/"); 
     394  if(!strcmp(path, "/")) 
     395    snprintf(xpath, sizeof(xpath), "/noit/*"); 
     396  else { 
     397    if(argc == 0) cliplen = strlen("/noit/") + strlen(path); 
     398    snprintf(xpath, sizeof(xpath), "/noit%s/*", path); 
     399  } 
     400 
     401  current_ctxt = xpath_ctxt; 
     402  pobj = xmlXPathEval((xmlChar *)xpath, current_ctxt); 
     403  if(!pobj || pobj->type != XPATH_NODESET) { 
     404    nc_printf(ncct, "no such object\n"); 
     405    goto bad; 
     406  } 
     407  if(xmlXPathNodeSetIsEmpty(pobj->nodesetval)) { 
     408    nc_printf(ncct, "empty\n"); 
     409  } 
     410  cnt = xmlXPathNodeSetGetLength(pobj->nodesetval); 
     411  for(i=0; i<cnt; i++) { 
     412    xmlNodePtr node; 
     413    node = (noit_conf_section_t)xmlXPathNodeSetItem(pobj->nodesetval, i); 
     414    nc_printf(ncct, "%s\n", xmlGetNodePath(node) + cliplen); 
     415  } 
     416 bad: 
     417  if(pobj) xmlXPathFreeObject(pobj); 
     418  return -1; 
     419} 
     420 
    302421static char * 
    303422conf_t_prompt(EditLine *el) { 
     
    332451  _conf_t_state->console_prompt_function = conf_t_prompt; 
    333452  noit_console_state_add_cmd(_conf_t_state, &console_command_exit); 
     453  noit_console_state_add_cmd(_conf_t_state, 
     454    NCSCMD("ls", noit_console_config_show, NULL, NULL)); 
     455  noit_console_state_add_cmd(_conf_t_state, 
     456    NCSCMD("section", noit_console_config_cd, NULL, NULL)); 
    334457 
    335458  _conf_state = calloc(1, sizeof(*_conf_state));