4 Copyright (C) Andrew Tridgell 2007
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, see <http://www.gnu.org/licenses/>.
22 #include "system/filesys.h"
23 #include "system/wait.h"
24 #include "system/dir.h"
25 #include "system/locale.h"
26 #include "../include/ctdb_private.h"
27 #include "lib/events/events.h"
28 #include "../common/rb_tree.h"
32 const char *script_running;
35 static void ctdb_event_script_timeout(struct event_context *ev, struct timed_event *te, struct timeval t, void *p);
38 ctdbd sends us a SIGTERM when we should time out the current script
40 static void sigterm(int sig)
42 char tbuf[100], buf[200];
45 DEBUG(DEBUG_ERR,("Timed out running script '%s' after %.1f seconds pid :%d\n",
46 child_state.script_running, timeval_elapsed(&child_state.start), getpid()));
50 strftime(tbuf, sizeof(tbuf)-1, "%Y%m%d%H%M%S", localtime(&t));
51 sprintf(buf, "{ pstree -p; cat /proc/locks; ls -li /var/ctdb/ /var/ctdb/persistent; }"
52 " >/tmp/ctdb.event.%s.%d", tbuf, getpid());
55 DEBUG(DEBUG_ERR,("Logged timedout eventscript : %s\n", buf));
57 /* all the child processes will be running in the same process group */
58 kill(-getpgrp(), SIGKILL);
62 struct ctdb_event_script_state {
63 struct ctdb_context *ctdb;
65 /* Warning: this can free us! */
66 void (*callback)(struct ctdb_context *, int, void *);
71 enum ctdb_eventscript_call call;
73 struct timeval timeout;
76 struct ctdb_scripts_wire *scripts;
79 static struct ctdb_script_wire *get_current_script(struct ctdb_event_script_state *state)
81 return &state->scripts->scripts[state->current];
84 /* called from ctdb_logging when we have received output on STDERR from
85 * one of the eventscripts
87 static void log_event_script_output(const char *str, uint16_t len, void *p)
89 struct ctdb_event_script_state *state
90 = talloc_get_type(p, struct ctdb_event_script_state);
91 struct ctdb_script_wire *current = get_current_script(state);
92 unsigned int slen, min;
94 /* Append, but don't overfill buffer. It starts zero-filled. */
95 slen = strlen(current->output);
96 min = MIN(len, sizeof(current->output) - slen - 1);
98 memcpy(current->output + slen, str, min);
101 int32_t ctdb_control_get_event_script_status(struct ctdb_context *ctdb,
105 if (call_type >= CTDB_EVENT_MAX) {
109 if (ctdb->last_status[call_type] == NULL) {
110 /* If it's never been run, return nothing so they can tell. */
113 outdata->dsize = talloc_get_size(ctdb->last_status[call_type]);
114 outdata->dptr = (uint8_t *)ctdb->last_status[call_type];
119 struct ctdb_script_tree_item {
124 /* Return true if OK, otherwise set errno. */
125 static bool check_executable(const char *dir, const char *name)
130 full = talloc_asprintf(NULL, "%s/%s", dir, name);
134 if (stat(full, &st) != 0) {
135 DEBUG(DEBUG_ERR,("Could not stat event script %s: %s\n",
136 full, strerror(errno)));
141 if (!(st.st_mode & S_IXUSR)) {
142 DEBUG(DEBUG_INFO,("Event script %s is not executable. Ignoring this event script\n", full));
152 static struct ctdb_scripts_wire *ctdb_get_script_list(struct ctdb_context *ctdb, TALLOC_CTX *mem_ctx)
158 struct ctdb_scripts_wire *scripts;
159 TALLOC_CTX *tmp_ctx = talloc_new(ctdb);
160 struct ctdb_script_tree_item *tree_item;
164 the service specific event scripts
166 if (stat(ctdb->event_script_dir, &st) != 0 &&
168 DEBUG(DEBUG_CRIT,("No event script directory found at '%s'\n", ctdb->event_script_dir));
169 talloc_free(tmp_ctx);
173 /* create a tree to store all the script names in */
174 tree = trbt_create(tmp_ctx, 0);
176 /* scan all directory entries and insert all valid scripts into the
179 dir = opendir(ctdb->event_script_dir);
181 DEBUG(DEBUG_CRIT,("Failed to open event script directory '%s'\n", ctdb->event_script_dir));
182 talloc_free(tmp_ctx);
187 while ((de=readdir(dir)) != NULL) {
191 namlen = strlen(de->d_name);
197 if (de->d_name[namlen-1] == '~') {
198 /* skip files emacs left behind */
202 if (de->d_name[2] != '.') {
206 if (sscanf(de->d_name, "%02u.", &num) != 1) {
210 if (strlen(de->d_name) > MAX_SCRIPT_NAME) {
211 DEBUG(DEBUG_ERR,("Script name %s too long! %u chars max",
212 de->d_name, MAX_SCRIPT_NAME));
216 tree_item = talloc(tree, struct ctdb_script_tree_item);
217 if (tree_item == NULL) {
218 DEBUG(DEBUG_ERR, (__location__ " Failed to allocate new tree item\n"));
219 talloc_free(tmp_ctx);
223 tree_item->error = 0;
224 if (!check_executable(ctdb->event_script_dir, de->d_name)) {
225 tree_item->error = errno;
228 tree_item->name = talloc_strdup(tree_item, de->d_name);
229 if (tree_item->name == NULL) {
230 DEBUG(DEBUG_ERR,(__location__ " Failed to allocate script name.\n"));
231 talloc_free(tmp_ctx);
235 /* store the event script in the tree */
236 trbt_insert32(tree, (num<<16)|count++, tree_item);
240 /* Overallocates by one, but that's OK */
241 scripts = talloc_zero_size(tmp_ctx,
243 + sizeof(scripts->scripts[0]) * count);
244 if (scripts == NULL) {
245 DEBUG(DEBUG_ERR, (__location__ " Failed to allocate scripts\n"));
246 talloc_free(tmp_ctx);
249 scripts->num_scripts = count;
251 for (count = 0; count < scripts->num_scripts; count++) {
252 tree_item = trbt_findfirstarray32(tree, 1);
254 strcpy(scripts->scripts[count].name, tree_item->name);
255 scripts->scripts[count].status = -tree_item->error;
257 /* remove this script from the tree */
258 talloc_free(tree_item);
261 talloc_steal(mem_ctx, scripts);
262 talloc_free(tmp_ctx);
266 static int child_setup(struct ctdb_context *ctdb)
268 if (setpgid(0,0) != 0) {
270 DEBUG(DEBUG_ERR,("Failed to create process group for event scripts - %s\n",
275 signal(SIGTERM, sigterm);
279 static char *child_command_string(struct ctdb_context *ctdb,
282 const char *scriptname,
283 enum ctdb_eventscript_call call,
286 const char *str = from_user ? "CTDB_CALLED_BY_USER=1 " : "";
288 /* Allow a setting where we run the actual monitor event
289 from an external source and replace it with
290 a "status" event that just picks up the actual
291 status of the event asynchronously.
293 if ((ctdb->tunable.use_status_events_for_monitoring != 0)
294 && (call == CTDB_EVENT_MONITOR)
296 return talloc_asprintf(ctx, "%s%s/%s %s",
298 ctdb->event_script_dir,
299 scriptname, "status");
301 return talloc_asprintf(ctx, "%s%s/%s %s %s",
303 ctdb->event_script_dir,
305 ctdb_eventscript_call_names[call],
310 static int child_run_one(struct ctdb_context *ctdb,
311 const char *scriptname, const char *cmdstr)
315 ret = system(cmdstr);
316 /* if the system() call was successful, translate ret into the
317 return code from the command
320 ret = WEXITSTATUS(ret);
325 /* 127 could mean it does not exist, 126 non-executable. */
326 if (ret == 127 || ret == 126) {
328 if (!check_executable(ctdb->event_script_dir, scriptname)) {
329 DEBUG(DEBUG_ERR,("Script %s returned status %u. Someone just deleted it?\n",
338 Actually run one event script
339 this function is called and run in the context of a forked child
340 which allows it to do blocking calls such as system()
342 static int child_run_script(struct ctdb_context *ctdb,
344 enum ctdb_eventscript_call call,
346 struct ctdb_script_wire *current)
350 TALLOC_CTX *tmp_ctx = talloc_new(ctdb);
352 child_state.start = timeval_current();
353 ret = child_setup(ctdb);
357 cmdstr = child_command_string(ctdb, tmp_ctx, from_user,
358 current->name, call, options);
359 CTDB_NO_MEMORY(ctdb, cmdstr);
360 child_state.script_running = cmdstr;
362 DEBUG(DEBUG_INFO,("Executing event script %s\n",cmdstr));
364 if (current->status) {
365 ret = current->status;
369 ret = child_run_one(ctdb, current->name, cmdstr);
371 talloc_free(tmp_ctx);
375 static void ctdb_event_script_handler(struct event_context *ev, struct fd_event *fde,
376 uint16_t flags, void *p);
378 static int fork_child_for_script(struct ctdb_context *ctdb,
379 struct ctdb_event_script_state *state)
382 struct ctdb_script_wire *current = get_current_script(state);
384 current->start = timeval_current();
388 DEBUG(DEBUG_ERR, (__location__ " pipe failed for child eventscript process\n"));
392 if (!ctdb_fork_with_logging(state, ctdb, log_event_script_output,
393 state, &state->child)) {
400 /* If we are the child, do the work. */
401 if (state->child == 0) {
405 set_close_on_exec(state->fd[1]);
407 rt = child_run_script(ctdb, state->from_user, state->call, state->options, current);
408 /* We must be able to write PIPEBUF bytes at least; if this
409 somehow fails, the read above will be short. */
410 write(state->fd[1], &rt, sizeof(rt));
416 set_close_on_exec(state->fd[0]);
418 DEBUG(DEBUG_DEBUG, (__location__ " Created PIPE FD:%d to child eventscript process\n", state->fd[0]));
420 /* Set ourselves up to be called when that's done. */
421 event_add_fd(ctdb->ev, state, state->fd[0], EVENT_FD_READ|EVENT_FD_AUTOCLOSE,
422 ctdb_event_script_handler, state);
426 /* called when child is finished */
427 static void ctdb_event_script_handler(struct event_context *ev, struct fd_event *fde,
428 uint16_t flags, void *p)
430 struct ctdb_event_script_state *state =
431 talloc_get_type(p, struct ctdb_event_script_state);
432 struct ctdb_script_wire *current = get_current_script(state);
433 struct ctdb_context *ctdb = state->ctdb;
436 r = read(state->fd[0], ¤t->status, sizeof(current->status));
438 current->status = -errno;
439 } else if (r != sizeof(current->status)) {
440 current->status = -EIO;
443 current->finished = timeval_current();
445 /* update overall status based on this script. */
446 state->cb_status = current->status;
448 /* don't stop just because it vanished or was disabled. */
449 if (current->status == -ENOENT || current->status == -ENOEXEC) {
450 state->cb_status = 0;
453 /* valgrind gets overloaded if we run next script as it's still doing
454 * post-execution analysis, so kill finished child here. */
455 if (ctdb->valgrinding) {
456 kill(state->child, SIGKILL);
461 /* Aborted or finished all scripts? We're done. */
462 if (state->cb_status != 0 || state->current+1 == state->scripts->num_scripts) {
463 DEBUG(DEBUG_INFO,(__location__ " Eventscript %s %s finished with state %d\n",
464 ctdb_eventscript_call_names[state->call], state->options, state->cb_status));
466 ctdb->event_script_timeouts = 0;
471 /* Forget about that old fd. */
476 state->cb_status = fork_child_for_script(ctdb, state);
477 if (state->cb_status != 0) {
478 /* This calls the callback. */
483 /* called when child times out */
484 static void ctdb_event_script_timeout(struct event_context *ev, struct timed_event *te,
485 struct timeval t, void *p)
487 struct ctdb_event_script_state *state = talloc_get_type(p, struct ctdb_event_script_state);
488 struct ctdb_context *ctdb = state->ctdb;
490 DEBUG(DEBUG_ERR,("Event script timed out : %s %s count : %u pid : %d\n",
491 ctdb_eventscript_call_names[state->call], state->options, ctdb->event_script_timeouts, state->child));
493 state->cb_status = -ETIME;
495 if (kill(state->child, 0) != 0) {
496 DEBUG(DEBUG_ERR,("Event script child process already dead, errno %s(%d)\n", strerror(errno), errno));
500 state->scripts->scripts[state->current].status = state->cb_status;
506 destroy an event script: kill it if ->child != 0.
508 static int event_script_destructor(struct ctdb_event_script_state *state)
511 DEBUG(DEBUG_ERR,(__location__ " Sending SIGTERM to child pid:%d\n", state->child));
513 if (kill(state->child, SIGTERM) != 0) {
514 DEBUG(DEBUG_ERR,("Failed to kill child process for eventscript, errno %s(%d)\n", strerror(errno), errno));
518 /* If we were the current monitor, we no longer are. */
519 if (state->ctdb->current_monitor == state) {
520 state->ctdb->current_monitor = NULL;
523 /* Save our scripts as the last executed status, if we have them. */
524 if (state->scripts) {
525 talloc_free(state->ctdb->last_status[state->call]);
526 state->ctdb->last_status[state->call] = state->scripts;
527 if (state->current < state->ctdb->last_status[state->call]->num_scripts) {
528 state->ctdb->last_status[state->call]->num_scripts = state->current+1;
532 /* This is allowed to free us; talloc will prevent double free anyway,
533 * but beware if you call this outside the destructor! */
534 if (state->callback) {
535 state->callback(state->ctdb, state->cb_status, state->private_data);
541 static unsigned int count_words(const char *options)
543 unsigned int words = 0;
545 options += strspn(options, " \t");
548 options += strcspn(options, " \t");
549 options += strspn(options, " \t");
554 static bool check_options(enum ctdb_eventscript_call call, const char *options)
557 /* These all take no arguments. */
558 case CTDB_EVENT_STARTUP:
559 case CTDB_EVENT_START_RECOVERY:
560 case CTDB_EVENT_RECOVERED:
561 case CTDB_EVENT_STOPPED:
562 case CTDB_EVENT_MONITOR:
563 case CTDB_EVENT_STATUS:
564 case CTDB_EVENT_SHUTDOWN:
565 case CTDB_EVENT_RELOAD:
566 return count_words(options) == 0;
568 case CTDB_EVENT_TAKE_IP: /* interface, IP address, netmask bits. */
569 case CTDB_EVENT_RELEASE_IP:
570 return count_words(options) == 3;
573 DEBUG(DEBUG_ERR,(__location__ "Unknown ctdb_eventscript_call %u\n", call));
579 run the event script in the background, calling the callback when
582 static int ctdb_event_script_callback_v(struct ctdb_context *ctdb,
583 void (*callback)(struct ctdb_context *, int, void *),
586 enum ctdb_eventscript_call call,
587 const char *fmt, va_list ap)
589 struct ctdb_event_script_state *state;
592 state = talloc(ctdb->event_script_ctx, struct ctdb_event_script_state);
593 CTDB_NO_MEMORY(ctdb, state);
596 state->callback = callback;
597 state->private_data = private_data;
598 state->from_user = from_user;
600 state->options = talloc_vasprintf(state, fmt, ap);
601 state->timeout = timeval_set(ctdb->tunable.script_timeout, 0);
602 state->scripts = NULL;
603 if (state->options == NULL) {
604 DEBUG(DEBUG_ERR, (__location__ " could not allocate state->options\n"));
608 if (!check_options(state->call, state->options)) {
609 DEBUG(DEBUG_ERR, ("Bad eventscript options '%s' for %s\n",
610 ctdb_eventscript_call_names[state->call], state->options));
615 if (ctdb->recovery_mode != CTDB_RECOVERY_NORMAL) {
616 /* we guarantee that only some specifically allowed event scripts are run
618 const enum ctdb_eventscript_call allowed_calls[] = {
619 CTDB_EVENT_START_RECOVERY, CTDB_EVENT_SHUTDOWN, CTDB_EVENT_RELEASE_IP, CTDB_EVENT_STOPPED };
621 for (i=0;i<ARRAY_SIZE(allowed_calls);i++) {
622 if (call == allowed_calls[i]) break;
624 if (i == ARRAY_SIZE(allowed_calls)) {
625 DEBUG(DEBUG_ERR,("Refusing to run event scripts call '%s' while in recovery\n",
626 ctdb_eventscript_call_names[call]));
632 /* Kill off any running monitor events to run this event. */
633 if (ctdb->current_monitor) {
634 /* Discard script status so we don't save to last_status */
635 talloc_free(ctdb->current_monitor->scripts);
636 ctdb->current_monitor->scripts = NULL;
637 talloc_free(ctdb->current_monitor);
638 ctdb->current_monitor = NULL;
641 if (!from_user && (call == CTDB_EVENT_MONITOR || call == CTDB_EVENT_STATUS)) {
642 ctdb->current_monitor = state;
645 DEBUG(DEBUG_INFO,(__location__ " Starting eventscript %s %s\n",
646 ctdb_eventscript_call_names[state->call],
649 /* This is not a child of state, since we save it in destructor. */
650 state->scripts = ctdb_get_script_list(ctdb, ctdb);
651 if (state->scripts == NULL) {
658 if (state->scripts->num_scripts == 0) {
659 ctdb->event_script_timeouts = 0;
664 ret = fork_child_for_script(ctdb, state);
666 talloc_free(state->scripts);
671 talloc_set_destructor(state, event_script_destructor);
672 if (!timeval_is_zero(&state->timeout)) {
673 event_add_timed(ctdb->ev, state, timeval_current_ofs(state->timeout.tv_sec, state->timeout.tv_usec), ctdb_event_script_timeout, state);
675 DEBUG(DEBUG_ERR, (__location__ " eventscript %s %s called with no timeout\n",
676 ctdb_eventscript_call_names[state->call],
685 run the event script in the background, calling the callback when
688 int ctdb_event_script_callback(struct ctdb_context *ctdb,
690 void (*callback)(struct ctdb_context *, int, void *),
693 enum ctdb_eventscript_call call,
694 const char *fmt, ...)
700 ret = ctdb_event_script_callback_v(ctdb, callback, private_data, from_user, call, fmt, ap);
707 struct callback_status {
713 called when ctdb_event_script() finishes
715 static void event_script_callback(struct ctdb_context *ctdb, int status, void *private_data)
717 struct callback_status *s = (struct callback_status *)private_data;
723 run the event script, waiting for it to complete. Used when the caller
724 doesn't want to continue till the event script has finished.
726 int ctdb_event_script_args(struct ctdb_context *ctdb, enum ctdb_eventscript_call call,
727 const char *fmt, ...)
731 struct callback_status status;
734 ret = ctdb_event_script_callback_v(ctdb,
735 event_script_callback, &status, false, call, fmt, ap);
744 while (status.done == false && event_loop_once(ctdb->ev) == 0) /* noop */;
746 if (status.status == -ETIME) {
747 DEBUG(DEBUG_ERR, (__location__ " eventscript for '%s' timedout."
748 " Immediately banning ourself for %d seconds\n",
749 ctdb_eventscript_call_names[call],
750 ctdb->tunable.recovery_ban_period));
754 return status.status;
757 int ctdb_event_script(struct ctdb_context *ctdb, enum ctdb_eventscript_call call)
759 /* GCC complains about empty format string, so use %s and "". */
760 return ctdb_event_script_args(ctdb, call, "%s", "");
763 struct eventscript_callback_state {
764 struct ctdb_req_control *c;
768 called when a forced eventscript run has finished
770 static void run_eventscripts_callback(struct ctdb_context *ctdb, int status,
773 struct eventscript_callback_state *state =
774 talloc_get_type(private_data, struct eventscript_callback_state);
776 ctdb_enable_monitoring(ctdb);
779 DEBUG(DEBUG_ERR,(__location__ " Failed to forcibly run eventscripts\n"));
782 ctdb_request_control_reply(ctdb, state->c, NULL, status, NULL);
783 /* This will free the struct ctdb_event_script_state we are in! */
789 /* Returns rest of string, or NULL if no match. */
790 static const char *get_call(const char *p, enum ctdb_eventscript_call *call)
794 /* Skip any initial whitespace. */
795 p += strspn(p, " \t");
797 /* See if we match any. */
798 for (*call = 0; *call < CTDB_EVENT_MAX; (*call)++) {
799 len = strlen(ctdb_eventscript_call_names[*call]);
800 if (strncmp(p, ctdb_eventscript_call_names[*call], len) == 0) {
801 /* If end of string or whitespace, we're done. */
802 if (strcspn(p + len, " \t") == 0) {
811 A control to force running of the eventscripts from the ctdb client tool
813 int32_t ctdb_run_eventscripts(struct ctdb_context *ctdb,
814 struct ctdb_req_control *c,
815 TDB_DATA indata, bool *async_reply)
818 struct eventscript_callback_state *state;
820 enum ctdb_eventscript_call call;
822 /* Figure out what call they want. */
823 options = get_call((const char *)indata.dptr, &call);
825 DEBUG(DEBUG_ERR, (__location__ " Invalid forced \"%s\"\n", (const char *)indata.dptr));
829 if (ctdb->recovery_mode != CTDB_RECOVERY_NORMAL) {
830 DEBUG(DEBUG_ERR, (__location__ " Aborted running eventscript \"%s\" while in RECOVERY mode\n", indata.dptr));
834 state = talloc(ctdb->event_script_ctx, struct eventscript_callback_state);
835 CTDB_NO_MEMORY(ctdb, state);
837 state->c = talloc_steal(state, c);
839 DEBUG(DEBUG_NOTICE,("Forced running of eventscripts with arguments %s\n", indata.dptr));
841 ctdb_disable_monitoring(ctdb);
843 ret = ctdb_event_script_callback(ctdb,
844 state, run_eventscripts_callback, state,
845 true, call, "%s", options);
848 ctdb_enable_monitoring(ctdb);
849 DEBUG(DEBUG_ERR,(__location__ " Failed to run eventscripts with arguments %s\n", indata.dptr));
854 /* tell ctdb_control.c that we will be replying asynchronously */
862 int32_t ctdb_control_enable_script(struct ctdb_context *ctdb, TDB_DATA indata)
867 TALLOC_CTX *tmp_ctx = talloc_new(ctdb);
869 script = (char *)indata.dptr;
870 if (indata.dsize == 0) {
871 DEBUG(DEBUG_ERR,(__location__ " No script specified.\n"));
872 talloc_free(tmp_ctx);
875 if (indata.dptr[indata.dsize - 1] != '\0') {
876 DEBUG(DEBUG_ERR,(__location__ " String is not null terminated.\n"));
877 talloc_free(tmp_ctx);
880 if (index(script,'/') != NULL) {
881 DEBUG(DEBUG_ERR,(__location__ " Script name contains '/'. Failed to enable script %s\n", script));
882 talloc_free(tmp_ctx);
887 if (stat(ctdb->event_script_dir, &st) != 0 &&
889 DEBUG(DEBUG_CRIT,("No event script directory found at '%s'\n", ctdb->event_script_dir));
890 talloc_free(tmp_ctx);
895 filename = talloc_asprintf(tmp_ctx, "%s/%s", ctdb->event_script_dir, script);
896 if (filename == NULL) {
897 DEBUG(DEBUG_ERR,(__location__ " Failed to create script path\n"));
898 talloc_free(tmp_ctx);
902 if (stat(filename, &st) != 0) {
903 DEBUG(DEBUG_ERR,("Could not stat event script %s. Failed to enable script.\n", filename));
904 talloc_free(tmp_ctx);
908 if (chmod(filename, st.st_mode | S_IXUSR) == -1) {
909 DEBUG(DEBUG_ERR,("Could not chmod %s. Failed to enable script.\n", filename));
910 talloc_free(tmp_ctx);
914 talloc_free(tmp_ctx);
918 int32_t ctdb_control_disable_script(struct ctdb_context *ctdb, TDB_DATA indata)
923 TALLOC_CTX *tmp_ctx = talloc_new(ctdb);
925 script = (char *)indata.dptr;
926 if (indata.dsize == 0) {
927 DEBUG(DEBUG_ERR,(__location__ " No script specified.\n"));
928 talloc_free(tmp_ctx);
931 if (indata.dptr[indata.dsize - 1] != '\0') {
932 DEBUG(DEBUG_ERR,(__location__ " String is not null terminated.\n"));
933 talloc_free(tmp_ctx);
936 if (index(script,'/') != NULL) {
937 DEBUG(DEBUG_ERR,(__location__ " Script name contains '/'. Failed to disable script %s\n", script));
938 talloc_free(tmp_ctx);
943 if (stat(ctdb->event_script_dir, &st) != 0 &&
945 DEBUG(DEBUG_CRIT,("No event script directory found at '%s'\n", ctdb->event_script_dir));
946 talloc_free(tmp_ctx);
951 filename = talloc_asprintf(tmp_ctx, "%s/%s", ctdb->event_script_dir, script);
952 if (filename == NULL) {
953 DEBUG(DEBUG_ERR,(__location__ " Failed to create script path\n"));
954 talloc_free(tmp_ctx);
958 if (stat(filename, &st) != 0) {
959 DEBUG(DEBUG_ERR,("Could not stat event script %s. Failed to disable script.\n", filename));
960 talloc_free(tmp_ctx);
964 if (chmod(filename, st.st_mode & ~(S_IXUSR|S_IXGRP|S_IXOTH)) == -1) {
965 DEBUG(DEBUG_ERR,("Could not chmod %s. Failed to disable script.\n", filename));
966 talloc_free(tmp_ctx);
970 talloc_free(tmp_ctx);