ctdb-event: Change event-tool script enable/disable to chmod file directly
authorMartin Schwenke <martin@meltin.net>
Thu, 12 Jul 2018 03:27:16 +0000 (13:27 +1000)
committerAmitay Isaacs <amitay@samba.org>
Sat, 28 Jul 2018 15:14:11 +0000 (17:14 +0200)
They no longer go over the socket to eventd to enable and disable
scripts.  Use the event script abstraction to chmod them directly.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=13551

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
ctdb/event/event_tool.c

index 7760c9713403fce25ad2c506016b28c444c4f231..223e829c3434d997dab69d8b715d427d8ba2e2a6 100644 (file)
@@ -30,6 +30,7 @@
 #include "common/cmdline.h"
 #include "common/logging.h"
 #include "common/path.h"
+#include "common/event_script.h"
 
 #include "event/event_protocol_api.h"
 #include "event/event.h"
@@ -298,44 +299,30 @@ static int event_command_script(TALLOC_CTX *mem_ctx,
                                struct event_tool_context *ctx,
                                const char *component,
                                const char *script,
-                               enum ctdb_event_script_action action)
+                               bool enable)
 {
-       struct tevent_req *req;
-       struct ctdb_event_request_script request_script;
-       int ret = 0, result = 0;
-       bool ok;
+       char *subdir, *etc_dir;
+       int result = 0;
 
-       ret = ctdb_event_init(ctx, ctx->ev, &ctx->eclient);
-       if (ret != 0) {
-               D_ERR("Failed to initialize event client, ret=%d\n", ret);
-               return ret;
+       subdir = talloc_asprintf(mem_ctx, "events/%s", component);
+       if (subdir == NULL) {
+               return ENOMEM;
        }
 
-       request_script.component = component;
-       request_script.script = script;
-       request_script.action = action;
-
-       req = ctdb_event_script_send(mem_ctx,
-                                    ctx->ev,
-                                    ctx->eclient,
-                                    &request_script);
-       if (req == NULL) {
-               D_ERR("Memory allocation error\n");
-               return 1;
+       etc_dir = path_etcdir_append(mem_ctx, subdir);
+       if (etc_dir == NULL) {
+               return ENOMEM;
        }
 
-       tevent_req_poll(req, ctx->ev);
-
-       ok = ctdb_event_script_recv(req, &ret, &result);
-       if (!ok) {
-               D_ERR("Failed to %s script, ret=%d\n",
-                     (action == CTDB_EVENT_SCRIPT_DISABLE ?
-                      "disable" :
-                      "enable"),
-                     ret);
-               return 1;
+       if (enable) {
+               result = event_script_chmod(etc_dir, script, true);
+       } else {
+               result = event_script_chmod(etc_dir, script, false);
        }
 
+       talloc_free(subdir);
+       talloc_free(etc_dir);
+
        D_NOTICE("Command script finished with result=%d\n", result);
 
        if (result == EINVAL) {
@@ -388,7 +375,7 @@ static int event_command_script_enable(TALLOC_CTX *mem_ctx,
                                                    ctx,
                                                    argv[0],
                                                    argv[1],
-                                                   CTDB_EVENT_SCRIPT_ENABLE);
+                                                   true);
                }
 
                printf("Script %s is not a file or a link\n", etc_script);
@@ -461,7 +448,7 @@ static int event_command_script_disable(TALLOC_CTX *mem_ctx,
                                                    ctx,
                                                    argv[0],
                                                    argv[1],
-                                                   CTDB_EVENT_SCRIPT_DISABLE);
+                                                   false);
                }
 
                printf("Script %s is not a file or a link\n", etc_script);