static void free_invalidate_t_list(invalidate_t *i) { if (i->next) free_invalidate_t_list(i->next); free_invalidate_t(i); }
static void free_plugin_state_t(plugin_state_t *pstate) { if (pstate->invalidate_list) free_invalidate_t_list(pstate->invalidate_list); if (pstate->config_file) TSfree(pstate->config_file); if (pstate->log) TSTextLogObjectDestroy(pstate->log); TSfree(pstate); }
static int free_handler(TSCont cont, TSEvent event, void *edata) { invalidate_t *iptr; TSDebug(LOG_PREFIX, "Freeing old config"); iptr = (invalidate_t *)TSContDataGet(cont); free_invalidate_t_list(iptr); TSContDestroy(cont); return 0; }
static int config_handler(TSCont cont, TSEvent event, void *edata) { plugin_state_t *pstate; invalidate_t *i, *iptr; TSCont free_cont; bool updated; TSMutex mutex; mutex = TSContMutexGet(cont); TSMutexLock(mutex); TSDebug(LOG_PREFIX, "In config Handler"); pstate = (plugin_state_t *)TSContDataGet(cont); i = copy_config(pstate->invalidate_list); updated = prune_config(&i); updated = load_config(pstate, &i) || updated; if (updated) { list_config(pstate, i); iptr = __sync_val_compare_and_swap(&(pstate->invalidate_list), pstate->invalidate_list, i); if (iptr) { free_cont = TSContCreate(free_handler, TSMutexCreate()); TSContDataSet(free_cont, (void *)iptr); TSContScheduleOnPool(free_cont, FREE_TMOUT, TS_THREAD_POOL_TASK); } } else { TSDebug(LOG_PREFIX, "No Changes"); if (i) { free_invalidate_t_list(i); } } TSMutexUnlock(mutex); // Don't reschedule for TS_EVENT_MGMT_UPDATE if (event == TS_EVENT_TIMEOUT) { TSContScheduleOnPool(cont, CONFIG_TMOUT, TS_THREAD_POOL_TASK); } return 0; }