memcpy(current->output + slen, str, min);
}
-/* called when all event script child processes are done */
-static int32_t ctdb_control_event_script_finished(struct ctdb_context *ctdb,
- struct ctdb_event_script_state *state)
-{
- DEBUG(DEBUG_INFO, ("event script finished called\n"));
-
- talloc_free(ctdb->last_status[state->call]);
- ctdb->last_status[state->call] = talloc_steal(ctdb, state->scripts);
- /* if we didn't finish all the scripts, trim status array. */
- if (state->current < ctdb->last_status[state->call]->num_scripts) {
- ctdb->last_status[state->call]->num_scripts = state->current+1;
- }
- state->scripts = NULL;
-
- return 0;
-}
-
int32_t ctdb_control_get_event_script_status(struct ctdb_context *ctdb, TDB_DATA *outdata)
{
struct ctdb_scripts_wire *monitoring_scripts = ctdb->last_status[CTDB_EVENT_MONITOR];
DEBUG(DEBUG_INFO,(__location__ " Eventscript %s %s finished with state %d\n",
call_names[state->call], state->options, state->cb_status));
- ctdb_control_event_script_finished(ctdb, state);
ctdb->event_script_timeouts = 0;
talloc_free(state);
return;
state->current++;
state->cb_status = fork_child_for_script(ctdb, state);
if (state->cb_status != 0) {
- ctdb_control_event_script_finished(ctdb, state);
/* This calls the callback. */
talloc_free(state);
}
}
state->scripts->scripts[state->current].status = state->cb_status;
- ctdb_control_event_script_finished(ctdb, state);
talloc_free(state);
}
state->ctdb->current_monitor = NULL;
}
+ /* Save our status as the last executed status. */
+ talloc_free(state->ctdb->last_status[state->call]);
+ state->ctdb->last_status[state->call] = state->scripts;
+ if (state->current < state->ctdb->last_status[state->call]->num_scripts) {
+ state->ctdb->last_status[state->call]->num_scripts = state->current+1;
+ }
+
/* This is allowed to free us; talloc will prevent double free anyway,
* but beware if you call this outside the destructor! */
if (state->callback) {
DEBUG(DEBUG_INFO,(__location__ " Starting eventscript %s %s\n",
call_names[state->call], state->options));
- state->scripts = ctdb_get_script_list(ctdb, state);
+ /* This is not a child of state, since we save it in destructor. */
+ state->scripts = ctdb_get_script_list(ctdb, ctdb);
if (state->scripts == NULL) {
talloc_free(state);
return -1;
/* Nothing to do? */
if (state->scripts->num_scripts == 0) {
- ctdb_control_event_script_finished(ctdb, state);
ctdb->event_script_timeouts = 0;
talloc_free(state);
return 0;
ret = fork_child_for_script(ctdb, state);
if (ret != 0) {
+ talloc_free(state->scripts);
talloc_free(state);
return -1;
}