summaryrefslogtreecommitdiffstats
path: root/ctdb/server/eventscript.c
diff options
context:
space:
mode:
authorRusty Russell <rusty@rustcorp.com.au>2009-12-07 23:12:19 +1030
committerRusty Russell <rusty@rustcorp.com.au>2009-12-07 23:12:19 +1030
commitc70afe0cd4933f89700d1aaa8aa202783e3c0984 (patch)
tree9ce9436ec2f7da2d550b69ab5614f6289815e432 /ctdb/server/eventscript.c
parentb9b75bd065e67ef1ee941323b7dfb48e51fee66e (diff)
downloadsamba-c70afe0cd4933f89700d1aaa8aa202783e3c0984.tar.gz
samba-c70afe0cd4933f89700d1aaa8aa202783e3c0984.tar.xz
samba-c70afe0cd4933f89700d1aaa8aa202783e3c0984.zip
eventscript: handle and report generic stat/execution errors
Rather than ignoring deleted event scripts (or pretending that they were "OK"), and discarding other stat errors, we save the errno and turn it into a negative status. This gives us a bit more information if we can't execute a script (eg. too many symlinks or other weird errors). Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> (This used to be ctdb commit 5d894e1ae5228df6bbe4fc305ccba19803fa3798)
Diffstat (limited to 'ctdb/server/eventscript.c')
-rw-r--r--ctdb/server/eventscript.c35
1 files changed, 21 insertions, 14 deletions
diff --git a/ctdb/server/eventscript.c b/ctdb/server/eventscript.c
index 57fbd85768..5f46b38ada 100644
--- a/ctdb/server/eventscript.c
+++ b/ctdb/server/eventscript.c
@@ -275,13 +275,13 @@ int32_t ctdb_control_get_event_script_status(struct ctdb_context *ctdb, TDB_DATA
struct ctdb_script_tree_item {
const char *name;
- int32_t is_enabled;
+ int error;
};
struct ctdb_script_list {
struct ctdb_script_list *next;
const char *name;
- int32_t is_enabled;
+ int error;
};
/* Return true if OK, otherwise set errno. */
@@ -377,12 +377,9 @@ static struct ctdb_script_list *ctdb_get_script_list(struct ctdb_context *ctdb,
return NULL;
}
- tree_item->is_enabled = 1;
+ tree_item->error = 0;
if (!check_executable(ctdb->event_script_dir, de->d_name)) {
- if (errno != ENOEXEC) {
- continue;
- }
- tree_item->is_enabled = 0;
+ tree_item->error = errno;
}
tree_item->name = talloc_strdup(tree_item, de->d_name);
@@ -415,7 +412,7 @@ static struct ctdb_script_list *ctdb_get_script_list(struct ctdb_context *ctdb,
new_item->next = NULL;
new_item->name = talloc_steal(new_item, tree_item->name);
- new_item->is_enabled = tree_item->is_enabled;
+ new_item->error = tree_item->error;
if (head == NULL) {
head = new_item;
@@ -538,17 +535,16 @@ static int ctdb_run_event_script(struct ctdb_context *ctdb,
return -1;
}
- if (!current->is_enabled) {
- if (ctdb_ctrl_event_script_stop(ctdb, -ENOEXEC) != 0) {
+ 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;
}
}
-
}
- if (!current->is_enabled) {
+ if (current->error) {
continue;
}
@@ -558,13 +554,18 @@ static int ctdb_run_event_script(struct ctdb_context *ctdb,
*/
if (ret != -1) {
ret = WEXITSTATUS(ret);
+ } else {
+ ret = -errno;
}
+
+ /* 127 could mean it does not exist, 126 non-executable. */
if (ret == 127 || ret == 126) {
/* Re-check it... */
if (!check_executable(ctdb->event_script_dir,
current->name)) {
- ret = 0;
- DEBUG(DEBUG_ERR,("Script %s returned status 127. Someone just deleted it?\n", cmdstr));
+ DEBUG(DEBUG_ERR,("Script %s returned status %u. Someone just deleted it?\n",
+ cmdstr, ret));
+ ret = -errno;
}
}
@@ -576,6 +577,12 @@ static int ctdb_run_event_script(struct ctdb_context *ctdb,
}
}
+ /* now we've reported the per-script error, don't exit the loop
+ * just because it vanished or was disabled. */
+ if (ret == -ENOENT || ret == -ENOEXEC) {
+ ret = 0;
+ }
+
/* return an error if the script failed */
if (ret != 0) {
DEBUG(DEBUG_ERR,("Event script %s failed with error %d\n", cmdstr, ret));