Changeset abfe5861994b2f5d62f789bf196ef636b0ef04fe
- Timestamp:
- 02/10/08 20:06:22 (5 years ago)
- git-parent:
- Files:
-
- src/noit_check.c (modified) (4 diffs)
- src/noit_conf.c (modified) (4 diffs)
- src/noit_console.h (modified) (4 diffs)
- src/noit_console_state.c (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
src/noit_check.c
r1d69a01 rabfe586 19 19 #include "noit_check.h" 20 20 #include "noit_module.h" 21 #include "noit_console.h" 21 22 #include "eventer/eventer.h" 22 23 … … 30 31 uuid_t foo; 31 32 }; 33 34 static void register_console_check_commands(); 32 35 33 36 #define UUID_SIZE sizeof(struct uuid_dummy) … … 219 222 noit_poller_load_checks(); 220 223 noit_poller_make_causal_map(); 224 register_console_check_commands(); 221 225 noit_poller_initiate(); 222 226 } … … 427 431 } 428 432 } 433 434 static void 435 nc_printf_check_brief(noit_console_closure_t ncct, 436 noit_check_t *check) { 437 char out[512]; 438 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"); 446 } 447 448 static int 449 noit_console_show_checks(noit_console_closure_t ncct, 450 int argc, char **argv, 451 noit_console_state_t *dstate, 452 void *closure) { 453 struct timeval _now; 454 noit_hash_iter iter = NOIT_HASH_ITER_ZERO; 455 uuid_t key_id; 456 int klen; 457 noit_check_t *check; 458 459 gettimeofday(&_now, NULL); 460 while(noit_hash_next(&polls, &iter, (const char **)key_id, &klen, 461 (void **)&check)) { 462 nc_printf_check_brief(ncct, check); 463 } 464 return 0; 465 } 466 static void 467 register_console_check_commands() { 468 noit_console_state_t *tl; 469 cmd_info_t *showcmd; 470 471 tl = noit_console_state_initial(); 472 showcmd = noit_console_state_get_cmd(tl, "show"); 473 assert(showcmd && showcmd->dstate); 474 475 noit_console_state_add_cmd(showcmd->dstate, 476 NCSCMD("checks", noit_console_show_checks, NULL, NULL)); 477 } 478 src/noit_conf.c
r1fe89bb rabfe586 39 39 }; 40 40 41 void register_console_config_commands();41 static void register_console_config_commands(); 42 42 43 43 void noit_conf_init() { … … 284 284 static int 285 285 noit_console_state_conf_terminal(noit_console_closure_t ncct, 286 int argc, char **argv, void *state) { 286 int argc, char **argv, 287 noit_console_state_t *state, void *closure) { 287 288 noit_conf_t_userdata_t *info; 288 289 if(argc) { … … 322 323 } 323 324 325 static 324 326 void register_console_config_commands() { 325 327 noit_console_state_t *tl, *_conf_state, *_conf_t_state; … … 333 335 _conf_state = calloc(1, sizeof(*_conf_state)); 334 336 noit_console_state_add_cmd(_conf_state, 335 NCSCMD("terminal", noit_console_state_conf_terminal, _conf_t_state ));337 NCSCMD("terminal", noit_console_state_conf_terminal, _conf_t_state, NULL)); 336 338 337 339 noit_console_state_add_cmd(tl, 338 NCSCMD("configure", noit_console_state_delegate, _conf_state ));339 } 340 NCSCMD("configure", noit_console_state_delegate, _conf_state, NULL)); 341 } src/noit_console.h
r1fe89bb rabfe586 18 18 19 19 typedef int (*console_cmd_func_t)(struct __noit_console_closure *, 20 int, char **, void *); 20 int, char **, 21 struct _console_state *, void *); 21 22 typedef char *(*console_prompt_func_t)(EditLine *); 22 23 typedef void (*state_free_func_t)(struct _console_state *); … … 24 25 25 26 typedef struct { 26 const char *name; 27 console_cmd_func_t func; 28 void *closure; 27 const char *name; 28 console_cmd_func_t func; 29 struct _console_state *dstate; 30 void *closure; 29 31 } cmd_info_t; 30 32 … … 110 112 API_EXPORT(int) 111 113 noit_console_state_pop(noit_console_closure_t ncct, int argc, char **argv, 112 void *);114 noit_console_state_t *, void *); 113 115 114 116 API_EXPORT(int) 115 117 noit_console_state_add_cmd(noit_console_state_t *state, 116 118 cmd_info_t *cmd); 119 120 API_EXPORT(cmd_info_t *) 121 noit_console_state_get_cmd(noit_console_state_t *state, 122 const char *name); 117 123 118 124 API_EXPORT(noit_console_state_t *) … … 140 146 API_EXPORT(int) 141 147 noit_console_state_delegate(noit_console_closure_t ncct, 142 int argc, char **argv, void *closure); 148 int argc, char **argv, 149 noit_console_state_t *dstate, 150 void *closure); 143 151 144 152 API_EXPORT(cmd_info_t *) 145 NCSCMD(const char *name, console_cmd_func_t func, void *closure); 153 NCSCMD(const char *name, console_cmd_func_t func, 154 noit_console_state_t *dstate, void *closure); 146 155 147 156 #endif src/noit_console_state.c
r7192210 rabfe586 13 13 #include "noit_tokenizer.h" 14 14 15 cmd_info_t console_command_exit = { "exit", noit_console_state_pop, NULL }; 15 cmd_info_t console_command_exit = { 16 "exit", noit_console_state_pop, NULL, NULL 17 }; 16 18 17 19 static char * … … 23 25 int 24 26 noit_console_state_delegate(noit_console_closure_t ncct, 25 int argc, char **argv, void *closure) { 27 int argc, char **argv, 28 noit_console_state_t *dstate, 29 void *closure) { 26 30 noit_console_state_stack_t tmps = { 0 }; 27 31 28 32 if(argc == 0) { 29 33 nc_printf(ncct, "arguments expected\n"); 34 /* XXX: noit_console_render_help(dstate); */ 30 35 return -1; 31 36 } 32 tmps.state = closure; 37 if(!dstate) { 38 nc_printf(ncct, "internal error: no delegate state\n"); 39 return -1; 40 } 41 tmps.state = dstate; 33 42 return _noit_console_state_do(ncct, &tmps, argc, argv); 34 43 } … … 49 58 return -1; 50 59 } 51 return cmd->func(ncct, argc-1, argv+1, cmd-> closure);60 return cmd->func(ncct, argc-1, argv+1, cmd->dstate, cmd->closure); 52 61 } 53 62 int … … 73 82 } 74 83 84 cmd_info_t * 85 noit_console_state_get_cmd(noit_console_state_t *state, 86 const char *name) { 87 cmd_info_t *cmd = NULL; 88 if(noit_hash_retrieve(&state->cmds, name, strlen(name), (void **)&cmd)) 89 return cmd; 90 return NULL; 91 } 92 75 93 noit_console_state_t * 76 94 noit_console_state_build(console_prompt_func_t promptf, cmd_info_t **clist, … … 90 108 91 109 cmd_info_t *NCSCMD(const char *name, console_cmd_func_t func, 92 void *closure) {110 noit_console_state_t *dstate, void *closure) { 93 111 cmd_info_t *cmd; 94 112 cmd = calloc(1, sizeof(*cmd)); 95 113 cmd->name = strdup(name); 96 114 cmd->func = func; 115 cmd->dstate = dstate; 97 116 cmd->closure = closure; 98 117 return cmd; … … 103 122 static noit_console_state_t *_top_level_state = NULL; 104 123 if(!_top_level_state) { 124 static noit_console_state_t *show_state; 105 125 _top_level_state = calloc(1, sizeof(*_top_level_state)); 106 126 noit_console_state_add_cmd(_top_level_state, &console_command_exit); 127 show_state = calloc(1, sizeof(*show_state)); 128 noit_console_state_add_cmd(_top_level_state, 129 NCSCMD("show", noit_console_state_delegate, show_state, NULL)); 107 130 } 108 131 return _top_level_state; … … 121 144 int 122 145 noit_console_state_pop(noit_console_closure_t ncct, int argc, char **argv, 123 void *unused) {146 noit_console_state_t *dstate, void *unused) { 124 147 noit_console_state_stack_t *current; 125 148
