mirror of
https://github.com/samba-team/samba.git
synced 2024-12-22 13:34:15 +03:00
eventscript: use -ENOEXEC for disabled status value
This unifies code paths and simplifies things: we just hand -ENOEXEC to ctdb_ctrl_event_script_stop(). Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> (This used to be ctdb commit eadf5e44ef97d7703a7d3bce0e7ea0f21cb11f14)
This commit is contained in:
parent
ce378014c7
commit
b9b75bd065
@ -3722,28 +3722,6 @@ int ctdb_ctrl_event_script_stop(struct ctdb_context *ctdb, int32_t result)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
tell the main daemon a script was disabled
|
||||
*/
|
||||
int ctdb_ctrl_event_script_disabled(struct ctdb_context *ctdb, const char *name)
|
||||
{
|
||||
int ret;
|
||||
int32_t res;
|
||||
TDB_DATA data;
|
||||
|
||||
data.dptr = discard_const(name);
|
||||
data.dsize = strlen(name)+1;
|
||||
|
||||
ret = ctdb_control(ctdb, CTDB_CURRENT_NODE, 0, CTDB_CONTROL_EVENT_SCRIPT_DISABLED, 0, data,
|
||||
ctdb, NULL, &res, NULL, NULL);
|
||||
if (ret != 0 || res != 0) {
|
||||
DEBUG(DEBUG_ERR,("Failed to send event_script_disabeld\n"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
get the status of running the monitor eventscripts
|
||||
*/
|
||||
|
@ -658,7 +658,6 @@ struct ctdb_monitoring_script_wire {
|
||||
char name[MAX_SCRIPT_NAME+1];
|
||||
struct timeval start;
|
||||
struct timeval finished;
|
||||
int32_t disabled;
|
||||
int32_t status;
|
||||
char output[MAX_SCRIPT_OUTPUT+1];
|
||||
};
|
||||
|
@ -618,7 +618,6 @@ enum ctdb_controls {CTDB_CONTROL_PROCESS_EXISTS = 0,
|
||||
CTDB_CONTROL_SET_NATGWSTATE = 103,
|
||||
CTDB_CONTROL_SET_LMASTERROLE = 104,
|
||||
CTDB_CONTROL_SET_RECMASTERROLE = 105,
|
||||
CTDB_CONTROL_EVENT_SCRIPT_DISABLED = 106,
|
||||
CTDB_CONTROL_ENABLE_SCRIPT = 107,
|
||||
CTDB_CONTROL_DISABLE_SCRIPT = 108,
|
||||
CTDB_CONTROL_SET_BAN_STATE = 109,
|
||||
@ -1513,12 +1512,10 @@ int ctdb_ctrl_event_script_init(struct ctdb_context *ctdb);
|
||||
int ctdb_ctrl_event_script_start(struct ctdb_context *ctdb, const char *name);
|
||||
int ctdb_ctrl_event_script_stop(struct ctdb_context *ctdb, int32_t res);
|
||||
int ctdb_ctrl_event_script_finished(struct ctdb_context *ctdb);
|
||||
int ctdb_ctrl_event_script_disabled(struct ctdb_context *ctdb, const char *name);
|
||||
|
||||
int32_t ctdb_control_event_script_init(struct ctdb_context *ctdb);
|
||||
int32_t ctdb_control_event_script_start(struct ctdb_context *ctdb, TDB_DATA indata);
|
||||
int32_t ctdb_control_event_script_stop(struct ctdb_context *ctdb, TDB_DATA indata);
|
||||
int32_t ctdb_control_event_script_disabled(struct ctdb_context *ctdb, TDB_DATA indata);
|
||||
int32_t ctdb_control_event_script_finished(struct ctdb_context *ctdb);
|
||||
|
||||
|
||||
|
@ -447,9 +447,6 @@ static int32_t ctdb_control_dispatch(struct ctdb_context *ctdb,
|
||||
CHECK_CONTROL_DATA_SIZE(0);
|
||||
return ctdb_control_event_script_finished(ctdb);
|
||||
|
||||
case CTDB_CONTROL_EVENT_SCRIPT_DISABLED:
|
||||
return ctdb_control_event_script_disabled(ctdb, indata);
|
||||
|
||||
case CTDB_CONTROL_GET_EVENT_SCRIPT_STATUS:
|
||||
CHECK_CONTROL_DATA_SIZE(0);
|
||||
return ctdb_control_get_event_script_status(ctdb, outdata);
|
||||
|
@ -90,7 +90,6 @@ struct ctdb_monitor_script_status {
|
||||
const char *name;
|
||||
struct timeval start;
|
||||
struct timeval finished;
|
||||
int32_t disabled;
|
||||
int32_t status;
|
||||
char *output;
|
||||
};
|
||||
@ -197,33 +196,6 @@ int32_t ctdb_control_event_script_stop(struct ctdb_context *ctdb, TDB_DATA indat
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* called from the event script child process when we have a disabled script
|
||||
*/
|
||||
int32_t ctdb_control_event_script_disabled(struct ctdb_context *ctdb, TDB_DATA indata)
|
||||
{
|
||||
const char *name = (const char *)indata.dptr;
|
||||
struct ctdb_monitor_script_status *script;
|
||||
|
||||
DEBUG(DEBUG_INFO, ("event script disabed called for script %s\n", name));
|
||||
|
||||
if (ctdb->current_monitor_status_ctx == NULL) {
|
||||
DEBUG(DEBUG_ERR,(__location__ " current_monitor_status_ctx is NULL when script finished\n"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
script = ctdb->current_monitor_status_ctx->scripts;
|
||||
if (script == NULL) {
|
||||
DEBUG(DEBUG_ERR,(__location__ " script is NULL when the script had finished\n"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
script->finished = timeval_current();
|
||||
script->status = 0;
|
||||
script->disabled = 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct ctdb_monitoring_wire *marshall_monitoring_scripts(TALLOC_CTX *mem_ctx, struct ctdb_monitoring_wire *monitoring_scripts, struct ctdb_monitor_script_status *script)
|
||||
{
|
||||
struct ctdb_monitoring_script_wire script_wire;
|
||||
@ -241,7 +213,6 @@ static struct ctdb_monitoring_wire *marshall_monitoring_scripts(TALLOC_CTX *mem_
|
||||
strncpy(script_wire.name, script->name, MAX_SCRIPT_NAME);
|
||||
script_wire.start = script->start;
|
||||
script_wire.finished = script->finished;
|
||||
script_wire.disabled = script->disabled;
|
||||
script_wire.status = script->status;
|
||||
if (script->output != NULL) {
|
||||
strncpy(script_wire.output, script->output, MAX_SCRIPT_OUTPUT);
|
||||
@ -568,7 +539,7 @@ static int ctdb_run_event_script(struct ctdb_context *ctdb,
|
||||
}
|
||||
|
||||
if (!current->is_enabled) {
|
||||
if (ctdb_ctrl_event_script_disabled(ctdb, current->name) != 0) {
|
||||
if (ctdb_ctrl_event_script_stop(ctdb, -ENOEXEC) != 0) {
|
||||
DEBUG(DEBUG_ERR,(__location__ " Failed to report disabled eventscript\n"));
|
||||
talloc_free(tmp_ctx);
|
||||
return -1;
|
||||
|
@ -743,15 +743,13 @@ static int control_scriptstatus(struct ctdb_context *ctdb, int argc, const char
|
||||
printf("%d scripts were executed last monitoring cycle\n", script_status->num_scripts);
|
||||
for (i=0; i<script_status->num_scripts; i++) {
|
||||
const char *status;
|
||||
if (script_status->scripts[i].disabled) {
|
||||
printf("%-20s Status:DISABLED\n",
|
||||
script_status->scripts[i].name);
|
||||
continue;
|
||||
}
|
||||
switch (script_status->scripts[i].status) {
|
||||
case -ETIME:
|
||||
status = "TIMEDOUT";
|
||||
break;
|
||||
case -ENOEXEC:
|
||||
status = "DISABLED";
|
||||
break;
|
||||
case 0:
|
||||
status = "OK";
|
||||
break;
|
||||
@ -766,8 +764,10 @@ static int control_scriptstatus(struct ctdb_context *ctdb, int argc, const char
|
||||
timeval_delta(&script_status->scripts[i].finished,
|
||||
&script_status->scripts[i].start));
|
||||
}
|
||||
printf("%s",
|
||||
ctime(&script_status->scripts[i].start.tv_sec));
|
||||
if (script_status->scripts[i].status != -ENOEXEC) {
|
||||
printf("%s",
|
||||
ctime(&script_status->scripts[i].start.tv_sec));
|
||||
}
|
||||
if (script_status->scripts[i].status != 0) {
|
||||
printf(" OUTPUT:%s\n",
|
||||
script_status->scripts[i].output);
|
||||
|
Loading…
Reference in New Issue
Block a user