diff options
author | Rusty Russell <rusty@rustcorp.com.au> | 2009-11-24 11:16:49 +1030 |
---|---|---|
committer | Rusty Russell <rusty@rustcorp.com.au> | 2009-11-24 11:16:49 +1030 |
commit | 2d9254404dffccd46d0867007f58aa5e182e7649 (patch) | |
tree | 8595d5654550203e8438bfce47a2f7a2a1506b26 /ctdb/server/eventscript.c | |
parent | 2763df22dede72097cb080c46e2e1179615a3ea7 (diff) | |
download | samba-2d9254404dffccd46d0867007f58aa5e182e7649.tar.gz samba-2d9254404dffccd46d0867007f58aa5e182e7649.tar.xz samba-2d9254404dffccd46d0867007f58aa5e182e7649.zip |
eventscript: introduce enum for different event script calls.
Rather than doing strcmp everywhere, pass an explicit enum around. This
also subtly documents what options are available. The "options" arg
is now used for extra arguments only.
Unfortunately, gcc complains on empty format strings, so we make
ctdb_event_script() take no varargs, and add ctdb_event_script_args(). We
leave ctdb_event_script_callback() taking varargs, which means callers
have to do "%s", "".
For the moment, we have CTDB_EVENT_UNKNOWN for handling forced scripts
from the ctdb tool.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
(This used to be ctdb commit 8001488be4f2beb25e943fe01b2afc2e8779930d)
Diffstat (limited to 'ctdb/server/eventscript.c')
-rw-r--r-- | ctdb/server/eventscript.c | 40 |
1 files changed, 31 insertions, 9 deletions
diff --git a/ctdb/server/eventscript.c b/ctdb/server/eventscript.c index 801ff4ecc9..58ec29ba58 100644 --- a/ctdb/server/eventscript.c +++ b/ctdb/server/eventscript.c @@ -32,6 +32,19 @@ static struct { const char *script_running; } child_state; +static const char *call_names[] = { + "startup", + "startrecovery", + "recovered", + "takeip", + "releaseip", + "stopped", + "monitor", + "status", + "shutdown", + "" +}; + static void ctdb_event_script_timeout(struct event_context *ev, struct timed_event *te, struct timeval t, void *p); /* @@ -737,13 +750,14 @@ static int event_script_destructor(struct ctdb_event_script_state *state) static int ctdb_event_script_callback_v(struct ctdb_context *ctdb, void (*callback)(struct ctdb_context *, int, void *), void *private_data, + enum ctdb_eventscript_call call, const char *fmt, va_list ap) { TALLOC_CTX *mem_ctx; struct ctdb_event_script_state *state; int ret; - if (!strcmp(fmt, "monitor") || !strcmp(fmt, "status")) { + if (call == CTDB_EVENT_MONITOR || call == CTDB_EVENT_STATUS) { /* if this was a "monitor" or a status event, we recycle the context to start a new monitor event */ @@ -781,7 +795,9 @@ static int ctdb_event_script_callback_v(struct ctdb_context *ctdb, state->ctdb = ctdb; state->callback = callback; state->private_data = private_data; - state->options = talloc_vasprintf(state, fmt, ap); + state->options = talloc_asprintf(state, "%s ", call_names[call]); + if (state->options) + state->options = talloc_vasprintf_append(discard_const_p(char, state->options), fmt, ap); state->timeout = timeval_set(ctdb->tunable.script_timeout, 0); if (state->options == NULL) { DEBUG(DEBUG_ERR, (__location__ " could not allocate state->options\n")); @@ -847,13 +863,14 @@ int ctdb_event_script_callback(struct ctdb_context *ctdb, TALLOC_CTX *mem_ctx, void (*callback)(struct ctdb_context *, int, void *), void *private_data, + enum ctdb_eventscript_call call, const char *fmt, ...) { va_list ap; int ret; va_start(ap, fmt); - ret = ctdb_event_script_callback_v(ctdb, callback, private_data, fmt, ap); + ret = ctdb_event_script_callback_v(ctdb, callback, private_data, call, fmt, ap); va_end(ap); return ret; @@ -879,20 +896,20 @@ static void event_script_callback(struct ctdb_context *ctdb, int status, void *p run the event script, waiting for it to complete. Used when the caller doesn't want to continue till the event script has finished. */ -int ctdb_event_script(struct ctdb_context *ctdb, const char *fmt, ...) +int ctdb_event_script_args(struct ctdb_context *ctdb, enum ctdb_eventscript_call call, + const char *fmt, ...) { va_list ap; int ret; struct callback_status status; va_start(ap, fmt); - ret = ctdb_event_script_callback_v(ctdb, - event_script_callback, &status, fmt, ap); - va_end(ap); - + ret = ctdb_event_script_callback_v(ctdb, + event_script_callback, &status, call, fmt, ap); if (ret != 0) { return ret; } + va_end(ap); status.status = -1; status.done = false; @@ -902,6 +919,11 @@ int ctdb_event_script(struct ctdb_context *ctdb, const char *fmt, ...) return status.status; } +int ctdb_event_script(struct ctdb_context *ctdb, enum ctdb_eventscript_call call) +{ + /* GCC complains about empty format string, so use %s and "". */ + return ctdb_event_script_args(ctdb, call, "%s", ""); +} struct eventscript_callback_state { struct ctdb_req_control *c; @@ -955,7 +977,7 @@ int32_t ctdb_run_eventscripts(struct ctdb_context *ctdb, ret = ctdb_event_script_callback(ctdb, state, run_eventscripts_callback, state, - "%s", (const char *)indata.dptr); + CTDB_EVENT_UNKNOWN, "%s", (const char *)indata.dptr); if (ret != 0) { ctdb_enable_monitoring(ctdb); |