void do_config(void) { int n; if (debug > 0) printf("got configuration connection\n"); if (cbu == cbs) { char *tmp; tmp = realloc(cb, cbs + 8192); if (tmp == NULL) { if (debug > 0) perror("malloc()"); free(cb); cb = NULL; cbs = 0; goto configdone; } cbs += 8192; cb = tmp; } n = read(conffd, cb + cbu, cbs - cbu); if (debug > 0) printf("read %d config bytes\n", n); if (n == 0) { parse_configs(); goto configdone; } else if (n == -1) { if (debug > 0) perror("read()"); goto configdone; } else cbu += n; return; configdone: cbu = 0; close(conffd); conffd = -1; }
/* Initialize the plugin / global continuation hook */ void TSPluginInit(int argc, const char *argv[]) { TSPluginRegistrationInfo info; if (2 != argc) { TSError("Must specify a configuration file.\n"); return; } info.plugin_name = "health_checks"; info.vendor_name = "Apache Software Foundation"; info.support_email = "*****@*****.**"; if (TS_SUCCESS != TSPluginRegister(TS_SDK_VERSION_3_0, &info)) { TSError("Plugin registration failed. \n"); return; } if (!check_ts_version()) { TSError("Plugin requires Traffic Server 3.0 or later\n"); return; } /* This will update the global configuration file, and is not reloaded at run time */ /* ToDo: Support reloading with traffic_line -x ? */ if (NULL == (g_config = parse_configs(argv[1]))) { TSError("Unable to read / parse %s config file", argv[1]); return; } /* Setup the background thread */ if (!TSThreadCreate(hc_thread, NULL)) { TSError("Failure in thread creation"); return; } /* Create a continuation with a mutex as there is a shared global structure containing the headers to add */ TSDebug(PLUGIN_NAME, "Started %s plugin", PLUGIN_NAME); TSHttpHookAdd(TS_HTTP_READ_REQUEST_HDR_HOOK, TSContCreate(health_check_origin, NULL)); }
int main(int argc, char *argv[]) { const char *cmdline; struct menu *m; int rows, cols; int i; (void)argc; parse_configs(argv + 1); /* * We don't start the console until we have parsed the configuration * file, since the configuration file might impact the console * configuration, e.g. MENU RESOLUTION. */ start_console(); if (getscreensize(1, &rows, &cols)) { /* Unknown screen size? */ rows = 24; cols = 80; } /* Some postprocessing for all menus */ for (m = menu_list; m; m = m->next) { if (!m->mparm[P_WIDTH]) m->mparm[P_WIDTH] = cols; /* If anyone has specified negative parameters, consider them relative to the bottom row of the screen. */ for (i = 0; i < NPARAMS; i++) if (m->mparm[i] < 0) m->mparm[i] = max(m->mparm[i] + rows, 0); } cm = start_menu; if (!cm->nentries) { fputs("Initial menu has no LABEL entries!\n", stdout); return 1; /* Error! */ } for (;;) { local_cursor_enable(true); cmdline = run_menu(); if (clearmenu) clear_screen(); local_cursor_enable(false); printf("\033[?25h\033[%d;1H\033[0m", END_ROW); if (cmdline) { uint32_t type = parse_image_type(cmdline); execute(cmdline, type, false); if (cm->onerror) { type = parse_image_type(cm->onerror); execute(cm->onerror, type, true); } } else { return 0; /* Exit */ } } }