summaryrefslogtreecommitdiffstats
path: root/ctdb/server/eventscript.c
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2008-05-14 20:57:04 +1000
committerAndrew Tridgell <tridge@samba.org>2008-05-14 20:57:04 +1000
commite465110f9503552fab1cf22640dee4a719b39707 (patch)
treef9d78a8dfb85b4eb3f8b30e05ab9d2b6fd3f54df /ctdb/server/eventscript.c
parent510fb39b9bb5759cdf93a4c44a6dbf56d3f72279 (diff)
downloadsamba-e465110f9503552fab1cf22640dee4a719b39707.tar.gz
samba-e465110f9503552fab1cf22640dee4a719b39707.tar.xz
samba-e465110f9503552fab1cf22640dee4a719b39707.zip
Fix the chicken and egg problem with ctdb/samba and a registry smb.conf
This attempts to fix the problem of ctdb event scripts blocking due to attempted access to the ctdb databases during recovery. The changes are: - now only the 'shutdown' and 'startrecovery' events can be called with the databases locked in recovery. The event scripts must ensure that for these two events no database access is attempted - the recovered, takeip and releaseip events could previously be called inside a recovery. The code now ensures that this doesn't happen, delaying the events till after recovery has finished - the 50.samba event script now avoids using testparm unless it is really needed This needs extensive testing. (This used to be ctdb commit e3cdb8f2be6a44ec877efcd75c7297edb008a80b)
Diffstat (limited to 'ctdb/server/eventscript.c')
-rw-r--r--ctdb/server/eventscript.c24
1 files changed, 18 insertions, 6 deletions
diff --git a/ctdb/server/eventscript.c b/ctdb/server/eventscript.c
index f6afd47800..f8a5077d47 100644
--- a/ctdb/server/eventscript.c
+++ b/ctdb/server/eventscript.c
@@ -52,7 +52,6 @@ static int ctdb_event_script_v(struct ctdb_context *ctdb, const char *fmt, va_li
{
char *options, *cmdstr;
int ret;
- va_list ap2;
struct stat st;
TALLOC_CTX *tmp_ctx = talloc_new(ctdb);
trbt_tree_t *tree;
@@ -60,6 +59,24 @@ static int ctdb_event_script_v(struct ctdb_context *ctdb, const char *fmt, va_li
struct dirent *de;
char *script;
+ options = talloc_vasprintf(tmp_ctx, fmt, ap);
+ CTDB_NO_MEMORY(ctdb, options);
+
+ if (ctdb->recovery_mode != CTDB_RECOVERY_NORMAL) {
+ /* we guarantee that only some specifically allowed event scripts are run
+ while in recovery */
+ const char *allowed_scripts[] = {"startrecovery", "shutdown" };
+ int i;
+ for (i=0;i<ARRAY_SIZE(allowed_scripts);i++) {
+ if (strcmp(options, allowed_scripts[i]) == 0) break;
+ }
+ if (i == ARRAY_SIZE(allowed_scripts)) {
+ DEBUG(0,("Refusing to run event scripts with option '%s' while in recovery\n",
+ options));
+ }
+ return -1;
+ }
+
if (setpgid(0,0) != 0) {
DEBUG(DEBUG_ERR,("Failed to create process group for event scripts - %s\n",
strerror(errno)));
@@ -146,11 +163,6 @@ static int ctdb_event_script_v(struct ctdb_context *ctdb, const char *fmt, va_li
them
*/
while ((script=trbt_findfirstarray32(tree, 1)) != NULL) {
- va_copy(ap2, ap);
- options = talloc_vasprintf(tmp_ctx, fmt, ap2);
- va_end(ap2);
- CTDB_NO_MEMORY(ctdb, options);
-
cmdstr = talloc_asprintf(tmp_ctx, "%s/%s %s",
ctdb->event_script_dir,
script, options);