Branch: refs/heads/feature-script_dir
  Home:   https://github.com/mailru/tarantool
  Commit: a8a6b2619e06105a0cebd37a1a1770d900ed1c50
      
https://github.com/mailru/tarantool/commit/a8a6b2619e06105a0cebd37a1a1770d900ed1c50
  Author: pmwkaa <[email protected]>
  Date:   2012-05-03 (Thu, 03 May 2012)

  Changed paths:
    M cfg/core_cfg.cfg_tmpl
    M cfg/tarantool_box_cfg.c
    M cfg/tarantool_box_cfg.h
    M src/tarantool_lua.m
    M test/box/admin.result
    M test/box/configuration.result

  Log Message:
  -----------
  feature-script_dir: script_dir configuration option added.
script_dir option defines path to a directory which contains the init.lua file.


diff --git a/cfg/core_cfg.cfg_tmpl b/cfg/core_cfg.cfg_tmpl
index 09a1b6d..0bf0617 100644
--- a/cfg/core_cfg.cfg_tmpl
+++ b/cfg/core_cfg.cfg_tmpl
@@ -41,6 +41,9 @@ snap_dir=".", ro
 # WAL directory (where WALs get saved/read)
 wal_dir=".", ro
 
+# script directory (where init.lua is expected to be)
+script_dir=".", ro
+
 # name of pid file
 pid_file="tarantool.pid", ro
 
diff --git a/cfg/tarantool_box_cfg.c b/cfg/tarantool_box_cfg.c
index d2168e7..7cf14f7 100644
--- a/cfg/tarantool_box_cfg.c
+++ b/cfg/tarantool_box_cfg.c
@@ -41,6 +41,7 @@
        c->work_dir = NULL;
        c->snap_dir = NULL;
        c->wal_dir = NULL;
+       c->script_dir = NULL;
        c->pid_file = NULL;
        c->logger = NULL;
        c->logger_nonblock = false;
@@ -88,6 +89,8 @@
        if (c->snap_dir == NULL) return CNF_NOMEMORY;
        c->wal_dir = strdup(".");
        if (c->wal_dir == NULL) return CNF_NOMEMORY;
+       c->script_dir = strdup(".");
+       if (c->script_dir == NULL) return CNF_NOMEMORY;
        c->pid_file = strdup("tarantool.pid");
        if (c->pid_file == NULL) return CNF_NOMEMORY;
        c->logger = NULL;
@@ -190,6 +193,9 @@
 static NameAtom _name__wal_dir[] = {
        { "wal_dir", -1, NULL }
 };
+static NameAtom _name__script_dir[] = {
+       { "script_dir", -1, NULL }
+};
 static NameAtom _name__pid_file[] = {
        { "pid_file", -1, NULL }
 };
@@ -540,6 +546,18 @@
                if (opt->paramValue.stringval && c->wal_dir == NULL)
                        return CNF_NOMEMORY;
        }
+       else if ( cmpNameAtoms( opt->name, _name__script_dir) ) {
+               if (opt->paramType != stringType )
+                       return CNF_WRONGTYPE;
+               c->__confetti_flags &= ~CNF_FLAG_STRUCT_NOTSET;
+               errno = 0;
+               if (check_rdonly && ( (opt->paramValue.stringval == NULL && 
c->script_dir == NULL) || strcmp(opt->paramValue.stringval, c->script_dir) != 
0))
+                       return CNF_RDONLY;
+                if (c->script_dir) free(c->script_dir);
+               c->script_dir = (opt->paramValue.stringval) ? 
strdup(opt->paramValue.stringval) : NULL;
+               if (opt->paramValue.stringval && c->script_dir == NULL)
+                       return CNF_NOMEMORY;
+       }
        else if ( cmpNameAtoms( opt->name, _name__pid_file) ) {
                if (opt->paramType != stringType )
                        return CNF_WRONGTYPE;
@@ -1229,6 +1247,7 @@
        S_name__work_dir,
        S_name__snap_dir,
        S_name__wal_dir,
+       S_name__script_dir,
        S_name__pid_file,
        S_name__logger,
        S_name__logger_nonblock,
@@ -1426,6 +1445,16 @@ struct tarantool_cfg_iterator_t {
                                return NULL;
                        }
                        snprintf(buf, PRINTBUFLEN-1, "wal_dir");
+                       i->state = S_name__script_dir;
+                       return buf;
+               case S_name__script_dir:
+                       *v = (c->script_dir) ? strdup(c->script_dir) : NULL;
+                       if (*v == NULL && c->script_dir) {
+                               free(i);
+                               out_warning(CNF_NOMEMORY, "No memory to output 
value");
+                               return NULL;
+                       }
+                       snprintf(buf, PRINTBUFLEN-1, "script_dir");
                        i->state = S_name__pid_file;
                        return buf;
                case S_name__pid_file:
@@ -1986,6 +2015,9 @@ struct tarantool_cfg_iterator_t {
        if (dst->wal_dir) free(dst->wal_dir);dst->wal_dir = src->wal_dir == 
NULL ? NULL : strdup(src->wal_dir);
        if (src->wal_dir != NULL && dst->wal_dir == NULL)
                return CNF_NOMEMORY;
+       if (dst->script_dir) free(dst->script_dir);dst->script_dir = 
src->script_dir == NULL ? NULL : strdup(src->script_dir);
+       if (src->script_dir != NULL && dst->script_dir == NULL)
+               return CNF_NOMEMORY;
        if (dst->pid_file) free(dst->pid_file);dst->pid_file = src->pid_file == 
NULL ? NULL : strdup(src->pid_file);
        if (src->pid_file != NULL && dst->pid_file == NULL)
                return CNF_NOMEMORY;
@@ -2093,6 +2125,8 @@ struct tarantool_cfg_iterator_t {
                free(c->snap_dir);
        if (c->wal_dir != NULL)
                free(c->wal_dir);
+       if (c->script_dir != NULL)
+               free(c->script_dir);
        if (c->pid_file != NULL)
                free(c->pid_file);
        if (c->logger != NULL)
@@ -2231,6 +2265,11 @@ struct tarantool_cfg_iterator_t {
 
                return diff;
 }
+       if (confetti_strcmp(c1->script_dir, c2->script_dir) != 0) {
+               snprintf(diff, PRINTBUFLEN - 1, "%s", "c->script_dir");
+
+               return diff;
+}
        if (confetti_strcmp(c1->pid_file, c2->pid_file) != 0) {
                snprintf(diff, PRINTBUFLEN - 1, "%s", "c->pid_file");
 
diff --git a/cfg/tarantool_box_cfg.h b/cfg/tarantool_box_cfg.h
index 81cbf5a..3ea6481 100644
--- a/cfg/tarantool_box_cfg.h
+++ b/cfg/tarantool_box_cfg.h
@@ -94,6 +94,9 @@
        /* WAL directory (where WALs get saved/read) */
        char*   wal_dir;
 
+       /* script directory (where init.lua is expected to be) */
+       char*   script_dir;
+
        /* name of pid file */
        char*   pid_file;
 
diff --git a/src/tarantool_lua.m b/src/tarantool_lua.m
index b49960e..0ad42f0 100644
--- a/src/tarantool_lua.m
+++ b/src/tarantool_lua.m
@@ -48,6 +48,7 @@
 /** tarantool start-up file */
 #define TARANTOOL_LUA_INIT_SCRIPT "init.lua"
 
+struct tarantool_cfg cfg;
 struct lua_State *tarantool_L;
 
 /* Remember the output of the administrative console in the
@@ -1082,8 +1083,16 @@ static char format_to_opcode(char format)
 {
        struct lua_State *L = (struct lua_State *) L_ptr;
        struct stat st;
+
+       char path[PATH_MAX];
+       snprintf(path, sizeof(path), "%s/%s",
+                        ((cfg.script_dir) ? cfg.script_dir : "."),
+                        TARANTOOL_LUA_INIT_SCRIPT);
+
+       say_info("trying to load %s", path);
+
        /* checking that Lua start-up file exist. */
-       if (stat(TARANTOOL_LUA_INIT_SCRIPT, &st)) {
+       if (stat(path, &st)) {
                /*
                 * File doesn't exist. It's OK, tarantool may not have
                 * start-up file.
@@ -1092,7 +1101,7 @@ static char format_to_opcode(char format)
        }
 
        /* execute start-up file */
-       if (tarantool_lua_dofile(L, TARANTOOL_LUA_INIT_SCRIPT))
+       if (tarantool_lua_dofile(L, path))
                panic("%s", lua_tostring(L, -1));
 }
 
diff --git a/test/box/admin.result b/test/box/admin.result
index a40aaf1..894f447 100644
--- a/test/box/admin.result
+++ b/test/box/admin.result
@@ -42,6 +42,7 @@ configuration:
   work_dir: (null)
   snap_dir: "."
   wal_dir: "."
+  script_dir: "."
   pid_file: "box.pid"
   logger: "cat - >> tarantool.log"
   logger_nonblock: "true"
diff --git a/test/box/configuration.result b/test/box/configuration.result
index 02ce266..b41d419 100644
--- a/test/box/configuration.result
+++ b/test/box/configuration.result
@@ -20,6 +20,7 @@ configuration:
   work_dir: (null)
   snap_dir: "."
   wal_dir: "."
+  script_dir: "."
   pid_file: "box.pid"
   logger: "cat - >> tarantool.log"
   logger_nonblock: "true"
@@ -83,6 +84,7 @@ configuration:
   work_dir: (null)
   snap_dir: "."
   wal_dir: "."
+  script_dir: "."
   pid_file: "box.pid"
   logger: "cat - >> tarantool.log"
   logger_nonblock: "true"


================================================================

_______________________________________________
Mailing list: https://launchpad.net/~tarantool-developers
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~tarantool-developers
More help   : https://help.launchpad.net/ListHelp

Reply via email to