diff options
author | Rusty Russell <rusty@rustcorp.com.au> | 2009-12-07 23:15:56 +1030 |
---|---|---|
committer | Rusty Russell <rusty@rustcorp.com.au> | 2009-12-07 23:15:56 +1030 |
commit | d5d88ecaaf1a759d5b92383f29a87af952abe27b (patch) | |
tree | d41f08bed295f37068c4c86869f1b233649fe962 /ctdb/server/eventscript.c | |
parent | 672e06f438f0b718415eb3069af50f478a71a841 (diff) | |
download | samba-d5d88ecaaf1a759d5b92383f29a87af952abe27b.tar.gz samba-d5d88ecaaf1a759d5b92383f29a87af952abe27b.tar.xz samba-d5d88ecaaf1a759d5b92383f29a87af952abe27b.zip |
eventscript: replace other -1 returns with -errno
This completes our "problem with script" reporting; we never set cb_status
to -1 on error. Real errnos are used where the failure is a system call
(eg. read, setpgid), otherwise -EIO is used if we couldn't communicate with
the parent.
The latter case is a bit useless, since the parent probably won't see
the error anyway, but it's neater.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
(This used to be ctdb commit 1269458547795c90d544371332ba1de68df29548)
Diffstat (limited to 'ctdb/server/eventscript.c')
-rw-r--r-- | ctdb/server/eventscript.c | 42 |
1 files changed, 20 insertions, 22 deletions
diff --git a/ctdb/server/eventscript.c b/ctdb/server/eventscript.c index bd42ed6d52..940b49ec7b 100644 --- a/ctdb/server/eventscript.c +++ b/ctdb/server/eventscript.c @@ -460,9 +460,8 @@ static int ctdb_run_event_script(struct ctdb_context *ctdb, } if (ctdb_ctrl_event_script_init(ctdb) != 0) { - DEBUG(DEBUG_ERR,(__location__ " Failed to init event script monitoring\n")); - talloc_free(tmp_ctx); - return -1; + ret = -EIO; + goto out; } } @@ -478,16 +477,16 @@ static int ctdb_run_event_script(struct ctdb_context *ctdb, if (i == ARRAY_SIZE(allowed_calls)) { DEBUG(DEBUG_ERR,("Refusing to run event scripts call '%s' while in recovery\n", call_names[call])); - talloc_free(tmp_ctx); - return -1; + ret = -EBUSY; + goto out; } } if (setpgid(0,0) != 0) { + ret = -errno; DEBUG(DEBUG_ERR,("Failed to create process group for event scripts - %s\n", strerror(errno))); - talloc_free(tmp_ctx); - return -1; + goto out; } signal(SIGTERM, sigterm); @@ -530,16 +529,14 @@ static int ctdb_run_event_script(struct ctdb_context *ctdb, if (!from_user && call == CTDB_EVENT_MONITOR) { if (ctdb_ctrl_event_script_start(ctdb, current->name) != 0) { - DEBUG(DEBUG_ERR,(__location__ " Failed to start event script monitoring\n")); - talloc_free(tmp_ctx); - return -1; + ret = -EIO; + goto out; } if (current->error) { if (ctdb_ctrl_event_script_stop(ctdb, -current->error) != 0) { - DEBUG(DEBUG_ERR,(__location__ " Failed to report disabled eventscript\n")); - talloc_free(tmp_ctx); - return -1; + ret = -EIO; + goto out; } } } @@ -571,9 +568,8 @@ static int ctdb_run_event_script(struct ctdb_context *ctdb, if (!from_user && call == CTDB_EVENT_MONITOR) { if (ctdb_ctrl_event_script_stop(ctdb, ret) != 0) { - DEBUG(DEBUG_ERR,(__location__ " Failed to stop event script monitoring\n")); - talloc_free(tmp_ctx); - return -1; + ret = -EIO; + goto out; } } @@ -594,12 +590,11 @@ static int ctdb_run_event_script(struct ctdb_context *ctdb, if (!from_user && call == CTDB_EVENT_MONITOR) { if (ctdb_ctrl_event_script_finished(ctdb) != 0) { - DEBUG(DEBUG_ERR,(__location__ " Failed to finish event script monitoring\n")); - talloc_free(tmp_ctx); - return -1; + ret = -EIO; } } +out: talloc_free(tmp_ctx); return ret; } @@ -611,10 +606,13 @@ static void ctdb_event_script_handler(struct event_context *ev, struct fd_event struct ctdb_event_script_state *state = talloc_get_type(p, struct ctdb_event_script_state); struct ctdb_context *ctdb = state->ctdb; + int r; - if (read(state->fd[0], &state->cb_status, sizeof(state->cb_status)) != - sizeof(state->cb_status)) { - state->cb_status = -2; + r = read(state->fd[0], &state->cb_status, sizeof(state->cb_status)); + if (r < 0) { + state->cb_status = -errno; + } else if (r != sizeof(state->cb_status)) { + state->cb_status = -EIO; } DEBUG(DEBUG_INFO,(__location__ " Eventscript %s %s finished with state %d\n", |