+ state = talloc(ctdb->event_script_ctx, struct ctdb_event_script_state);
+ CTDB_NO_MEMORY(ctdb, state);
+
+ /* The callback isn't done if the context is freed. */
+ state->callback = talloc(mem_ctx, struct event_script_callback);
+ CTDB_NO_MEMORY(ctdb, state->callback);
+ DLIST_ADD(ctdb->script_callbacks, state->callback);
+ talloc_set_destructor(state->callback, remove_callback);
+ state->callback->ctdb = ctdb;
+ state->callback->fn = callback;
+ state->callback->private_data = private_data;
+
+ state->ctdb = ctdb;
+ state->from_user = from_user;
+ 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);
+ return -1;
+ }
+ if (!check_options(state->call, state->options)) {
+ DEBUG(DEBUG_ERR, ("Bad eventscript options '%s' for %s\n",
+ ctdb_eventscript_call_names[state->call], state->options));
+ talloc_free(state);
+ return -1;
+ }
+