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 const char *call_names[] = {
48 static void ctdb_event_script_timeout(struct event_context *ev, struct timed_event *te, struct timeval t, void *p);
51 ctdbd sends us a SIGTERM when we should time out the current script
53 static void sigterm(int sig)
55 char tbuf[100], buf[200];
58 DEBUG(DEBUG_ERR,("Timed out running script '%s' after %.1f seconds pid :%d\n",
59 child_state.script_running, timeval_elapsed(&child_state.start), getpid()));
63 strftime(tbuf, sizeof(tbuf)-1, "%Y%m%d%H%M%S", localtime(&t));
64 sprintf(buf, "pstree -p >/tmp/ctdb.event.%s.%d", tbuf, getpid());
67 DEBUG(DEBUG_ERR,("Logged timedout eventscript : %s\n", buf));
69 /* all the child processes will be running in the same process group */
70 kill(-getpgrp(), SIGKILL);
74 struct ctdb_event_script_state {
75 struct ctdb_context *ctdb;
77 /* Warning: this can free us! */
78 void (*callback)(struct ctdb_context *, int, void *);
83 enum ctdb_eventscript_call call;
85 struct timeval timeout;
88 struct ctdb_scripts_wire *scripts;
91 static struct ctdb_script_wire *get_current_script(struct ctdb_event_script_state *state)
93 return &state->scripts->scripts[state->current];
96 /* called from ctdb_logging when we have received output on STDERR from
97 * one of the eventscripts
99 static void log_event_script_output(const char *str, uint16_t len, void *p)
101 struct ctdb_event_script_state *state
102 = talloc_get_type(p, struct ctdb_event_script_state);
103 struct ctdb_script_wire *current = get_current_script(state);
104 unsigned int slen, min;
106 /* Append, but don't overfill buffer. It starts zero-filled. */
107 slen = strlen(current->output);
108 min = MIN(len, sizeof(current->output) - slen - 1);
110 memcpy(current->output + slen, str, min);
113 /* called when all event script child processes are done */
114 static int32_t ctdb_control_event_script_finished(struct ctdb_context *ctdb,
115 struct ctdb_event_script_state *state)
117 DEBUG(DEBUG_INFO, ("event script finished called\n"));
119 talloc_free(ctdb->last_status);
120 ctdb->last_status = talloc_steal(ctdb, state->scripts);
121 /* if we didn't finish all the scripts, trim status array. */
122 if (state->current < ctdb->last_status->num_scripts) {
123 ctdb->last_status->num_scripts = state->current+1;
125 state->scripts = NULL;
130 int32_t ctdb_control_get_event_script_status(struct ctdb_context *ctdb, TDB_DATA *outdata)
132 struct ctdb_scripts_wire *monitoring_scripts = ctdb->last_status;
134 if (monitoring_scripts == NULL) {
135 DEBUG(DEBUG_ERR,(__location__ " last_monitor_status_ctx is NULL when reading status\n"));
139 outdata->dsize = talloc_get_size(monitoring_scripts);
140 outdata->dptr = (uint8_t *)monitoring_scripts;
145 struct ctdb_script_tree_item {
150 /* Return true if OK, otherwise set errno. */
151 static bool check_executable(const char *dir, const char *name)
156 full = talloc_asprintf(NULL, "%s/%s", dir, name);
160 if (stat(full, &st) != 0) {
161 DEBUG(DEBUG_ERR,("Could not stat event script %s: %s\n",
162 full, strerror(errno)));
167 if (!(st.st_mode & S_IXUSR)) {
168 DEBUG(DEBUG_INFO,("Event script %s is not executable. Ignoring this event script\n", full));
178 static struct ctdb_scripts_wire *ctdb_get_script_list(struct ctdb_context *ctdb, TALLOC_CTX *mem_ctx)
184 struct ctdb_scripts_wire *scripts;
185 TALLOC_CTX *tmp_ctx = talloc_new(ctdb);
186 struct ctdb_script_tree_item *tree_item;
190 the service specific event scripts
192 if (stat(ctdb->event_script_dir, &st) != 0 &&
194 DEBUG(DEBUG_CRIT,("No event script directory found at '%s'\n", ctdb->event_script_dir));
195 talloc_free(tmp_ctx);
199 /* create a tree to store all the script names in */
200 tree = trbt_create(tmp_ctx, 0);
202 /* scan all directory entries and insert all valid scripts into the
205 dir = opendir(ctdb->event_script_dir);
207 DEBUG(DEBUG_CRIT,("Failed to open event script directory '%s'\n", ctdb->event_script_dir));
208 talloc_free(tmp_ctx);
213 while ((de=readdir(dir)) != NULL) {
217 namlen = strlen(de->d_name);
223 if (de->d_name[namlen-1] == '~') {
224 /* skip files emacs left behind */
228 if (de->d_name[2] != '.') {
232 if (sscanf(de->d_name, "%02u.", &num) != 1) {
236 if (strlen(de->d_name) > MAX_SCRIPT_NAME) {
237 DEBUG(DEBUG_ERR,("Script name %s too long! %u chars max",
238 de->d_name, MAX_SCRIPT_NAME));
242 tree_item = talloc(tree, struct ctdb_script_tree_item);
243 if (tree_item == NULL) {
244 DEBUG(DEBUG_ERR, (__location__ " Failed to allocate new tree item\n"));
245 talloc_free(tmp_ctx);
249 tree_item->error = 0;
250 if (!check_executable(ctdb->event_script_dir, de->d_name)) {
251 tree_item->error = errno;
254 tree_item->name = talloc_strdup(tree_item, de->d_name);
255 if (tree_item->name == NULL) {
256 DEBUG(DEBUG_ERR,(__location__ " Failed to allocate script name.\n"));
257 talloc_free(tmp_ctx);
261 /* store the event script in the tree */
262 trbt_insert32(tree, (num<<16)|count++, tree_item);
266 /* Overallocates by one, but that's OK */
267 scripts = talloc_zero_size(tmp_ctx,
269 + sizeof(scripts->scripts[0]) * count);
270 if (scripts == NULL) {
271 DEBUG(DEBUG_ERR, (__location__ " Failed to allocate scripts\n"));
272 talloc_free(tmp_ctx);
275 scripts->num_scripts = count;
277 for (count = 0; count < scripts->num_scripts; count++) {
278 tree_item = trbt_findfirstarray32(tree, 1);
280 strcpy(scripts->scripts[count].name, tree_item->name);
281 scripts->scripts[count].status = -tree_item->error;
283 /* remove this script from the tree */
284 talloc_free(tree_item);
287 talloc_steal(mem_ctx, scripts);
288 talloc_free(tmp_ctx);
292 static int child_setup(struct ctdb_context *ctdb)
294 if (setpgid(0,0) != 0) {
296 DEBUG(DEBUG_ERR,("Failed to create process group for event scripts - %s\n",
301 signal(SIGTERM, sigterm);
305 static char *child_command_string(struct ctdb_context *ctdb,
308 const char *scriptname,
309 enum ctdb_eventscript_call call,
312 const char *str = from_user ? "CTDB_CALLED_BY_USER=1 " : "";
314 /* Allow a setting where we run the actual monitor event
315 from an external source and replace it with
316 a "status" event that just picks up the actual
317 status of the event asynchronously.
319 if ((ctdb->tunable.use_status_events_for_monitoring != 0)
320 && (call == CTDB_EVENT_MONITOR)
322 return talloc_asprintf(ctx, "%s%s/%s %s",
324 ctdb->event_script_dir,
325 scriptname, "status");
327 return talloc_asprintf(ctx, "%s%s/%s %s %s",
329 ctdb->event_script_dir,
330 scriptname, call_names[call], options);
334 static int child_run_one(struct ctdb_context *ctdb,
335 const char *scriptname, const char *cmdstr)
339 ret = system(cmdstr);
340 /* if the system() call was successful, translate ret into the
341 return code from the command
344 ret = WEXITSTATUS(ret);
349 /* 127 could mean it does not exist, 126 non-executable. */
350 if (ret == 127 || ret == 126) {
352 if (!check_executable(ctdb->event_script_dir, scriptname)) {
353 DEBUG(DEBUG_ERR,("Script %s returned status %u. Someone just deleted it?\n",
362 Actually run one event script
363 this function is called and run in the context of a forked child
364 which allows it to do blocking calls such as system()
366 static int child_run_script(struct ctdb_context *ctdb,
368 enum ctdb_eventscript_call call,
370 struct ctdb_script_wire *current)
374 TALLOC_CTX *tmp_ctx = talloc_new(ctdb);
376 child_state.start = timeval_current();
377 ret = child_setup(ctdb);
381 cmdstr = child_command_string(ctdb, tmp_ctx, from_user,
382 current->name, call, options);
383 CTDB_NO_MEMORY(ctdb, cmdstr);
384 child_state.script_running = cmdstr;
386 DEBUG(DEBUG_INFO,("Executing event script %s\n",cmdstr));
388 if (current->status) {
389 ret = current->status;
393 ret = child_run_one(ctdb, current->name, cmdstr);
395 talloc_free(tmp_ctx);
399 static void ctdb_event_script_handler(struct event_context *ev, struct fd_event *fde,
400 uint16_t flags, void *p);
402 static int fork_child_for_script(struct ctdb_context *ctdb,
403 struct ctdb_event_script_state *state)
406 struct ctdb_script_wire *current = get_current_script(state);
408 current->start = timeval_current();
412 DEBUG(DEBUG_ERR, (__location__ " pipe failed for child eventscript process\n"));
416 if (!ctdb_fork_with_logging(state, ctdb, log_event_script_output,
417 state, &state->child)) {
424 /* If we are the child, do the work. */
425 if (state->child == 0) {
429 set_close_on_exec(state->fd[1]);
431 rt = child_run_script(ctdb, state->from_user, state->call, state->options, current);
432 /* We must be able to write PIPEBUF bytes at least; if this
433 somehow fails, the read above will be short. */
434 write(state->fd[1], &rt, sizeof(rt));
440 set_close_on_exec(state->fd[0]);
442 DEBUG(DEBUG_DEBUG, (__location__ " Created PIPE FD:%d to child eventscript process\n", state->fd[0]));
444 /* Set ourselves up to be called when that's done. */
445 event_add_fd(ctdb->ev, state, state->fd[0], EVENT_FD_READ|EVENT_FD_AUTOCLOSE,
446 ctdb_event_script_handler, state);
450 /* called when child is finished */
451 static void ctdb_event_script_handler(struct event_context *ev, struct fd_event *fde,
452 uint16_t flags, void *p)
454 struct ctdb_event_script_state *state =
455 talloc_get_type(p, struct ctdb_event_script_state);
456 struct ctdb_script_wire *current = get_current_script(state);
457 struct ctdb_context *ctdb = state->ctdb;
460 r = read(state->fd[0], ¤t->status, sizeof(current->status));
462 current->status = -errno;
463 } else if (r != sizeof(current->status)) {
464 current->status = -EIO;
467 current->finished = timeval_current();
469 /* update overall status based on this script. */
470 state->cb_status = current->status;
472 /* don't stop just because it vanished or was disabled. */
473 if (current->status == -ENOENT || current->status == -ENOEXEC) {
474 state->cb_status = 0;
479 /* Aborted or finished all scripts? We're done. */
480 if (state->cb_status != 0 || state->current+1 == state->scripts->num_scripts) {
481 DEBUG(DEBUG_INFO,(__location__ " Eventscript %s %s finished with state %d\n",
482 call_names[state->call], state->options, state->cb_status));
484 if (!state->from_user && state->call == CTDB_EVENT_MONITOR) {
485 ctdb_control_event_script_finished(ctdb, state);
487 ctdb->event_script_timeouts = 0;
492 /* Forget about that old fd. */
497 state->cb_status = fork_child_for_script(ctdb, state);
498 if (state->cb_status != 0) {
499 if (!state->from_user && state->call == CTDB_EVENT_MONITOR) {
500 ctdb_control_event_script_finished(ctdb, state);
502 /* This calls the callback. */
507 /* called when child times out */
508 static void ctdb_event_script_timeout(struct event_context *ev, struct timed_event *te,
509 struct timeval t, void *p)
511 struct ctdb_event_script_state *state = talloc_get_type(p, struct ctdb_event_script_state);
512 struct ctdb_context *ctdb = state->ctdb;
514 DEBUG(DEBUG_ERR,("Event script timed out : %s %s count : %u pid : %d\n",
515 call_names[state->call], state->options, ctdb->event_script_timeouts, state->child));
517 state->cb_status = -ETIME;
519 if (kill(state->child, 0) != 0) {
520 DEBUG(DEBUG_ERR,("Event script child process already dead, errno %s(%d)\n", strerror(errno), errno));
524 if (state->call == CTDB_EVENT_MONITOR || state->call == CTDB_EVENT_STATUS) {
525 state->scripts->scripts[state->current].status = state->cb_status;
526 ctdb_control_event_script_finished(ctdb, state);
533 destroy an event script: kill it if ->child != 0.
535 static int event_script_destructor(struct ctdb_event_script_state *state)
538 DEBUG(DEBUG_ERR,(__location__ " Sending SIGTERM to child pid:%d\n", state->child));
540 if (kill(state->child, SIGTERM) != 0) {
541 DEBUG(DEBUG_ERR,("Failed to kill child process for eventscript, errno %s(%d)\n", strerror(errno), errno));
545 /* If we were the current monitor, we no longer are. */
546 if (state->ctdb->current_monitor == state) {
547 state->ctdb->current_monitor = NULL;
550 /* This is allowed to free us; talloc will prevent double free anyway,
551 * but beware if you call this outside the destructor! */
552 if (state->callback) {
553 state->callback(state->ctdb, state->cb_status, state->private_data);
559 static unsigned int count_words(const char *options)
561 unsigned int words = 0;
563 options += strspn(options, " \t");
566 options += strcspn(options, " \t");
567 options += strspn(options, " \t");
572 static bool check_options(enum ctdb_eventscript_call call, const char *options)
575 /* These all take no arguments. */
576 case CTDB_EVENT_STARTUP:
577 case CTDB_EVENT_START_RECOVERY:
578 case CTDB_EVENT_RECOVERED:
579 case CTDB_EVENT_STOPPED:
580 case CTDB_EVENT_MONITOR:
581 case CTDB_EVENT_STATUS:
582 case CTDB_EVENT_SHUTDOWN:
583 case CTDB_EVENT_RELOAD:
584 return count_words(options) == 0;
586 case CTDB_EVENT_TAKE_IP: /* interface, IP address, netmask bits. */
587 case CTDB_EVENT_RELEASE_IP:
588 return count_words(options) == 3;
591 DEBUG(DEBUG_ERR,(__location__ "Unknown ctdb_eventscript_call %u\n", call));
597 run the event script in the background, calling the callback when
600 static int ctdb_event_script_callback_v(struct ctdb_context *ctdb,
601 void (*callback)(struct ctdb_context *, int, void *),
604 enum ctdb_eventscript_call call,
605 const char *fmt, va_list ap)
607 struct ctdb_event_script_state *state;
610 state = talloc(ctdb->event_script_ctx, struct ctdb_event_script_state);
611 CTDB_NO_MEMORY(ctdb, state);
614 state->callback = callback;
615 state->private_data = private_data;
616 state->from_user = from_user;
618 state->options = talloc_vasprintf(state, fmt, ap);
619 state->timeout = timeval_set(ctdb->tunable.script_timeout, 0);
620 state->scripts = NULL;
621 if (state->options == NULL) {
622 DEBUG(DEBUG_ERR, (__location__ " could not allocate state->options\n"));
626 if (!check_options(state->call, state->options)) {
627 DEBUG(DEBUG_ERR, ("Bad eventscript options '%s' for %s\n",
628 call_names[state->call], state->options));
633 if (ctdb->recovery_mode != CTDB_RECOVERY_NORMAL) {
634 /* we guarantee that only some specifically allowed event scripts are run
636 const enum ctdb_eventscript_call allowed_calls[] = {
637 CTDB_EVENT_START_RECOVERY, CTDB_EVENT_SHUTDOWN, CTDB_EVENT_RELEASE_IP, CTDB_EVENT_STOPPED };
639 for (i=0;i<ARRAY_SIZE(allowed_calls);i++) {
640 if (call == allowed_calls[i]) break;
642 if (i == ARRAY_SIZE(allowed_calls)) {
643 DEBUG(DEBUG_ERR,("Refusing to run event scripts call '%s' while in recovery\n",
650 /* Kill off any running monitor events to run this event. */
651 talloc_free(ctdb->current_monitor);
652 ctdb->current_monitor = NULL;
654 if (!from_user && (call == CTDB_EVENT_MONITOR || call == CTDB_EVENT_STATUS)) {
655 ctdb->current_monitor = state;
658 DEBUG(DEBUG_INFO,(__location__ " Starting eventscript %s %s\n",
659 call_names[state->call], state->options));
661 state->scripts = ctdb_get_script_list(ctdb, state);
662 if (state->scripts == NULL) {
669 if (state->scripts->num_scripts == 0) {
670 if (!state->from_user && state->call == CTDB_EVENT_MONITOR) {
671 ctdb_control_event_script_finished(ctdb, state);
673 ctdb->event_script_timeouts = 0;
678 ret = fork_child_for_script(ctdb, state);
684 talloc_set_destructor(state, event_script_destructor);
685 if (!timeval_is_zero(&state->timeout)) {
686 event_add_timed(ctdb->ev, state, timeval_current_ofs(state->timeout.tv_sec, state->timeout.tv_usec), ctdb_event_script_timeout, state);
688 DEBUG(DEBUG_ERR, (__location__ " eventscript %s %s called with no timeout\n",
689 call_names[state->call], state->options));
697 run the event script in the background, calling the callback when
700 int ctdb_event_script_callback(struct ctdb_context *ctdb,
702 void (*callback)(struct ctdb_context *, int, void *),
705 enum ctdb_eventscript_call call,
706 const char *fmt, ...)
712 ret = ctdb_event_script_callback_v(ctdb, callback, private_data, from_user, call, fmt, ap);
719 struct callback_status {
725 called when ctdb_event_script() finishes
727 static void event_script_callback(struct ctdb_context *ctdb, int status, void *private_data)
729 struct callback_status *s = (struct callback_status *)private_data;
735 run the event script, waiting for it to complete. Used when the caller
736 doesn't want to continue till the event script has finished.
738 int ctdb_event_script_args(struct ctdb_context *ctdb, enum ctdb_eventscript_call call,
739 const char *fmt, ...)
743 struct callback_status status;
746 ret = ctdb_event_script_callback_v(ctdb,
747 event_script_callback, &status, false, call, fmt, ap);
756 while (status.done == false && event_loop_once(ctdb->ev) == 0) /* noop */;
758 if (status.status == -ETIME) {
759 DEBUG(DEBUG_ERR, (__location__ " eventscript for '%s' timedout."
760 " Immediately banning ourself for %d seconds\n",
762 ctdb->tunable.recovery_ban_period));
766 return status.status;
769 int ctdb_event_script(struct ctdb_context *ctdb, enum ctdb_eventscript_call call)
771 /* GCC complains about empty format string, so use %s and "". */
772 return ctdb_event_script_args(ctdb, call, "%s", "");
775 struct eventscript_callback_state {
776 struct ctdb_req_control *c;
780 called when a forced eventscript run has finished
782 static void run_eventscripts_callback(struct ctdb_context *ctdb, int status,
785 struct eventscript_callback_state *state =
786 talloc_get_type(private_data, struct eventscript_callback_state);
788 ctdb_enable_monitoring(ctdb);
791 DEBUG(DEBUG_ERR,(__location__ " Failed to forcibly run eventscripts\n"));
794 ctdb_request_control_reply(ctdb, state->c, NULL, status, NULL);
795 /* This will free the struct ctdb_event_script_state we are in! */
801 /* Returns rest of string, or NULL if no match. */
802 static const char *get_call(const char *p, enum ctdb_eventscript_call *call)
806 /* Skip any initial whitespace. */
807 p += strspn(p, " \t");
809 /* See if we match any. */
810 for (*call = 0; *call < ARRAY_SIZE(call_names); (*call)++) {
811 len = strlen(call_names[*call]);
812 if (strncmp(p, call_names[*call], len) == 0) {
813 /* If end of string or whitespace, we're done. */
814 if (strcspn(p + len, " \t") == 0) {
823 A control to force running of the eventscripts from the ctdb client tool
825 int32_t ctdb_run_eventscripts(struct ctdb_context *ctdb,
826 struct ctdb_req_control *c,
827 TDB_DATA indata, bool *async_reply)
830 struct eventscript_callback_state *state;
832 enum ctdb_eventscript_call call;
834 /* Figure out what call they want. */
835 options = get_call((const char *)indata.dptr, &call);
837 DEBUG(DEBUG_ERR, (__location__ " Invalid forced \"%s\"\n", (const char *)indata.dptr));
841 if (ctdb->recovery_mode != CTDB_RECOVERY_NORMAL) {
842 DEBUG(DEBUG_ERR, (__location__ " Aborted running eventscript \"%s\" while in RECOVERY mode\n", indata.dptr));
846 state = talloc(ctdb->event_script_ctx, struct eventscript_callback_state);
847 CTDB_NO_MEMORY(ctdb, state);
849 state->c = talloc_steal(state, c);
851 DEBUG(DEBUG_NOTICE,("Forced running of eventscripts with arguments %s\n", indata.dptr));
853 ctdb_disable_monitoring(ctdb);
855 ret = ctdb_event_script_callback(ctdb,
856 state, run_eventscripts_callback, state,
857 true, call, "%s", options);
860 ctdb_enable_monitoring(ctdb);
861 DEBUG(DEBUG_ERR,(__location__ " Failed to run eventscripts with arguments %s\n", indata.dptr));
866 /* tell ctdb_control.c that we will be replying asynchronously */
874 int32_t ctdb_control_enable_script(struct ctdb_context *ctdb, TDB_DATA indata)
879 TALLOC_CTX *tmp_ctx = talloc_new(ctdb);
881 script = (char *)indata.dptr;
882 if (indata.dsize == 0) {
883 DEBUG(DEBUG_ERR,(__location__ " No script specified.\n"));
884 talloc_free(tmp_ctx);
887 if (indata.dptr[indata.dsize - 1] != '\0') {
888 DEBUG(DEBUG_ERR,(__location__ " String is not null terminated.\n"));
889 talloc_free(tmp_ctx);
892 if (index(script,'/') != NULL) {
893 DEBUG(DEBUG_ERR,(__location__ " Script name contains '/'. Failed to enable script %s\n", script));
894 talloc_free(tmp_ctx);
899 if (stat(ctdb->event_script_dir, &st) != 0 &&
901 DEBUG(DEBUG_CRIT,("No event script directory found at '%s'\n", ctdb->event_script_dir));
902 talloc_free(tmp_ctx);
907 filename = talloc_asprintf(tmp_ctx, "%s/%s", ctdb->event_script_dir, script);
908 if (filename == NULL) {
909 DEBUG(DEBUG_ERR,(__location__ " Failed to create script path\n"));
910 talloc_free(tmp_ctx);
914 if (stat(filename, &st) != 0) {
915 DEBUG(DEBUG_ERR,("Could not stat event script %s. Failed to enable script.\n", filename));
916 talloc_free(tmp_ctx);
920 if (chmod(filename, st.st_mode | S_IXUSR) == -1) {
921 DEBUG(DEBUG_ERR,("Could not chmod %s. Failed to enable script.\n", filename));
922 talloc_free(tmp_ctx);
926 talloc_free(tmp_ctx);
930 int32_t ctdb_control_disable_script(struct ctdb_context *ctdb, TDB_DATA indata)
935 TALLOC_CTX *tmp_ctx = talloc_new(ctdb);
937 script = (char *)indata.dptr;
938 if (indata.dsize == 0) {
939 DEBUG(DEBUG_ERR,(__location__ " No script specified.\n"));
940 talloc_free(tmp_ctx);
943 if (indata.dptr[indata.dsize - 1] != '\0') {
944 DEBUG(DEBUG_ERR,(__location__ " String is not null terminated.\n"));
945 talloc_free(tmp_ctx);
948 if (index(script,'/') != NULL) {
949 DEBUG(DEBUG_ERR,(__location__ " Script name contains '/'. Failed to disable script %s\n", script));
950 talloc_free(tmp_ctx);
955 if (stat(ctdb->event_script_dir, &st) != 0 &&
957 DEBUG(DEBUG_CRIT,("No event script directory found at '%s'\n", ctdb->event_script_dir));
958 talloc_free(tmp_ctx);
963 filename = talloc_asprintf(tmp_ctx, "%s/%s", ctdb->event_script_dir, script);
964 if (filename == NULL) {
965 DEBUG(DEBUG_ERR,(__location__ " Failed to create script path\n"));
966 talloc_free(tmp_ctx);
970 if (stat(filename, &st) != 0) {
971 DEBUG(DEBUG_ERR,("Could not stat event script %s. Failed to disable script.\n", filename));
972 talloc_free(tmp_ctx);
976 if (chmod(filename, st.st_mode & ~(S_IXUSR|S_IXGRP|S_IXOTH)) == -1) {
977 DEBUG(DEBUG_ERR,("Could not chmod %s. Failed to disable script.\n", filename));
978 talloc_free(tmp_ctx);
982 talloc_free(tmp_ctx);