enum ctdb_eventscript_call call;
const char *options;
struct timeval timeout;
+
+ struct ctdb_monitor_script_status *scripts;
};
char *output;
};
-struct ctdb_monitor_script_status_ctx {
- struct ctdb_monitor_script_status *scripts;
-};
-
/* called from ctdb_logging when we have received output on STDERR from
* one of the eventscripts
*/
{
struct ctdb_monitor_script_status *script;
- if (ctdb->current_monitor_status_ctx == NULL) {
+ if (ctdb->current_monitor == NULL) {
return -1;
}
- script = ctdb->current_monitor_status_ctx->scripts;
+ script = ctdb->current_monitor->scripts;
if (script == NULL) {
return -1;
}
{
DEBUG(DEBUG_INFO, ("event script init called\n"));
- if (ctdb->current_monitor_status_ctx == NULL) {
+ if (ctdb->current_monitor == NULL) {
DEBUG(DEBUG_ERR,(__location__ " current_monitor_status_ctx is NULL when initing script\n"));
return -1;
}
DEBUG(DEBUG_INFO, ("event script start called : %s\n", name));
- if (ctdb->current_monitor_status_ctx == NULL) {
+ if (ctdb->current_monitor == NULL) {
DEBUG(DEBUG_ERR,(__location__ " current_monitor_status_ctx is NULL when starting script\n"));
return -1;
}
- script = talloc_zero(ctdb->current_monitor_status_ctx, struct ctdb_monitor_script_status);
+ script = talloc_zero(ctdb->current_monitor, struct ctdb_monitor_script_status);
if (script == NULL) {
DEBUG(DEBUG_ERR,(__location__ " Failed to talloc ctdb_monitor_script_status for script %s\n", name));
return -1;
}
- script->next = ctdb->current_monitor_status_ctx->scripts;
+ script->next = ctdb->current_monitor->scripts;
script->name = talloc_strdup(script, name);
CTDB_NO_MEMORY(ctdb, script->name);
script->start = timeval_current();
- ctdb->current_monitor_status_ctx->scripts = script;
+ ctdb->current_monitor->scripts = script;
return 0;
}
int32_t res = *((int32_t *)indata.dptr);
struct ctdb_monitor_script_status *script;
- if (ctdb->current_monitor_status_ctx == NULL) {
+ if (ctdb->current_monitor == NULL) {
DEBUG(DEBUG_ERR,(__location__ " current_monitor_status_ctx is NULL when script finished\n"));
return -1;
}
- script = ctdb->current_monitor_status_ctx->scripts;
+ script = ctdb->current_monitor->scripts;
if (script == NULL) {
DEBUG(DEBUG_ERR,(__location__ " script is NULL when the script had finished\n"));
return -1;
{
DEBUG(DEBUG_INFO, ("event script finished called\n"));
- if (ctdb->current_monitor_status_ctx == NULL) {
+ if (ctdb->current_monitor == NULL) {
DEBUG(DEBUG_ERR,(__location__ " script_status is NULL when monitoring event finished\n"));
return -1;
}
}
ctdb->last_status->num_scripts = 0;
- ctdb->last_status = marshall_monitoring_scripts(ctdb, ctdb->last_status, ctdb->current_monitor_status_ctx->scripts);
- ctdb->current_monitor_status_ctx = NULL;
+ ctdb->last_status = marshall_monitoring_scripts(ctdb, ctdb->last_status, ctdb->current_monitor->scripts);
+ talloc_free(ctdb->current_monitor->scripts);
+ ctdb->current_monitor->scripts = NULL;
return 0;
}
if (state->call == CTDB_EVENT_MONITOR || state->call == CTDB_EVENT_STATUS) {
struct ctdb_monitor_script_status *script;
- if (ctdb->current_monitor_status_ctx != NULL) {
- script = ctdb->current_monitor_status_ctx->scripts;
+ if (ctdb->current_monitor != NULL) {
+ script = ctdb->current_monitor->scripts;
if (script != NULL) {
script->status = state->cb_status;
}
}
}
+ /* If we were the current monitor, we no longer are. */
+ if (state->ctdb->current_monitor == state) {
+ state->ctdb->current_monitor = NULL;
+ }
+
/* This is allowed to free us; talloc will prevent double free anyway,
* but beware if you call this outside the destructor! */
if (state->callback) {
state->call = call;
state->options = talloc_vasprintf(state, fmt, ap);
state->timeout = timeval_set(ctdb->tunable.script_timeout, 0);
+ state->scripts = NULL;
if (state->options == NULL) {
DEBUG(DEBUG_ERR, (__location__ " could not allocate state->options\n"));
talloc_free(state);
}
/* Kill off any running monitor events to run this event. */
- talloc_free(ctdb->current_monitor_status_ctx);
- ctdb->current_monitor_status_ctx = NULL;
+ talloc_free(ctdb->current_monitor);
+ ctdb->current_monitor = NULL;
if (!from_user && (call == CTDB_EVENT_MONITOR || call == CTDB_EVENT_STATUS)) {
- /* Allocate script state, and make us a child of it. */
- ctdb->current_monitor_status_ctx = talloc(ctdb, struct ctdb_monitor_script_status_ctx);
- CTDB_NO_MEMORY(ctdb, ctdb->current_monitor_status_ctx);
- ctdb->current_monitor_status_ctx->scripts = NULL;
- talloc_steal(ctdb->current_monitor_status_ctx, state);
+ ctdb->current_monitor = state;
}
DEBUG(DEBUG_INFO,(__location__ " Starting eventscript %s %s\n",