From 08ab8230e191ab4f6bd8a3a873ab8c7811155580 Mon Sep 17 00:00:00 2001 From: onefang Date: Tue, 3 Aug 2021 17:03:30 +1000 Subject: Close all the sim panes at full stop, and related cleanups. --- src/sledjchisl/sledjchisl.c | 101 ++++++++++++++++++++++++++++++++------------ 1 file changed, 73 insertions(+), 28 deletions(-) (limited to 'src') diff --git a/src/sledjchisl/sledjchisl.c b/src/sledjchisl/sledjchisl.c index 373dbb3..4c7d45f 100644 --- a/src/sledjchisl/sledjchisl.c +++ b/src/sledjchisl/sledjchisl.c @@ -7253,7 +7253,6 @@ jit library is loaded or the JIT compiler will not be activated. // Other start up stuff. //////////////////////////////////////////////////////////////////////////////////////////////////// getSims(); - if (isTmux || isWeb) { char *d; @@ -8015,18 +8014,6 @@ fcgiDone: ourSims->simsLua->unlock(ourSims->simsLua); } -/* -sims = -- Note these are .shini / tmux tab short names. -{ - {['type'] = 'Welcome'; ['panes'] = 0; "Welcome"}, - {["type"] = "Important"; ["panes"] = 2; "Sandbox", "Shops"}, - {["type"] = "Rentals"; "Karen", "Bob"}, - {["type"] = "Freebies"; "Gifts", "Free"}, - {["type"] = "unsorted"; "New"}, -- NOTE - this is where new ones go to by default. - {["type"] = "Water"; ["number"] = 20; ["panes"] = 6; "Water0", "Water1", "Water2", "Water3", "Water4"}, - {["type"] = "Heavies"; ["number"] = 18; "DP", "ARSE"}, -} -*/ //////////////////////////////////////////////////////////////////////////////////////////////////// // Sim wrangling loop. @@ -8132,8 +8119,6 @@ sims = -- Note these are .shini / tmux tab short names. time_t curtime; char date[DATE_TIME_LEN]; - 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. // strip off the last bit of file name (YYYY-mm-dd_HH:MM:SS.oar) to get the name @@ -8143,7 +8128,7 @@ sims = -- Note these are .shini / tmux tab short names. strftime(date, DATE_TIME_LEN, "%F_%T", localtime(&curtime)); I("%s is being backed up to %s/backups/%s-%s.oar.", simd->name, scRoot, simd->tab, date); snprintf(toybuf, sizeof(toybuf), "save oar --all %s/backups/%s-%s.oar", scRoot, simd->tab, date); - sendTmuxCmd(cmd, toybuf); + sendTmuxCmd(simd->paneID, toybuf); // if (0 == doWait) { memset(toybuf, 0, sizeof(toybuf)); @@ -8154,7 +8139,6 @@ sims = -- Note these are .shini / tmux tab short names. // Have a config option for delete / gitAR. la = waitLoadAverage(la, loadAverageInc, simTimeOut); } - free(cmd); } break; } @@ -8178,14 +8162,8 @@ sims = -- Note these are .shini / tmux tab short names. { if (checkSimIsRunning(simd->tab)) { -/* TODO - -Leave empty panes as is. -Don't bother to close panes unless we are doing a full stop. -Also clear out tmp when doing a full stop. -*/ - cmd = xmprintf("%d.%d", simd->window, simd->pane); - sendTmuxCmd(cmd, "quit"); - free(cmd); + // Leave empty panes as is. + sendTmuxCmd(simd->paneID, "quit"); // There's three things that might happen - // Sim will quit, tmux pane will go away before we can see the shutdown message. // pane-exited hook might be useful here. @@ -8193,7 +8171,7 @@ Also clear out tmp when doing a full stop. // 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. +// TODO - cater for and test them all. // Could also loop on checkSimIsRunning(sim) // snprintf(toybuf, sizeof(toybuf), "[SHUTDOWN]: Shutdown processing on main thread complete. Exiting..."); // waitTmuxText(nm, toybuf); @@ -8247,8 +8225,75 @@ Also clear out tmp when doing a full stop. } 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. + I("Closing all the panes."); + memset((void*)&obj0, 0, sizeof(obj0)); + ourSims->simsLua->lock(ourSims->simsLua); + while(ourSims->simsLua->getnext(ourSims->simsLua, &obj0, false) == true) + { + q0 = obj0.data; + char *type = "unsorted"; + + if (LUA_TTABLE == q0->type) + { + panes = 4; + q1 = q0->v.t->get(q0->v.t, "number", NULL, false); if (NULL != q1) window = q1->v.f - 1; + q1 = q0->v.t->get(q0->v.t, "panes", NULL, false); if (NULL != q1) panes = q1->v.f; + q1 = q0->v.t->get(q0->v.t, "type", NULL, false); if (NULL != q1) type = q1->v.s; + if (0 == panes) + { + pane = 2; + window = 0; + type = Ttab; + } + else if (0 != pane) + { + pane = 0; + window++; + } + + memset((void*)&obj1, 0, sizeof(obj1)); + q0->v.t->lock(q0->v.t); + while(q0->v.t->getnext(q0->v.t, &obj1, false) == true) + { + q1 = obj1.data; + + if ((strcmp("number", obj1.name) != 0) && (strcmp("panes", obj1.name) != 0) && (strcmp("type", obj1.name) != 0)) + { + char *sim = q1->v.s; + qlisttbl_t *ini = ourSims->byTab->get(ourSims->byTab, sim, NULL, false); + + if (NULL == ini) + E("Sim %s not found in ini list!", sim); + else + { + simData *simd = ini->get(ini, "SIM DATA", NULL, false); + + while (checkSimIsRunning(simd->tab)) + sleep(1); + sleep(1); + sendTmuxCmd(simd->paneID, "exit"); + I("Tmux tab [%d:%s](pane %d) tmux ID %s, from %s/sim%d - %s has stopped.", window, type, pane, simd->paneID, scTemp, count, simd->name); + + count++; + pane++; + if (pane >= panes) + { + pane = 0; + window++; + } + } + } + } + q0->v.t->unlock(q0->v.t); + } + } + ourSims->simsLua->unlock(ourSims->simsLua); + + char *c = xmprintf("rm -fr %s/*", scTemp); + if (!WIFEXITED(system(c))) + E("rrm command failed! %s", c); + free(c); + } //////////////////////////////////////////////////////////////////////////////////////////////////// // End of OpenSim wrangling section. -- cgit v1.1