ctdb-event: Declare and construct data_script only if needed
authorMartin Schwenke <martin@meltin.net>
Fri, 7 Sep 2018 04:35:15 +0000 (14:35 +1000)
committerAmitay Isaacs <amitay@gmail.com>
Tue, 18 Dec 2018 02:36:47 +0000 (13:36 +1100)
Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
ctdb/event/event_tool.c

index 8350f20..b597279 100644 (file)
@@ -515,7 +515,7 @@ static int event_command_script_enable(TALLOC_CTX *mem_ctx,
        struct event_tool_context *ctx = talloc_get_type_abort(
                private_data, struct event_tool_context);
        struct stat statbuf;
-       char *script, *etc_script, *data_script;
+       char *script, *etc_script;
        int ret;
 
        if (argc != 2) {
@@ -533,11 +533,6 @@ static int event_command_script_enable(TALLOC_CTX *mem_ctx,
                return ENOMEM;
        }
 
-       data_script = path_datadir_append(mem_ctx, script);
-       if (data_script == NULL) {
-               return ENOMEM;
-       }
-
        ret = lstat(etc_script, &statbuf);
        if (ret == 0) {
                if (S_ISLNK(statbuf.st_mode)) {
@@ -555,6 +550,13 @@ static int event_command_script_enable(TALLOC_CTX *mem_ctx,
                return EINVAL;
        } else {
                if (errno == ENOENT) {
+                       char *data_script;
+
+                       data_script = path_datadir_append(mem_ctx, script);
+                       if (data_script == NULL) {
+                               return ENOMEM;
+                       }
+
                        ret = stat(data_script, &statbuf);
                        if (ret != 0) {
                                printf("Script %s does not exist in %s\n",