diff options
author | Rusty Russell <rusty@rustcorp.com.au> | 2009-11-24 11:24:22 +1030 |
---|---|---|
committer | Rusty Russell <rusty@rustcorp.com.au> | 2009-11-24 11:24:22 +1030 |
commit | ff59bb34af7fdc0049ddc37e21856c628f4ab47e (patch) | |
tree | 67afc90ef0ac3fc850cedab04ee5edcb2a227949 /ctdb/server/eventscript.c | |
parent | 187efa08aba97a3cc3d203f25f5a117ac55717ec (diff) | |
download | samba-ff59bb34af7fdc0049ddc37e21856c628f4ab47e.tar.gz samba-ff59bb34af7fdc0049ddc37e21856c628f4ab47e.tar.xz samba-ff59bb34af7fdc0049ddc37e21856c628f4ab47e.zip |
eventscript: check that ctdb forced script events correct
Now we're doing checking, we might as well make sure the commands from
"ctdb eventscripts" are valid.
This gets rid of the "UNKNOWN" event type.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
(This used to be ctdb commit 66b22980b14601f29fe8cc64bd8f29883c7ca1c0)
Diffstat (limited to 'ctdb/server/eventscript.c')
-rw-r--r-- | ctdb/server/eventscript.c | 39 |
1 files changed, 34 insertions, 5 deletions
diff --git a/ctdb/server/eventscript.c b/ctdb/server/eventscript.c index 8814858f26..24e08f0cf5 100644 --- a/ctdb/server/eventscript.c +++ b/ctdb/server/eventscript.c @@ -42,7 +42,6 @@ static const char *call_names[] = { "monitor", "status", "shutdown", - "" }; static void ctdb_event_script_timeout(struct event_context *ev, struct timed_event *te, struct timeval t, void *p); @@ -774,9 +773,6 @@ static bool check_options(enum ctdb_eventscript_call call, const char *options) case CTDB_EVENT_RELEASE_IP: return count_words(options) == 3; - case CTDB_EVENT_UNKNOWN: - return true; - default: DEBUG(DEBUG_ERR,(__location__ "Unknown ctdb_eventscript_call %u\n", call)); return false; @@ -999,6 +995,30 @@ static void run_eventscripts_callback(struct ctdb_context *ctdb, int status, } +static const char *get_call(const char *p, enum ctdb_eventscript_call *call) +{ + unsigned int len; + + /* Skip any initial whitespace. */ + p += strspn(p, " \t"); + + /* See if we match any. */ + for (*call = 0; *call < ARRAY_SIZE(call_names); (*call)++) { + len = strlen(call_names[*call]); + if (strncmp(p, call_names[*call], len) == 0) { + /* If that's it, we're good. */ + if (*p == '\0') + return p; + /* Otherwise, if whitespace is next, good. */ + len = strspn(p, " \t"); + if (len) + return p + len; + /* Hmm, extra chars: keep looking. */ + } + } + return NULL; +} + /* A control to force running of the eventscripts from the ctdb client tool */ @@ -1008,6 +1028,15 @@ int32_t ctdb_run_eventscripts(struct ctdb_context *ctdb, { int ret; struct eventscript_callback_state *state; + const char *options; + enum ctdb_eventscript_call call; + + /* Figure out what call they want. */ + options = get_call((const char *)indata.dptr, &call); + if (!options) { + DEBUG(DEBUG_ERR, (__location__ " Invalid forced \"%s\"\n", (const char *)indata.dptr)); + return -1; + } if (ctdb->recovery_mode != CTDB_RECOVERY_NORMAL) { DEBUG(DEBUG_ERR, (__location__ " Aborted running eventscript \"%s\" while in RECOVERY mode\n", indata.dptr)); @@ -1025,7 +1054,7 @@ int32_t ctdb_run_eventscripts(struct ctdb_context *ctdb, ret = ctdb_event_script_callback(ctdb, state, run_eventscripts_callback, state, - CTDB_EVENT_UNKNOWN, "%s", (const char *)indata.dptr); + call, "%s", options); if (ret != 0) { ctdb_enable_monitoring(ctdb); |