1
0
mirror of https://github.com/samba-team/samba.git synced 2025-03-23 06:50:21 +03:00

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 1d24a3869fe89fc9a109fd9e9b69df5fc665a5f6)
This commit is contained in:
Rusty Russell 2009-11-25 11:02:29 +10:30
parent 0b4b83aea0
commit 3188df4a88
2 changed files with 31 additions and 7 deletions

View File

@ -868,8 +868,7 @@ enum ctdb_eventscript_call {
CTDB_EVENT_STOPPED, /* This node is stopped: no args. */
CTDB_EVENT_MONITOR, /* Please check if service is healthy: no args. */
CTDB_EVENT_STATUS, /* Report service status: no args. */
CTDB_EVENT_SHUTDOWN, /* CTDB shutting down: no args. */
CTDB_EVENT_UNKNOWN, /* Other: manually invoked from "ctdb eventscript". */
CTDB_EVENT_SHUTDOWN /* CTDB shutting down: no args. */
};
/* internal prototypes */

View File

@ -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;
@ -997,6 +993,26 @@ static void run_eventscripts_callback(struct ctdb_context *ctdb, int status,
return;
}
/* Returns rest of string, or NULL if no match. */
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 end of string or whitespace, we're done. */
if (strcspn(p + len, " \t") == 0) {
return p + len;
}
}
}
return NULL;
}
/*
A control to force running of the eventscripts from the ctdb client tool
@ -1007,6 +1023,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));
@ -1024,7 +1049,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);