diff options
author | onefang | 2021-08-03 14:07:52 +1000 |
---|---|---|
committer | onefang | 2021-08-03 14:07:52 +1000 |
commit | ccc563e24dfc001b8e5689e7cb5faa834986bdc1 (patch) | |
tree | 149ca60622da3f54b5bb2e6c1cd6d5497a622a79 /src/sledjchisl/sledjchisl.c | |
parent | memset-- (diff) | |
download | opensim-SC-ccc563e24dfc001b8e5689e7cb5faa834986bdc1.zip opensim-SC-ccc563e24dfc001b8e5689e7cb5faa834986bdc1.tar.gz opensim-SC-ccc563e24dfc001b8e5689e7cb5faa834986bdc1.tar.bz2 opensim-SC-ccc563e24dfc001b8e5689e7cb5faa834986bdc1.tar.xz |
Move window and pane opening to ROBUST starting time.
So the writing of the pane ID files is also then.
Open those pane ID files also before the main loop.
So all the actions have access.
Also some clean up of that code.
Diffstat (limited to 'src/sledjchisl/sledjchisl.c')
-rw-r--r-- | src/sledjchisl/sledjchisl.c | 500 |
1 files changed, 261 insertions, 239 deletions
diff --git a/src/sledjchisl/sledjchisl.c b/src/sledjchisl/sledjchisl.c index c8622d8..093c3ef 100644 --- a/src/sledjchisl/sledjchisl.c +++ b/src/sledjchisl/sledjchisl.c | |||
@@ -7780,6 +7780,10 @@ fcgiDone: | |||
7780 | 7780 | ||
7781 | //T("ARGS - %i |%s| |%s|", currentMode, toys.optargs[0], target); | 7781 | //T("ARGS - %i |%s| |%s|", currentMode, toys.optargs[0], target); |
7782 | 7782 | ||
7783 | qtreetbl_obj_t obj0, obj1; | ||
7784 | qLua *q0, *q1; | ||
7785 | int count = 0, window = 0, panes = 4, pane = 0; | ||
7786 | |||
7783 | //////////////////////////////////////////////////////////////////////////////////////////////////// | 7787 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
7784 | // Start ROBUST or join the tmux session. | 7788 | // Start ROBUST or join the tmux session. |
7785 | //////////////////////////////////////////////////////////////////////////////////////////////////// | 7789 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
@@ -7795,6 +7799,139 @@ fcgiDone: | |||
7795 | sendTmuxCmd(d, c); | 7799 | sendTmuxCmd(d, c); |
7796 | free(c); | 7800 | free(c); |
7797 | doTmuxCmd("select-pane -t 0 -T 'ROBUST'", Tcmd, scRun, Tsocket); | 7801 | doTmuxCmd("select-pane -t 0 -T 'ROBUST'", Tcmd, scRun, Tsocket); |
7802 | |||
7803 | //////////////////////////////////////////////////////////////////////////////////////////////////// | ||
7804 | // Create all the tmux windows, panes, and temporary .ini files, coz OpenSim sucketh. | ||
7805 | //////////////////////////////////////////////////////////////////////////////////////////////////// | ||
7806 | memset((void*)&obj0, 0, sizeof(obj0)); | ||
7807 | ourSims->simsLua->lock(ourSims->simsLua); | ||
7808 | while(ourSims->simsLua->getnext(ourSims->simsLua, &obj0, false) == true) | ||
7809 | { | ||
7810 | q0 = obj0.data; | ||
7811 | char *type = "unsorted"; | ||
7812 | |||
7813 | if (LUA_TTABLE == q0->type) | ||
7814 | { | ||
7815 | panes = 4; | ||
7816 | q1 = q0->v.t->get(q0->v.t, "number", NULL, false); if (NULL != q1) window = q1->v.f - 1; | ||
7817 | q1 = q0->v.t->get(q0->v.t, "panes", NULL, false); if (NULL != q1) panes = q1->v.f; | ||
7818 | q1 = q0->v.t->get(q0->v.t, "type", NULL, false); if (NULL != q1) type = q1->v.s; | ||
7819 | if (0 == panes) | ||
7820 | { | ||
7821 | pane = 2; | ||
7822 | window = 0; | ||
7823 | type = Ttab; | ||
7824 | } | ||
7825 | else if (0 != pane) | ||
7826 | { | ||
7827 | pane = 0; | ||
7828 | window++; | ||
7829 | } | ||
7830 | |||
7831 | T("Prepping sims of type %s, window %d, %d panes per window.", type, window, panes); | ||
7832 | |||
7833 | memset((void*)&obj1, 0, sizeof(obj1)); | ||
7834 | q0->v.t->lock(q0->v.t); | ||
7835 | while(q0->v.t->getnext(q0->v.t, &obj1, false) == true) | ||
7836 | { | ||
7837 | q1 = obj1.data; | ||
7838 | |||
7839 | if ((strcmp("number", obj1.name) != 0) && (strcmp("panes", obj1.name) != 0) && (strcmp("type", obj1.name) != 0)) | ||
7840 | { | ||
7841 | char *sim = q1->v.s; | ||
7842 | qlisttbl_t *ini = ourSims->byTab->get(ourSims->byTab, sim, NULL, false); | ||
7843 | |||
7844 | if (NULL == ini) | ||
7845 | E("Sim %s not found in ini list!", sim); | ||
7846 | else | ||
7847 | { | ||
7848 | simData *simd = ini->get(ini, "SIM DATA", NULL, false); | ||
7849 | char *path = xmprintf("%s/%s.shini", scEtc, simd->tab); | ||
7850 | char *newPath = xmprintf("%s/sim%d/%s.ini", scTemp, count, simd->tab); // Coz OpenSim. | ||
7851 | char *cmd; | ||
7852 | |||
7853 | simd->window = window; | ||
7854 | simd->pane = pane; | ||
7855 | |||
7856 | // The bash invocations are so that the PATH is properly propagated. | ||
7857 | if (0 == panes) | ||
7858 | doTmuxCmd("split-window -hp 50 -d -t '%s:0.1' bash", Tconsole); | ||
7859 | else if (0 == pane) | ||
7860 | { | ||
7861 | doTmuxCmd("new-window -dc '%s/current/bin' -n '%s' -t '%s:%d' bash", scRoot, type, Tconsole, window); | ||
7862 | if (2 <= panes) | ||
7863 | doTmuxCmd("split-window -hp 50 -d -t '%s:%d.0' bash", Tconsole, window); | ||
7864 | if (4 <= panes) | ||
7865 | { | ||
7866 | doTmuxCmd("split-window -vp 50 -d -t '%s:%d.1' bash", Tconsole, window); | ||
7867 | doTmuxCmd("split-window -vp 50 -d -t '%s:%d.0' bash", Tconsole, window); | ||
7868 | } | ||
7869 | if (8 <= panes) | ||
7870 | { | ||
7871 | doTmuxCmd("split-window -hp 50 -d -t '%s:%d.3' bash", Tconsole, window); | ||
7872 | doTmuxCmd("split-window -hp 50 -d -t '%s:%d.2' bash", Tconsole, window); | ||
7873 | doTmuxCmd("split-window -hp 50 -d -t '%s:%d.1' bash", Tconsole, window); | ||
7874 | doTmuxCmd("split-window -hp 50 -d -t '%s:%d.0' bash", Tconsole, window); | ||
7875 | } | ||
7876 | } | ||
7877 | snprintf(toybuf, sizeof(toybuf), "echo 'IDs={' >%s/IDs_%d.lua", scTemp, window); | ||
7878 | system(toybuf); | ||
7879 | doTmuxCmd("list-panes -t %d -F \"['%d #{pane_index}'] = '#{window_id}.#{pane_id}',\" >> %s/IDs_%d.lua", window, window, scTemp, window); | ||
7880 | snprintf(toybuf, sizeof(toybuf), "echo '}\nreturn IDs' >>%s/IDs_%d.lua", scTemp, window); | ||
7881 | system(toybuf); | ||
7882 | |||
7883 | snprintf(toybuf, sizeof(toybuf), "%s/IDs_%d.lua", scTemp, window); | ||
7884 | qtreetbl_t *IDs = Lua2tree(toybuf, "IDs"); | ||
7885 | snprintf(toybuf, sizeof(toybuf), "%d %d", window, pane); | ||
7886 | simd->paneID = xmprintf("%s", qLuaGet(IDs, toybuf)->v.s); | ||
7887 | freeLuaTree(IDs); | ||
7888 | |||
7889 | simd->portH = 8004 + count * 2; | ||
7890 | simd->portU = 8005 + count * 2; | ||
7891 | cmd = xmprintf("rm -fr %s/sim%d; mkdir -p %s/sim%d; sed -E" | ||
7892 | " -e 's@\\[Region\\]@" | ||
7893 | " paneID = \"\\%s\"\\n" | ||
7894 | "\\[Startup\\]\\n" | ||
7895 | " PIDFile = \"\\$\\{Paths\\|CachePath\\}\\/\\$\\{Const\\|mysim\\}\\.pid\"\\n" | ||
7896 | " LogFile = \"\\$\\{Paths\\|LogPath\\}\\/OpenSim_\\$\\{Const\\|mysim\\}\\.log\"\\n" | ||
7897 | " StatsLogFile = \"\\$\\{Paths\\|LogPath\\}\\/OpenSimStats_\\$\\{Const\\|mysim\\}\\.log\"\\n" | ||
7898 | " ConsoleHistoryFile = \"\\$\\{Paths\\|LogPath\\}\\/OpenSimConsoleHistory_\\$\\{Const\\|mysim\\}\\.txt\"\\n" | ||
7899 | "\\n\\[Region\\]@'" | ||
7900 | " -e 's/InternalPort[[:space:]]*=[[:space:]]*[[:digit:]]+/InternalPort = %d/'" | ||
7901 | " -e 's/InternalPort[[:space:]]*=[[:space:]]*\"[[:digit:]]+\"/InternalPort = %d/'" | ||
7902 | " -e 's/http_listener_port[[:space:]]*=[[:space:]]*[[:digit:]]+/http_listener_port = %d/'" | ||
7903 | " -e 's/http_listener_port[[:space:]]*=[[:space:]]*\"[[:digit:]]+\"/http_listener_port = %d/'" | ||
7904 | " %s >%s", | ||
7905 | scTemp, count, | ||
7906 | scTemp, count, | ||
7907 | simd->paneID, | ||
7908 | simd->portU, | ||
7909 | simd->portU, | ||
7910 | simd->portH, | ||
7911 | simd->portH, | ||
7912 | path, newPath); | ||
7913 | D("Writing .ini file %s with ports %d %d", newPath, simd->portH, simd->portU); | ||
7914 | int j = system(cmd); | ||
7915 | if (!WIFEXITED(j)) | ||
7916 | E("sed command failed!"); | ||
7917 | free(cmd); | ||
7918 | free(newPath); | ||
7919 | free(path); | ||
7920 | count++; | ||
7921 | pane++; | ||
7922 | if (pane >= panes) | ||
7923 | { | ||
7924 | pane = 0; | ||
7925 | window++; | ||
7926 | } | ||
7927 | } | ||
7928 | } | ||
7929 | } | ||
7930 | q0->v.t->unlock(q0->v.t); | ||
7931 | } | ||
7932 | } | ||
7933 | ourSims->simsLua->unlock(ourSims->simsLua); | ||
7934 | |||
7798 | waitTmuxText(d, "INITIALIZATION COMPLETE FOR ROBUST"); | 7935 | waitTmuxText(d, "INITIALIZATION COMPLETE FOR ROBUST"); |
7799 | I("ROBUST is done starting up."); | 7936 | I("ROBUST is done starting up."); |
7800 | free(d); | 7937 | free(d); |
@@ -7805,6 +7942,77 @@ fcgiDone: | |||
7805 | doTmuxCmd("select-window -t '%s' \\; attach-session -t '%s'", Tconsole, Tconsole); | 7942 | doTmuxCmd("select-window -t '%s' \\; attach-session -t '%s'", Tconsole, Tconsole); |
7806 | goto finished; | 7943 | goto finished; |
7807 | } | 7944 | } |
7945 | else | ||
7946 | { | ||
7947 | // Find out where the sims are in tmux. | ||
7948 | memset((void*)&obj0, 0, sizeof(obj0)); | ||
7949 | ourSims->simsLua->lock(ourSims->simsLua); | ||
7950 | while(ourSims->simsLua->getnext(ourSims->simsLua, &obj0, false) == true) | ||
7951 | { | ||
7952 | q0 = obj0.data; | ||
7953 | char *type = "unsorted"; | ||
7954 | |||
7955 | if (LUA_TTABLE == q0->type) | ||
7956 | { | ||
7957 | panes = 4; | ||
7958 | q1 = q0->v.t->get(q0->v.t, "number", NULL, false); if (NULL != q1) window = q1->v.f - 1; | ||
7959 | q1 = q0->v.t->get(q0->v.t, "panes", NULL, false); if (NULL != q1) panes = q1->v.f; | ||
7960 | q1 = q0->v.t->get(q0->v.t, "type", NULL, false); if (NULL != q1) type = q1->v.s; | ||
7961 | if (0 == panes) | ||
7962 | { | ||
7963 | pane = 2; | ||
7964 | window = 0; | ||
7965 | type = Ttab; | ||
7966 | } | ||
7967 | else if (0 != pane) | ||
7968 | { | ||
7969 | pane = 0; | ||
7970 | window++; | ||
7971 | } | ||
7972 | |||
7973 | memset((void*)&obj1, 0, sizeof(obj1)); | ||
7974 | q0->v.t->lock(q0->v.t); | ||
7975 | while(q0->v.t->getnext(q0->v.t, &obj1, false) == true) | ||
7976 | { | ||
7977 | q1 = obj1.data; | ||
7978 | |||
7979 | if ((strcmp("number", obj1.name) != 0) && (strcmp("panes", obj1.name) != 0) && (strcmp("type", obj1.name) != 0)) | ||
7980 | { | ||
7981 | char *sim = q1->v.s; | ||
7982 | qlisttbl_t *ini = ourSims->byTab->get(ourSims->byTab, sim, NULL, false); | ||
7983 | |||
7984 | if (NULL == ini) | ||
7985 | E("Sim %s not found in ini list!", sim); | ||
7986 | else | ||
7987 | { | ||
7988 | simData *simd = ini->get(ini, "SIM DATA", NULL, false); | ||
7989 | |||
7990 | simd->window = window; | ||
7991 | simd->pane = pane; | ||
7992 | |||
7993 | char *newPath = xmprintf("%s/sim%d/%s.ini", scTemp, count, simd->tab); // Coz OpenSim. | ||
7994 | |||
7995 | snprintf(toybuf, sizeof(toybuf), "%s/IDs_%d.lua", scTemp, window); | ||
7996 | qtreetbl_t *IDs = Lua2tree(toybuf, "IDs"); | ||
7997 | snprintf(toybuf, sizeof(toybuf), "%d %d", window, pane); | ||
7998 | simd->paneID = xmprintf("%s", qLuaGet(IDs, toybuf)->v.s); | ||
7999 | freeLuaTree(IDs); | ||
8000 | free(newPath); | ||
8001 | count++; | ||
8002 | pane++; | ||
8003 | if (pane >= panes) | ||
8004 | { | ||
8005 | pane = 0; | ||
8006 | window++; | ||
8007 | } | ||
8008 | } | ||
8009 | } | ||
8010 | } | ||
8011 | q0->v.t->unlock(q0->v.t); | ||
8012 | } | ||
8013 | } | ||
8014 | ourSims->simsLua->unlock(ourSims->simsLua); | ||
8015 | } | ||
7808 | 8016 | ||
7809 | /* | 8017 | /* |
7810 | sims = -- Note these are .shini / tmux tab short names. | 8018 | sims = -- Note these are .shini / tmux tab short names. |
@@ -7818,10 +8026,11 @@ sims = -- Note these are .shini / tmux tab short names. | |||
7818 | {["type"] = "Heavies"; ["number"] = 18; "DP", "ARSE"}, | 8026 | {["type"] = "Heavies"; ["number"] = 18; "DP", "ARSE"}, |
7819 | } | 8027 | } |
7820 | */ | 8028 | */ |
7821 | qtreetbl_obj_t obj0, obj1; | ||
7822 | qLua *q0, *q1; | ||
7823 | int count = 0, window = 0, panes = 4, pane = 0; | ||
7824 | 8029 | ||
8030 | //////////////////////////////////////////////////////////////////////////////////////////////////// | ||
8031 | // Sim wrangling loop. | ||
8032 | //////////////////////////////////////////////////////////////////////////////////////////////////// | ||
8033 | count = 0; window = 0; panes = 4; pane = 0; | ||
7825 | memset((void*)&obj0, 0, sizeof(obj0)); | 8034 | memset((void*)&obj0, 0, sizeof(obj0)); |
7826 | ourSims->simsLua->lock(ourSims->simsLua); | 8035 | ourSims->simsLua->lock(ourSims->simsLua); |
7827 | while(ourSims->simsLua->getnext(ourSims->simsLua, &obj0, false) == true) | 8036 | while(ourSims->simsLua->getnext(ourSims->simsLua, &obj0, false) == true) |
@@ -7839,6 +8048,7 @@ sims = -- Note these are .shini / tmux tab short names. | |||
7839 | { | 8048 | { |
7840 | pane = 2; | 8049 | pane = 2; |
7841 | window = 0; | 8050 | window = 0; |
8051 | type = Ttab; | ||
7842 | } | 8052 | } |
7843 | else if (0 != pane) | 8053 | else if (0 != pane) |
7844 | { | 8054 | { |
@@ -7846,7 +8056,7 @@ sims = -- Note these are .shini / tmux tab short names. | |||
7846 | window++; | 8056 | window++; |
7847 | } | 8057 | } |
7848 | 8058 | ||
7849 | T("Doing sims of type %s, window %d, %d panes per window. %d", type, window, panes, pane); | 8059 | T("Doing sims of type %s, window %d, %d panes per window.", type, window, panes); |
7850 | memset((void*)&obj1, 0, sizeof(obj1)); | 8060 | memset((void*)&obj1, 0, sizeof(obj1)); |
7851 | q0->v.t->lock(q0->v.t); | 8061 | q0->v.t->lock(q0->v.t); |
7852 | while(q0->v.t->getnext(q0->v.t, &obj1, false) == true) | 8062 | while(q0->v.t->getnext(q0->v.t, &obj1, false) == true) |
@@ -7863,248 +8073,58 @@ sims = -- Note these are .shini / tmux tab short names. | |||
7863 | else | 8073 | else |
7864 | { | 8074 | { |
7865 | simData *simd = ini->get(ini, "SIM DATA", NULL, false); | 8075 | simData *simd = ini->get(ini, "SIM DATA", NULL, false); |
7866 | char *nm = simd->tab; | ||
7867 | char *name = simd->name; | ||
7868 | |||
7869 | simd->window = window; | ||
7870 | simd->pane = pane; | ||
7871 | I("%s is starting up in tab [%d:%s](pane %d), tmux ID = %s, from %s/sim%d.", name, window, type, pane, simd->paneID, scTemp, count); | ||
7872 | |||
7873 | 8076 | ||
7874 | 8077 | // Check if only doing a single sim. | |
7875 | count++; | 8078 | int cont = FALSE; |
7876 | } | 8079 | if (NULL != target) |
7877 | |||
7878 | pane++; | ||
7879 | if (pane >= panes) | ||
7880 | { | ||
7881 | pane = 0; | ||
7882 | window++; | ||
7883 | } | ||
7884 | } | ||
7885 | } | ||
7886 | q0->v.t->unlock(q0->v.t); | ||
7887 | } | ||
7888 | } | ||
7889 | ourSims->simsLua->unlock(ourSims->simsLua); | ||
7890 | goto finished; | ||
7891 | |||
7892 | |||
7893 | |||
7894 | |||
7895 | snprintf(toybuf, sizeof(toybuf), "%s/sims.lua", scEtc); | ||
7896 | if (0 == lstat(toybuf, &st)) | ||
7897 | { | ||
7898 | // int count = 0, window = 0, panes = 4, pane = 0; | ||
7899 | |||
7900 | I("Loading sims file - %s", toybuf); | ||
7901 | status = luaL_loadfile(L, toybuf); | ||
7902 | if (status) // If something went wrong, error message is at the top of the stack. | ||
7903 | E("Couldn't load file: %s", lua_tostring(L, -1)); | ||
7904 | else | ||
7905 | { | ||
7906 | result = lua_pcall(L, 0, LUA_MULTRET, 0); | ||
7907 | if (result) | ||
7908 | E("Failed to run script: %s", lua_tostring(L, -1)); | ||
7909 | else | ||
7910 | { | ||
7911 | //////////////////////////////////////////////////////////////////////////////////////////////////// | ||
7912 | // Sim wrangling loop. | ||
7913 | //////////////////////////////////////////////////////////////////////////////////////////////////// | ||
7914 | lua_getglobal(L, "sims"); | ||
7915 | |||
7916 | lua_pushnil(L); // lua_next() needs the last key at the top, but we don't start with one. | ||
7917 | while(lua_next(L, -2) != 0) // pushes key then value. | ||
7918 | { // key -2 value -1 | ||
7919 | if (lua_istable(L, -1)) | ||
7920 | { | ||
7921 | const char *type = "unsorted"; | ||
7922 | |||
7923 | panes = 4; | ||
7924 | lua_getfield(L, -1, "type"); | ||
7925 | lua_getfield(L, -2, "number"); | ||
7926 | lua_getfield(L, -3, "panes"); | ||
7927 | if (LUA_TNIL != lua_type(L, -3)) type = lua_tostring(L, -3); | ||
7928 | if (LUA_TNIL != lua_type(L, -2)) window = lua_tonumber(L, -2) - 1; | ||
7929 | if (LUA_TNIL != lua_type(L, -1)) panes = lua_tonumber(L, -1); | ||
7930 | lua_pop(L, 3); | ||
7931 | if (0 == panes) | ||
7932 | { | 8080 | { |
7933 | pane = 2; | 8081 | cont = TRUE; |
7934 | window = 0; | 8082 | snprintf(toybuf, sizeof(toybuf), "%s.shini", simd->tab); |
8083 | if | ||
8084 | ( | ||
8085 | (strcmp(target, sim) == 0) || | ||
8086 | (strcmp(target, simd->name) == 0) || | ||
8087 | (strcmp(target, simd->tab) == 0) || | ||
8088 | (strcmp(target, toybuf) == 0) | ||
8089 | ) | ||
8090 | cont = FALSE; | ||
8091 | snprintf(toybuf, sizeof(toybuf), "%s.ini", simd->tab); | ||
8092 | if (strcmp(target, toybuf) == 0) | ||
8093 | cont = FALSE; | ||
8094 | snprintf(toybuf, sizeof(toybuf), "sim%d.ini", count); | ||
8095 | if (strcmp(target, toybuf) == 0) | ||
8096 | cont = FALSE; | ||
7935 | } | 8097 | } |
7936 | else if (0 != pane) | 8098 | if (!cont) |
7937 | { | 8099 | { |
7938 | pane = 0; | ||
7939 | window++; | ||
7940 | } | ||
7941 | |||
7942 | T("Doing sims of type %s, window %d, %d panes per window", type, window, panes); | ||
7943 | lua_pushnil(L); | ||
7944 | while(lua_next(L, -2) != 0) | ||
7945 | { | ||
7946 | char *sim = (char *) lua_tostring(L, -1); | ||
7947 | |||
7948 | if (LUA_TNUMBER == lua_type(L, -2)) | ||
7949 | { | ||
7950 | int num; | ||
7951 | char *nm = NULL; | ||
7952 | char *name;// = getSimName(ourSims->sims[i], &nm, &num); | ||
7953 | qlisttbl_t *ini = ourSims->byTab->get(ourSims->byTab, sim, NULL, false); | ||
7954 | simData *simd; | ||
7955 | |||
7956 | if (NULL == ini) | ||
7957 | { | ||
7958 | E("Sim %s not found in ini list!", sim); | ||
7959 | } | ||
7960 | else | ||
7961 | { | ||
7962 | simd = ini->get(ini, "SIM DATA", NULL, false); | ||
7963 | name = simd->name; | ||
7964 | nm = simd->tab; | ||
7965 | simd->window = window; | ||
7966 | simd->pane = pane; | ||
7967 | } | ||
7968 | |||
7969 | if (NULL != target) | ||
7970 | { | ||
7971 | int cont = TRUE; | ||
7972 | |||
7973 | snprintf(toybuf, sizeof(toybuf), "%s.shini", nm); | ||
7974 | if | ||
7975 | ( | ||
7976 | (strcmp(target, sim) == 0) || | ||
7977 | (strcmp(target, name) == 0) || | ||
7978 | (strcmp(target, nm) == 0) || | ||
7979 | (strcmp(target, toybuf) == 0) | ||
7980 | ) | ||
7981 | cont = FALSE; | ||
7982 | snprintf(toybuf, sizeof(toybuf), "%s.ini", nm); | ||
7983 | if (strcmp(target, toybuf) == 0) | ||
7984 | cont = FALSE; | ||
7985 | snprintf(toybuf, sizeof(toybuf), "sim%d.ini", count); | ||
7986 | if (strcmp(target, toybuf) == 0) | ||
7987 | cont = FALSE; | ||
7988 | if (cont) | ||
7989 | goto nextSim; | ||
7990 | } | ||
7991 | |||
7992 | switch (currentMode) | 8100 | switch (currentMode) |
7993 | { | 8101 | { |
7994 | case START : // "start sim01" "start 'Welcome sim'" "start Welcome.ini" "start Welcome" "start" start everything | 8102 | case START : // "start sim01" "start 'Welcome sim'" "start Welcome.ini" "start Welcome" "start" start everything |
7995 | { // TODO - check if sim is down, but tmux window is still up, and close the tmux window first. | 8103 | { // TODO - check if sim is down, but tmux window is still up, and close the tmux window first. |
7996 | if (!checkSimIsRunning(nm)) | 8104 | if (!checkSimIsRunning(simd->tab)) |
7997 | { | 8105 | { |
7998 | char *path = xmprintf("%s/%s.shini", scEtc, nm); | 8106 | I("Tmux tab [%d:%s](pane %d) tmux ID %s, from %s/sim%d - %s is starting.", window, type, pane, simd->paneID, scTemp, count, simd->name); |
7999 | char *newPath = xmprintf("%s/sim%d/%s.ini", scTemp, count, nm); // Coz OpenSim. | 8107 | doTmuxCmd("select-pane -t %s:%s -T '%s'", Tconsole, simd->paneID, simd->tab); |
8000 | char *cmd; | ||
8001 | |||
8002 | // The bash invocations are so that the PATH is properly propagated. | ||
8003 | if (0 == panes) | ||
8004 | doTmuxCmd("split-window -hp 50 -d -t '%s:0.1' bash", Tconsole); | ||
8005 | else if (0 == pane) | ||
8006 | { | ||
8007 | doTmuxCmd("new-window -dc '%s/current/bin' -n '%s' -t '%s:%d' bash", scRoot, type, Tconsole, window); | ||
8008 | if (2 <= panes) | ||
8009 | doTmuxCmd("split-window -hp 50 -d -t '%s:%d.0' bash", Tconsole, window); | ||
8010 | if (4 <= panes) | ||
8011 | { | ||
8012 | doTmuxCmd("split-window -vp 50 -d -t '%s:%d.1' bash", Tconsole, window); | ||
8013 | doTmuxCmd("split-window -vp 50 -d -t '%s:%d.0' bash", Tconsole, window); | ||
8014 | } | ||
8015 | if (8 <= panes) | ||
8016 | { | ||
8017 | doTmuxCmd("split-window -hp 50 -d -t '%s:%d.3' bash", Tconsole, window); | ||
8018 | doTmuxCmd("split-window -hp 50 -d -t '%s:%d.2' bash", Tconsole, window); | ||
8019 | doTmuxCmd("split-window -hp 50 -d -t '%s:%d.1' bash", Tconsole, window); | ||
8020 | doTmuxCmd("split-window -hp 50 -d -t '%s:%d.0' bash", Tconsole, window); | ||
8021 | } | ||
8022 | /* TODO - | ||
8023 | IDs={ | ||
8024 | ['21 0'] = '@17.%65', | ||
8025 | ['21 1'] = '@17.%68', | ||
8026 | ['21 2'] = '@17.%66', | ||
8027 | ['21 3'] = '@17.%67', | ||
8028 | } | ||
8029 | return IDs | ||
8030 | |||
8031 | Move window and pane opening to ROBUST starting time. | ||
8032 | So the writing of the pane ID files is also then. | ||
8033 | Open those pane ID files also before the main loop. | ||
8034 | So all the actions have access. | ||
8035 | |||
8036 | Leave empty panes as is. | ||
8037 | Don't bother to close panes unless we are doing a full stop. | ||
8038 | Also clear out tmp when doing a full stop. | ||
8039 | */ | ||
8040 | } | ||
8041 | snprintf(toybuf, sizeof(toybuf), "echo 'IDs={' >%s/IDs_%d.lua", scTemp, window); | ||
8042 | system(toybuf); | ||
8043 | doTmuxCmd("list-panes -t %d -F \"['%d #{pane_index}'] = '#{window_id}.#{pane_id}',\" >> %s/IDs_%d.lua", window, window, scTemp, window); | ||
8044 | snprintf(toybuf, sizeof(toybuf), "echo '}\nreturn IDs' >>%s/IDs_%d.lua", scTemp, window); | ||
8045 | system(toybuf); | ||
8046 | |||
8047 | snprintf(toybuf, sizeof(toybuf), "%s/IDs_%d.lua", scTemp, window); | ||
8048 | qtreetbl_t *IDs = Lua2tree(toybuf, "IDs"); | ||
8049 | snprintf(toybuf, sizeof(toybuf), "%d %d", window, pane); | ||
8050 | simd->paneID = qLuaGet(IDs, toybuf)->v.s; | ||
8051 | |||
8052 | I("%s is starting up in tab [%d:%s](pane %d), tmux ID = %s, from %s/sim%d.", name, window, type, pane, simd->paneID, scTemp, count); | ||
8053 | simd->portH = 8004 + count * 2; | ||
8054 | simd->portU = 8005 + count * 2; | ||
8055 | cmd = xmprintf("rm -fr %s/sim%d; mkdir -p %s/sim%d; sed -E" | ||
8056 | " -e 's@\\[Region\\]@" | ||
8057 | " paneID = \"\\%s\"\\n" | ||
8058 | "\\[Startup\\]\\n" | ||
8059 | " PIDFile = \"\\$\\{Paths\\|CachePath\\}\\/\\$\\{Const\\|mysim\\}\\.pid\"\\n" | ||
8060 | " LogFile = \"\\$\\{Paths\\|LogPath\\}\\/OpenSim_\\$\\{Const\\|mysim\\}\\.log\"\\n" | ||
8061 | " StatsLogFile = \"\\$\\{Paths\\|LogPath\\}\\/OpenSimStats_\\$\\{Const\\|mysim\\}\\.log\"\\n" | ||
8062 | " ConsoleHistoryFile = \"\\$\\{Paths\\|LogPath\\}\\/OpenSimConsoleHistory_\\$\\{Const\\|mysim\\}\\.txt\"\\n" | ||
8063 | "\\n\\[Region\\]@'" | ||
8064 | " -e 's/InternalPort[[:space:]]*=[[:space:]]*[[:digit:]]+/InternalPort = %d/'" | ||
8065 | " -e 's/InternalPort[[:space:]]*=[[:space:]]*\"[[:digit:]]+\"/InternalPort = %d/'" | ||
8066 | " -e 's/http_listener_port[[:space:]]*=[[:space:]]*[[:digit:]]+/http_listener_port = %d/'" | ||
8067 | " -e 's/http_listener_port[[:space:]]*=[[:space:]]*\"[[:digit:]]+\"/http_listener_port = %d/'" | ||
8068 | " %s >%s", | ||
8069 | scTemp, count, | ||
8070 | scTemp, count, | ||
8071 | simd->paneID, | ||
8072 | simd->portU, | ||
8073 | simd->portU, | ||
8074 | simd->portH, | ||
8075 | simd->portH, | ||
8076 | path, newPath); | ||
8077 | int j; | ||
8078 | |||
8079 | D("Writing .ini file %s with ports %d %d", newPath, 8004 + count * 2, 8005 + count * 2); | ||
8080 | j = system(cmd); | ||
8081 | if (!WIFEXITED(j)) | ||
8082 | E("sed command failed!"); | ||
8083 | free(cmd); | ||
8084 | |||
8085 | doTmuxCmd("select-pane -t %s:%s -T '%s'", Tconsole, simd->paneID, nm); | ||
8086 | { | 8108 | { |
8087 | snprintf(toybuf, sizeof(toybuf), "mono OpenSim.exe -inidirectory=%s/sim%d", scTemp, count); | 8109 | snprintf(toybuf, sizeof(toybuf), "mono OpenSim.exe -inidirectory=%s/sim%d", scTemp, count); |
8088 | sendTmuxCmd(simd->paneID, toybuf); | 8110 | sendTmuxCmd(simd->paneID, toybuf); |
8089 | if (0 == doWait) | 8111 | if (0 == doWait) |
8090 | { | 8112 | { |
8091 | snprintf(toybuf, sizeof(toybuf), "INITIALIZATION COMPLETE FOR %s", name); | 8113 | snprintf(toybuf, sizeof(toybuf), "INITIALIZATION COMPLETE FOR %s", simd->name); |
8092 | waitTmuxText(simd->paneID, toybuf); | 8114 | waitTmuxText(simd->paneID, toybuf); |
8093 | I("%s is done starting up.", name); | 8115 | I("%s is done starting up.", simd->name); |
8094 | la = waitLoadAverage(la, loadAverageInc, simTimeOut); | 8116 | la = waitLoadAverage(la, loadAverageInc, simTimeOut); |
8095 | } | 8117 | } |
8096 | count++; | 8118 | count++; |
8097 | doWait = (count % bulkSims); | 8119 | doWait = (count % bulkSims); |
8098 | } | 8120 | } |
8099 | free(newPath); | ||
8100 | free(path); | ||
8101 | } | 8121 | } |
8102 | break; | 8122 | break; |
8103 | } | 8123 | } |
8104 | 8124 | ||
8105 | case BACKUP : // "backup 'onefang rejected'" "backup sim01" "backup 'Welcome Sim'" "backup" backup everything | 8125 | case BACKUP : // "backup 'onefang rejected'" "backup sim01" "backup 'Welcome Sim'" "backup" backup everything |
8106 | { // TODO - If it's not a sim code, and not a sim name, it's an account inventory. | 8126 | { // TODO - If it's not a sim code, and not a sim name, it's an account inventory. |
8107 | if (checkSimIsRunning(nm)) | 8127 | if (checkSimIsRunning(simd->tab)) |
8108 | { | 8128 | { |
8109 | struct timeval tv; | 8129 | struct timeval tv; |
8110 | time_t curtime; | 8130 | time_t curtime; |
@@ -8119,15 +8139,15 @@ Also clear out tmp when doing a full stop. | |||
8119 | gettimeofday(&tv, NULL); | 8139 | gettimeofday(&tv, NULL); |
8120 | curtime = tv.tv_sec; | 8140 | curtime = tv.tv_sec; |
8121 | strftime(date, DATE_TIME_LEN, "%F_%T", localtime(&curtime)); | 8141 | strftime(date, DATE_TIME_LEN, "%F_%T", localtime(&curtime)); |
8122 | I("%s is being backed up to %s/backups/%s-%s.oar.", name, scRoot, nm, date); | 8142 | I("%s is being backed up to %s/backups/%s-%s.oar.", simd->name, scRoot, simd->tab, date); |
8123 | snprintf(toybuf, sizeof(toybuf), "save oar --all %s/backups/%s-%s.oar", scRoot, nm, date); | 8143 | snprintf(toybuf, sizeof(toybuf), "save oar --all %s/backups/%s-%s.oar", scRoot, simd->tab, date); |
8124 | sendTmuxCmd(cmd, toybuf); | 8144 | sendTmuxCmd(cmd, toybuf); |
8125 | // if (0 == doWait) | 8145 | // if (0 == doWait) |
8126 | { | 8146 | { |
8127 | memset(toybuf, 0, sizeof(toybuf)); | 8147 | memset(toybuf, 0, sizeof(toybuf)); |
8128 | snprintf(toybuf, sizeof(toybuf), "Finished writing out OAR for %s", name); | 8148 | snprintf(toybuf, sizeof(toybuf), "Finished writing out OAR for %s", simd->name); |
8129 | waitTmuxText(cmd, toybuf); | 8149 | waitTmuxText(cmd, toybuf); |
8130 | I("%s is done backing up.", name); | 8150 | I("%s is done backing up.", simd->name); |
8131 | // TODO - should delete / gitAR the old ones now. | 8151 | // TODO - should delete / gitAR the old ones now. |
8132 | // Have a config option for delete / gitAR. | 8152 | // Have a config option for delete / gitAR. |
8133 | la = waitLoadAverage(la, loadAverageInc, simTimeOut); | 8153 | la = waitLoadAverage(la, loadAverageInc, simTimeOut); |
@@ -8154,10 +8174,14 @@ Also clear out tmp when doing a full stop. | |||
8154 | 8174 | ||
8155 | case STOP : // "stop sim01" "stop 'Welcome Sim'" "stop" stop everything | 8175 | case STOP : // "stop sim01" "stop 'Welcome Sim'" "stop" stop everything |
8156 | { | 8176 | { |
8157 | if (checkSimIsRunning(nm)) | 8177 | if (checkSimIsRunning(simd->tab)) |
8158 | { | 8178 | { |
8179 | /* TODO - | ||
8180 | Leave empty panes as is. | ||
8181 | Don't bother to close panes unless we are doing a full stop. | ||
8182 | Also clear out tmp when doing a full stop. | ||
8183 | */ | ||
8159 | cmd = xmprintf("%d.%d", simd->window, simd->pane); | 8184 | cmd = xmprintf("%d.%d", simd->window, simd->pane); |
8160 | I("%s is stopping in pane %d.%d.", name, simd->window, simd->pane); | ||
8161 | sendTmuxCmd(cmd, "quit"); | 8185 | sendTmuxCmd(cmd, "quit"); |
8162 | free(cmd); | 8186 | free(cmd); |
8163 | // There's three things that might happen - | 8187 | // There's three things that might happen - |
@@ -8171,7 +8195,7 @@ Also clear out tmp when doing a full stop. | |||
8171 | // Could also loop on checkSimIsRunning(sim) | 8195 | // Could also loop on checkSimIsRunning(sim) |
8172 | // snprintf(toybuf, sizeof(toybuf), "[SHUTDOWN]: Shutdown processing on main thread complete. Exiting..."); | 8196 | // snprintf(toybuf, sizeof(toybuf), "[SHUTDOWN]: Shutdown processing on main thread complete. Exiting..."); |
8173 | // waitTmuxText(nm, toybuf); | 8197 | // waitTmuxText(nm, toybuf); |
8174 | // I("%s is done stopping.", name); | 8198 | // I("%s is done stopping.", simd->name); |
8175 | // la = waitLoadAverage(la, loadAverageInc, simTimeOut); | 8199 | // la = waitLoadAverage(la, loadAverageInc, simTimeOut); |
8176 | } | 8200 | } |
8177 | break; | 8201 | break; |
@@ -8183,24 +8207,22 @@ Also clear out tmp when doing a full stop. | |||
8183 | break; | 8207 | break; |
8184 | } | 8208 | } |
8185 | } | 8209 | } |
8186 | nextSim: | ||
8187 | pane++; | ||
8188 | if (pane >= panes) | ||
8189 | { | ||
8190 | pane = 0; | ||
8191 | window++; | ||
8192 | } | ||
8193 | //if (4 < number) break; | ||
8194 | } | ||
8195 | lua_pop(L, 1); // removes 'value'; keeps 'key' for next iteration | ||
8196 | } | 8210 | } |
8211 | |||
8197 | } | 8212 | } |
8198 | 8213 | ||
8199 | lua_pop(L, 1); | 8214 | pane++; |
8215 | if (pane >= panes) | ||
8216 | { | ||
8217 | pane = 0; | ||
8218 | window++; | ||
8219 | } | ||
8200 | } | 8220 | } |
8201 | } | 8221 | } |
8222 | q0->v.t->unlock(q0->v.t); | ||
8202 | } | 8223 | } |
8203 | } | 8224 | } |
8225 | ourSims->simsLua->unlock(ourSims->simsLua); | ||
8204 | 8226 | ||
8205 | 8227 | ||
8206 | if (START == currentMode) | 8228 | if (START == currentMode) |