From 4f782a3476193eb9d4913bebd19dc9d8c27f9ddf Mon Sep 17 00:00:00 2001 From: onefang Date: Tue, 27 Jul 2021 07:12:47 +1000 Subject: Rejig the windows and panes, as well as strip boiler plate from .ini files. --- src/sledjchisl/sledjchisl.c | 193 ++++++++++++++++++++++++++++---------------- 1 file changed, 122 insertions(+), 71 deletions(-) (limited to 'src') diff --git a/src/sledjchisl/sledjchisl.c b/src/sledjchisl/sledjchisl.c index e6caa67..42d4547 100644 --- a/src/sledjchisl/sledjchisl.c +++ b/src/sledjchisl/sledjchisl.c @@ -713,7 +713,7 @@ struct _simData // portH is the HTTP port for the sim, portI is the UDP port for the sim. int num, locX, locY, sizeX, sizeY, sizeZ, portH, portI, maxPrims; char *name, *tab, *UUID, *regionType, *estate, *owner; - int win, pane; + int window, pane; // char *nmbr; }; @@ -877,6 +877,11 @@ ourSims->tbl->put(ourSims->tbl, sim, ini, sizeof(qlisttbl_t)); " -e 's#\\[Const]#\\[Const] ; fakeVariableCozOpenSim='' ; pushd ../current/bin; ./sledjchisl $1 `basename $0`; popd ; exit 0#'" " -e 's/mysim=\"[[:digit:]]*\"/mysim=\"%s\"/'" " -e 's/sim\\$\\{Const\\|mysim\\}/\\$\\{Const\\|mysim\\}/g'" + " -e '/\\[Startup\\]/d'" + " -e '/PIDFile.*/d'" + " -e '/LogFile.*/d'" + " -e '/StatsLogFile.*/d'" + " -e '/ConsoleHistoryFile.*/d'" " %s >%s", simd->tab, path, newPath); I("Writing .shini file %s", newPath); @@ -7569,15 +7574,15 @@ sims = -- Note these are .shini / tmux tab short names. {["type"] = "Rentals"; "Karen", "Bob"}, {["type"] = "Freebies"; "Gifts", "Free"}, {["type"] = "unsorted"; "New"}, -- NOTE - this is where new ones go to by default. - {["type"] = "Water"; ["number"] = 90; ["panes"] = 6; "Water0", "Water1", "Water2", "Water3", "Water4"}, - {["type"] = "Heavies"; ["number"] = 70; "DP", "ARSE"}, + {["type"] = "Water"; ["number"] = 20; ["panes"] = 6; "Water0", "Water1", "Water2", "Water3", "Water4"}, + {["type"] = "Heavies"; ["number"] = 18; "DP", "ARSE"}, } */ memset(toybuf, 0, sizeof(toybuf)); snprintf(toybuf, sizeof(toybuf), "%s/sims.lua", scEtc); if (0 == lstat(toybuf, &st)) { - int number = 1, count = 1; + int count = 0, window = 0, panes = 4, pane = 0; I("Loading configuration file - %s", toybuf); status = luaL_loadfile(L, toybuf); @@ -7598,22 +7603,27 @@ sims = -- Note these are .shini / tmux tab short names. if (lua_istable(L, -1)) { const char *type = "unsorted"; - int panes = 4, win = 0, startNum = 0, pane = 0; + panes = 4; lua_getfield(L, -1, "type"); lua_getfield(L, -2, "number"); lua_getfield(L, -3, "panes"); if (LUA_TNIL != lua_type(L, -3)) type = lua_tostring(L, -3); - if (LUA_TNIL != lua_type(L, -2)) number = lua_tonumber(L, -2); + if (LUA_TNIL != lua_type(L, -2)) window = lua_tonumber(L, -2) - 1; if (LUA_TNIL != lua_type(L, -1)) panes = lua_tonumber(L, -1); lua_pop(L, 3); - startNum = number; - if (panes) - win = startNum - 1; - else + if (0 == panes) + { pane = 2; + window = 0; + } + else if (0 != pane) + { + pane = 0; + window++; + } - T("Doing sims of type %s starting at number %d, window %d, %d panes per window", type, startNum, win, panes); + T("Doing sims of type %s, window %d, %d panes per window", type, window, panes); lua_pushnil(L); while(lua_next(L, -2) != 0) { @@ -7636,7 +7646,7 @@ sims = -- Note these are .shini / tmux tab short names. simd = ini->get(ini, "SIM DATA", NULL, false); name = simd->name; nm = simd->tab; - simd->win = win; + simd->window = window; simd->pane = pane; } @@ -7660,14 +7670,13 @@ sims = -- Note these are .shini / tmux tab short names. if (strcmp(target, toybuf) == 0) cont = FALSE; memset(toybuf, 0, sizeof(toybuf)); - snprintf(toybuf, sizeof(toybuf), "sim%d.ini", number); + snprintf(toybuf, sizeof(toybuf), "sim%d.ini", count); if (strcmp(target, toybuf) == 0) cont = FALSE; if (cont) goto nextSim; } - doWait = (count % bulkSims); switch (currentMode) { case START : // "start sim01" "start 'Welcome sim'" "start Welcome.ini" "start Welcome" "start" start everything @@ -7675,62 +7684,91 @@ sims = -- Note these are .shini / tmux tab short names. if (!checkSimIsRunning(nm)) { char *path = xmprintf("%s/%s.shini", scEtc, nm); - char *newPath = xmprintf("%s/sim%d/%s.ini", scTemp, number, nm); // Coz OpenSim. - char *cmd = xmprintf("rm -fr %s/sim%d; mkdir -p %s/sim%d; sed -E" - " -e 's/InternalPort[[:space:]]*=[[:space:]]*[[:digit:]]+/InternalPort = %d/'" - " -e 's/InternalPort[[:space:]]*=[[:space:]]*\"[[:digit:]]+\"/InternalPort = %d/'" - " -e 's/http_listener_port[[:space:]]*=[[:space:]]*[[:digit:]]+/http_listener_port = %d/'" - " -e 's/http_listener_port[[:space:]]*=[[:space:]]*\"[[:digit:]]+\"/http_listener_port = %d/'" - " %s >%s", - scTemp, number, - scTemp, number, - 8004 + number * 2, - 8004 + number * 2, - 8005 + number * 2, - 8005 + number * 2, - path, newPath); - int j; - - D("Writing .ini file %s with ports %d %d", newPath, 8004 + number * 2, 8005 + number * 2); - j = system(cmd); - if (!WIFEXITED(j)) - E("sed command failed!"); - free(cmd); + char *newPath = xmprintf("%s/sim%d/%s.ini", scTemp, count, nm); // Coz OpenSim. - I("%s is starting up in tab [%d:%s] pane .%d, from %s/sim%d.", name, win, type, pane, scTemp, number); memset(toybuf, 0, sizeof(toybuf)); if (0 == panes) doTmuxCmd("split-window -hp 50 -d -t '%s:0.1'", Tconsole); else if (0 == pane) { - doTmuxCmd("new-window -dc '%s/current/bin' -n '%s' -t '%s:%d'", scRoot, type, Tconsole, win); + doTmuxCmd("new-window -dc '%s/current/bin' -n '%s' -t '%s:%d'", scRoot, type, Tconsole, window); if (2 <= panes) - doTmuxCmd("split-window -hp 50 -d -t '%s:%d.0'", Tconsole, win); + doTmuxCmd("split-window -hp 50 -d -t '%s:%d.0'", Tconsole, window); if (4 <= panes) { - doTmuxCmd("split-window -vp 50 -d -t '%s:%d.1'", Tconsole, win); - doTmuxCmd("split-window -vp 50 -d -t '%s:%d.0'", Tconsole, win); + doTmuxCmd("split-window -vp 50 -d -t '%s:%d.1'", Tconsole, window); + doTmuxCmd("split-window -vp 50 -d -t '%s:%d.0'", Tconsole, window); } if (8 <= panes) { - doTmuxCmd("split-window -hp 50 -d -t '%s:%d.3'", Tconsole, win); - doTmuxCmd("split-window -hp 50 -d -t '%s:%d.2'", Tconsole, win); - doTmuxCmd("split-window -hp 50 -d -t '%s:%d.1'", Tconsole, win); - doTmuxCmd("split-window -hp 50 -d -t '%s:%d.0'", Tconsole, win); + doTmuxCmd("split-window -hp 50 -d -t '%s:%d.3'", Tconsole, window); + doTmuxCmd("split-window -hp 50 -d -t '%s:%d.2'", Tconsole, window); + doTmuxCmd("split-window -hp 50 -d -t '%s:%d.1'", Tconsole, window); + doTmuxCmd("split-window -hp 50 -d -t '%s:%d.0'", Tconsole, window); } -/* +/* TODO - tmux -S /opt/opensim_SC-DG/var/run/opensim-tmux.socket list-panes -t 31 -F '#{pane_index} #{pane_id}' 0 %39 1 %42 2 %40 3 %41 + +I can get the tabs to show their ID. session:window.pane $sessionID $=ExactSessionMatch @windowID @=ExactWindowMatch %paneID + "The pane ID is passed to the child process of the pane in the TMUX_PANE environment variable." + Tuck the window and pane ID into the tmp ini file we are about to make, so other runs of sledjchisl can find it. + +Leave empty panes as is. +Don't bother to close panes unless we are doing a full stop. + +Is there a "switch to pane 1" command? Nope + Ctrc A digit Move to that numbered window. + Ctrl A arrow key Move to the pane in that direction. + Ctrl A n Move to the next window. + Ctrl A p Move to the previous window. + Ctrl A w Choose the current window interactively. + Ctrl A o Move to the next pane. + Ctrl A ; Move to the previously selected pane. + Ctrl A l Move to the previously selected window. + Ctrl A Ctrl o Rotate panes"forwards". I do this accidently sometimes, coz MC. + Ctrl A Alt o Rotate panes"backwards". + Ctrl A z Toggle zooming into the current pane. */ } - cmd = xmprintf("%d.%d", simd->win, simd->pane); + I("%s is starting up in tab [%d:%s] pane .%d, from %s/sim%d.", name, window, type, pane, scTemp, count); + + char *cmd = xmprintf("rm -fr %s/sim%d; mkdir -p %s/sim%d; sed -E" + " -e 's@\\[Region\\]@" + "\\[Startup\\]\\n" + " PIDFile = \"\\$\\{Paths\\|CachePath\\}\\/\\$\\{Const\\|mysim\\}\\.pid\"\\n" + " LogFile = \"\\$\\{Paths\\|LogPath\\}\\/OpenSim_\\$\\{Const\\|mysim\\}\\.log\"\\n" + " StatsLogFile = \"\\$\\{Paths\\|LogPath\\}\\/OpenSimStats_\\$\\{Const\\|mysim\\}\\.log\"\\n" + " ConsoleHistoryFile = \"\\$\\{Paths\\|LogPath\\}\\/OpenSimConsoleHistory_\\$\\{Const\\|mysim\\}\\.txt\"\\n" + "\\n\\[Region\\]@'" + " -e 's/InternalPort[[:space:]]*=[[:space:]]*[[:digit:]]+/InternalPort = %d/'" + " -e 's/InternalPort[[:space:]]*=[[:space:]]*\"[[:digit:]]+\"/InternalPort = %d/'" + " -e 's/http_listener_port[[:space:]]*=[[:space:]]*[[:digit:]]+/http_listener_port = %d/'" + " -e 's/http_listener_port[[:space:]]*=[[:space:]]*\"[[:digit:]]+\"/http_listener_port = %d/'" + " %s >%s", + scTemp, count, + scTemp, count, + 8004 + count * 2, + 8004 + count * 2, + 8005 + count * 2, + 8005 + count * 2, + path, newPath); + int j; + + D("Writing .ini file %s with ports %d %d", newPath, 8004 + count * 2, 8005 + count * 2); + j = system(cmd); + if (!WIFEXITED(j)) + E("sed command failed!"); + free(cmd); + + cmd = xmprintf("%d.%d", simd->window, simd->pane); doTmuxCmd("select-pane -t %s:%s -T '%s'", Tconsole, cmd, nm); { memset(toybuf, 0, sizeof(toybuf)); - snprintf(toybuf, sizeof(toybuf), "mono OpenSim.exe -inidirectory=%s/sim%d; exit", scTemp, number); + snprintf(toybuf, sizeof(toybuf), "mono OpenSim.exe -inidirectory=%s/sim%d", scTemp, count); sendTmuxCmd(cmd, toybuf); if (0 == doWait) { @@ -7741,6 +7779,7 @@ tmux -S /opt/opensim_SC-DG/var/run/opensim-tmux.socket list-panes -t 31 -F '#{pa la = waitLoadAverage(la, loadAverageInc, simTimeOut); } count++; + doWait = (count % bulkSims); } free(cmd); free(newPath); @@ -7757,7 +7796,7 @@ tmux -S /opt/opensim_SC-DG/var/run/opensim-tmux.socket list-panes -t 31 -F '#{pa time_t curtime; char date[DATE_TIME_LEN]; - cmd = xmprintf("%d.%d", simd->win, simd->pane); + cmd = xmprintf("%d.%d", simd->window, simd->pane); // TODO - should collect names of existing backups, both tmux / ini name and proper name. // Scan backups directory once before this for loop, add details to sims list. @@ -7804,14 +7843,16 @@ tmux -S /opt/opensim_SC-DG/var/run/opensim-tmux.socket list-panes -t 31 -F '#{pa { if (checkSimIsRunning(nm)) { - cmd = xmprintf("%d.%d", simd->win, simd->pane); - I("%s is stopping in pane .", name, simd->win, simd->pane); + cmd = xmprintf("%d.%d", simd->window, simd->pane); + I("%s is stopping in pane %d.%d.", name, simd->window, simd->pane); sendTmuxCmd(cmd, "quit"); free(cmd); // There's three things that might happen - - // Sim will quit, tmux tab will go away before we can see the shutdown message. - // Sim will quit, tmux tab wont go away. Dunno yet if waitTmuxText() will still work. - // Sim fails to quit, error message on the tab that we want to read, wont see the shutdown message. + // Sim will quit, tmux pane will go away before we can see the shutdown message. + // pane-exited hook might be useful here. + // Sim will quit, tmux pane wont go away. Dunno yet if waitTmuxText() will still work. + // pane-died hook might be useful here. + // Sim fails to quit, error message on the pane that we want to read, wont see the shutdown message. // Also sim might not have finished starting up, and may even not be accepting comands yet. // TODO - cater for and test them all. // Could also loop on checkSimIsRunning(sim) @@ -7831,12 +7872,14 @@ tmux -S /opt/opensim_SC-DG/var/run/opensim-tmux.socket list-panes -t 31 -F '#{pa } } nextSim: - number++; - if (panes) +// if (panes) { - pane = (number - startNum) % panes; - if (0 == pane) - win++; + pane++; + if (pane >= panes) + { + pane = 0; + window++; + } } //if (4 < number) break; } @@ -7851,21 +7894,29 @@ nextSim: } - if ((START == currentMode) && checkSimIsRunning("ROBUST") && (NULL == target)) + if (START == currentMode) { - // Start up the web stuff. TODO - remove this once we handle the fcgi stuff ourselves. - I("Starting the web stuff."); - char *d = xmprintf("%s.{bottom}", Ttab); - char *c = xmprintf("cd %s/current/src;" - " spawn-fcgi -n -u %s -s %s/sledjchisl.socket -M 0660 -G www-data -- " - "/usr/bin/valgrind --leak-check=full build/toybox/generated/unstripped/toybox sledjchisl", - scRoot, scUser, scCache); - sendTmuxCmd(d, c); - free(c); - free(d); + if (checkSimIsRunning("ROBUST") && (NULL == target)) + { + // Start up the web stuff. TODO - remove this once we handle the fcgi stuff ourselves. + I("Starting the web stuff."); + char *d = xmprintf("%s.{bottom}", Ttab); + char *c = xmprintf("cd %s/current/src;" + " spawn-fcgi -n -u %s -s %s/sledjchisl.socket -M 0660 -G www-data -- " + "/usr/bin/valgrind --leak-check=full build/toybox/generated/unstripped/toybox sledjchisl", + scRoot, scUser, scCache); + sendTmuxCmd(d, c); + free(c); + free(d); + } + else + I("NOT Starting the web stuff."); + } + else if ((STOP == currentMode) && (NULL == target)) + { +I("Closing all the panes."); +// TODO - Wait for all the sims to stop, close all the sim panes, even the empty ones. } - else - I("NOT Starting the web stuff."); /* -- cgit v1.1