/** * Start the instance of the monitor, returning a handle on the monitor. * * This function creates a thread to execute the actual monitoring. * * @return A handle to use when interacting with the monitor */ static void * startMonitor(void *arg, void* opt) { MONITOR* mon = arg; GALERA_MONITOR *handle = mon->handle; CONFIG_PARAMETER* params = (CONFIG_PARAMETER*) opt; bool have_events = false, script_error = false; if (handle != NULL) { handle->shutdown = 0; } else { if ((handle = (GALERA_MONITOR *) malloc(sizeof(GALERA_MONITOR))) == NULL) { return NULL; } handle->shutdown = 0; handle->id = MONITOR_DEFAULT_ID; handle->disableMasterFailback = 0; handle->availableWhenDonor = 0; handle->disableMasterRoleSetting = 0; handle->master = NULL; handle->script = NULL; handle->use_priority = false; memset(handle->events, false, sizeof(handle->events)); spinlock_init(&handle->lock); } while (params) { if (!strcmp(params->name, "disable_master_failback")) { handle->disableMasterFailback = config_truth_value(params->value); } else if (!strcmp(params->name, "available_when_donor")) { handle->availableWhenDonor = config_truth_value(params->value); } else if (!strcmp(params->name, "disable_master_role_setting")) { handle->disableMasterRoleSetting = config_truth_value(params->value); } else if (!strcmp(params->name, "use_priority")) { handle->use_priority = config_truth_value(params->value); } else if (!strcmp(params->name, "script")) { if (externcmd_can_execute(params->value)) { free(handle->script); handle->script = strdup(params->value); } else { script_error = true; } } else if (!strcmp(params->name, "events")) { if (mon_parse_event_string((bool*) & handle->events, sizeof(handle->events), params->value) != 0) { script_error = true; } else { have_events = true; } } params = params->next; } if (script_error) { MXS_ERROR("Errors were found in the script configuration parameters " "for the monitor '%s'. The script will not be used.", mon->name); free(handle->script); handle->script = NULL; } /** If no specific events are given, enable them all */ if (!have_events) { memset(handle->events, true, sizeof(handle->events)); } handle->tid = (THREAD) thread_start(monitorMain, mon); return handle; }
/** * Start the instance of the monitor, returning a handle on the monitor. * * This function creates a thread to execute the actual monitoring. * * @param arg The current handle - NULL if first start * @return A handle to use when interacting with the monitor */ static void * startMonitor(void *arg,void* opt) { MONITOR* mon = (MONITOR*)arg; MM_MONITOR *handle = mon->handle; CONFIG_PARAMETER* params = (CONFIG_PARAMETER*)opt; bool have_events = false,script_error = false; if (handle) { handle->shutdown = 0; } else { if ((handle = (MM_MONITOR *)malloc(sizeof(MM_MONITOR))) == NULL) return NULL; handle->shutdown = 0; handle->id = MONITOR_DEFAULT_ID; handle->master = NULL; handle->script = NULL; memset(handle->events,false,sizeof(handle->events)); spinlock_init(&handle->lock); } while(params) { if(!strcmp(params->name,"detect_stale_master")) { handle->detectStaleMaster = config_truth_value(params->value); } else if(!strcmp(params->name,"script")) { if(handle->script) { free(handle->script); } if(access(params->value,X_OK) == 0) { handle->script = strdup(params->value); } else { script_error = true; if(access(params->value,F_OK) == 0) { skygw_log_write(LE, "Error: The file cannot be executed: %s", params->value); } else { skygw_log_write(LE, "Error: The file cannot be found: %s", params->value); } handle->script = NULL; } } else if(!strcmp(params->name,"events")) { if(mon_parse_event_string((bool*)&handle->events,sizeof(handle->events),params->value) != 0) script_error = true; else have_events = true; } params = params->next; } if(script_error) { skygw_log_write(LE,"Error: Errors were found in the script configuration parameters " "for the monitor '%s'. The script will not be used.",mon->name); free(handle->script); handle->script = NULL; } /** If no specific events are given, enable them all */ if(!have_events) { memset(handle->events,true,sizeof(handle->events)); } handle->tid = (THREAD)thread_start(monitorMain, mon); return handle; }