From 189f6b9e19c20ac39aa72cf94982d72ed5f78e0a Mon Sep 17 00:00:00 2001 From: onefang Date: Tue, 10 Aug 2021 17:25:38 +1000 Subject: getSims() now does all the converting of old .ini files to new .shini and sims.lua files. Also had to do some shifting of functions, and several other related tweaks. --- src/sledjchisl/sledjchisl.c | 581 +++++++++++++++++++++++++++----------------- 1 file changed, 363 insertions(+), 218 deletions(-) (limited to 'src') diff --git a/src/sledjchisl/sledjchisl.c b/src/sledjchisl/sledjchisl.c index 8b63866..057e5c3 100644 --- a/src/sledjchisl/sledjchisl.c +++ b/src/sledjchisl/sledjchisl.c @@ -1090,11 +1090,11 @@ struct _simList { int len, num; char **sims; - qtreetbl_t *byTab, *simsLua; - // Stuff for the looping through sims doing things and waiting. - char *target; + qtreetbl_t *byTab, *simsLua, *unsorted; + // Stuff for the looping through sims, doing things, and waiting. + int doIt; float la; - int doWait; + char *target; }; simList *ourSims = NULL; @@ -1163,86 +1163,201 @@ static int filterInis(struct dirtree *node) return 0; } -// Get the details from all the .ini or .shini sim files. -// Creates the .shini and sims.lua files if it's an old install. -// TODO - read the .shini and if it exists. -/* -ourSims shall be - - int len, num; - char **sims; - qtreetbl_t *byTab, *simsLua; - -byTab has the short name as the key, simData as the value. - Iterate through it looking for target sims if specified in the sledjchisl arguments. - Which can be short name, long name, foo.shini file name. - Though short name is a direct lookup, and "foo.shini" we can strip off the .shini and direct lookup the short name. - So only need to iterate if it's a long name. - Keep in mind the argument might be a user name for IAR backups. Or perhaps a UUID. - -**sims will be in sims.lua order, and maybe include a pointer to the simData. - We really only need to iterate through this at full start up and reverse iterate through it at full shutdown. - So just the tab names in the correct order is fine. - - -if sims.lua doesn't exist - create blank one -else - read it -loop through old config/sim* - if it's not a *.shini file - read *.ini - create *.shini - write *.shini - else - read the *.shini file - add *.shini to ourSims - if it's not in sims.lua, add it to unsorted -write sims.lua if it changed -reorder **sims +static int filterShinis(struct dirtree *node) +{ + if (!node->parent) return DIRTREE_RECURSE | DIRTREE_SHUTUP; + int l = strlen(node->name); + if ((6 < l) && ((strncmp(&(node->name[l - 6]), ".shini", 6) == 0))) + { + simList *list = (simList *) node->parent->extra; -*/ -simList *getSims() + if ((list->num + 1) > list->len) + { + list->len = list->len + 1; + list->sims = xrealloc(list->sims, list->len * sizeof(char *)); + } + list->sims[list->num] = xstrndup(node->name, l - 6); + list->num++; + } + return 0; +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// +// Sim wrangling loop. +//////////////////////////////////////////////////////////////////////////////////////////////////// +typedef void (*simFunction)(simData *simd, char *sim, char *type, int count, int window, int panes, int pane); +void forEachSim(char *verb, simFunction func, simFunction not) { - if (NULL != ourSims) return ourSims; + qtreetbl_obj_t obj0, obj1; + qLua *q0, *q1; + int count = 0, window = 0, panes = 4, pane = 0; - char *path = xmprintf("%s/config", scRoot), *newPath; - struct dirtree *new = dirtree_add_node(0, path, 0); - int i, j; + 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"; - ourSims = xzalloc(sizeof(simList)); - ourSims->byTab = qtreetbl(0); - new->extra = (long) ourSims; - dirtree_handle_callback(new, filterSims); + 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++; + } + + if (verb) + V("%s sims of type %s, window %d, %d panes per window.", verb, type, window, panes); + 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)) + { + simData *simd = ourSims->byTab->get(ourSims->byTab, q1->v.s, NULL, false); + + if (NULL == simd) + { + if (not) + not(simd, q1->v.s, type, count, window, panes, pane); + else + E("Sim %s not found in ini list!", q1->v.s); + } + else + { + func(simd, q1->v.s, type, count, window, panes, pane); + count++; + pane++; + if (pane >= panes) + { + pane = 0; + window++; + } + } + } + } + q0->v.t->unlock(q0->v.t); + } + } + ourSims->simsLua->unlock(ourSims->simsLua); +} + +void simNotFound(simData *simd, char *sim, char *type, int count, int window, int panes, int pane) +{ + char *path = xmprintf("%s/%s.shini", scEtc, sim); + qlisttbl_t *ini = qconfig_parse_file(NULL, path, '='); + + if (NULL == ini) + E("Can't find %s", path); + else + { + simd = xzalloc(sizeof(simData)); + simd->tab = sim; + simd->name = qstrunchar(ini->getstr(ini, "Region.RegionName", true), '"', '"'); + simd->UUID = qstrunchar(ini->getstr(ini, "Region.RegionUUID", true), '"', '"'); +// simd->regionType = qstrunchar(ini->getstr(ini, "Region.RegionType", true), '"', '"'); + simd->sizeX = getIntFromIni(ini, "Region.SizeX"); + simd->sizeY = getIntFromIni(ini, "Region.SizeY"); + simd->sizeZ = getIntFromIni(ini, "Region.SizeZ"); +// TODO - store a pointer instead of multiple copies of the data. + ourSims->byTab->put(ourSims->byTab, sim, simd, sizeof(simData)); + if (strcmp("unsorted", type) == 0) + ourSims->unsorted->put(ourSims->unsorted, sim, simd, sizeof(simData)); + ini->free(ini); + free(simd); + } free(path); +} - char *file = xmprintf("%s/sims.lua", scEtc); - char *tnm = "sims = -- Note these are .shini / tmux tab short names.\n{\n {['type'] = 'unsorted';\n"; - struct stat st; - int s = stat(file, &st); - int fd = -1; - size_t l = strlen(tnm); - ourSims->simsLua = Lua2tree(file, "sims"); -// dumpLuaTree(ourSims->simsLua, "simsLua", 0); +void freeSimList(simList *sims) +{ + int i; - if (s) + for (i = 0; i < sims->num; i++) + free(sims->sims[i]); + free(sims->sims); + + qtreetbl_obj_t obj; + memset((void*) &obj, 0, sizeof(obj)); // start from the minimum. + sims->byTab->lock(sims->byTab); + while (sims->byTab->getnext(sims->byTab, &obj, false) == true) { - I("Creating sims %s.", file); - fd = notstdio(xcreate_stdio(file, O_CREAT | O_WRONLY | O_TRUNC | O_CLOEXEC, S_IRUSR | S_IWUSR)); + char *name = qmemdup(obj.name, obj.namesize); // keep the name + size_t namesize = obj.namesize; // for removal argument + { + simData *simd = (simData *) obj.data; + + if (NULL != simd) + { + free(simd->name); +// free(simd->tab); + free(simd->UUID); +// free(simd->regionType); + free(simd->estate); + free(simd->owner); + free(simd->paneID); + } + } +// sims->byTab->remove_by_obj(sims->byTab, obj.name, obj.namesize); // remove +// obj = sims->byTab->find_nearest(sims->byTab, name, namesize, false); // rewind one step back + free(name); // clean up } + sims->byTab->unlock(sims->byTab); + sims->byTab->free(sims->byTab); + freeLuaTree(sims->simsLua); + freeLuaTree(sims->unsorted); + + free(sims); +} + +// Get the details from all the .ini or .shini sim files. +// Creates the .shini and sims.lua files if it's an old install. +simList *getSims() +{ + if (NULL != ourSims) return ourSims; + + int i, fd = -1; + size_t l; + char *file = xmprintf("%s/sims.lua", scEtc); + + ourSims = xzalloc(sizeof(simList)); + ourSims->byTab = qtreetbl(0); + ourSims->unsorted = qtreetbl(0); + ourSims->doIt = FALSE; - if (-1 != fd) + // Read or create simsLua + ourSims->simsLua = Lua2tree(file, "sims"); + if (NULL == ourSims->simsLua) { - if (l != writeall(fd, tnm, l)) - perror_msg("Writing %s", file); + ourSims->simsLua = qtreetbl(0); + ourSims->doIt = TRUE; } + // Find all the old .ini files, convert them to .shini files if they don't exist. + char *path = xmprintf("%s/config", scRoot), *newPath; + struct dirtree *new = dirtree_add_node(0, path, 0); + new->extra = (long) ourSims; + dirtree_handle_callback(new, filterSims); + free(path); for (i = 0; i < ourSims->num; i++) { char *sim = ourSims->sims[i], *name = xmprintf("%s/config/%s", scRoot, sim); qlisttbl_t *ini; - simData *simd = xzalloc(sizeof(simData)); struct dirtree *new = dirtree_add_node(0, name, 0); free(name); @@ -1253,20 +1368,10 @@ simList *getSims() { path = xmprintf("%s/config/%s/%s.ini", scRoot, sim, name); newPath = xmprintf("%s/%s.shini", scEtc, name); - d("Reading .ini file %s", path); - ini = qconfig_parse_file(NULL, path, '='); - simd->name = qstrunchar(ini->getstr(ini, "Region.RegionName", true), '"', '"'); - simd->UUID = qstrunchar(ini->getstr(ini, "Region.RegionUUID", true), '"', '"'); - simd->regionType = qstrunchar(ini->getstr(ini, "Region.RegionType", true), '"', '"'); - simd->sizeX = getIntFromIni(ini, "Region.SizeX"); - simd->sizeY = getIntFromIni(ini, "Region.SizeY"); - simd->sizeZ = getIntFromIni(ini, "Region.SizeZ"); - simd->tab = name; - ourSims->byTab->put(ourSims->byTab, name, simd, sizeof(simData)); - - if ((!qfile_exist(newPath))) + + if (!qfile_exist(newPath)) { - char *cmd = xmprintf("sed -E" + char *cmd = xmprintf("sed -E" " -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'" @@ -1275,100 +1380,206 @@ simList *getSims() " -e '/LogFile.*/d'" " -e '/StatsLogFile.*/d'" " -e '/ConsoleHistoryFile.*/d'" - " %s >%s", simd->tab, path, newPath); + " %s >%s", name, path, newPath); - I("Writing .shini file %s", newPath); + V("Converting %s.ini -> %s", path, newPath); D(cmd); - j = system(cmd); - if (!WIFEXITED(j)) + if (!WIFEXITED(system(cmd))) E("sed command failed!"); else { free(cmd); cmd = xmprintf("chmod ugo+x %s", newPath); - j = system(cmd); - if (!WIFEXITED(j)) + if (!WIFEXITED(system(cmd))) E("chmod command failed!"); + free(cmd); - char *link = xmprintf("%s/%s.shini", scBin, simd->tab); + char *link = xmprintf("%s/%s.shini", scBin, name); I("Symlinking %s to %s", newPath, link); + if (qfile_exist(link)) + { + cmd = xmprintf("rm %s", link); + if (!WIFEXITED(system(cmd))) + E("rm command failed!"); + free(cmd); + } if (0 != symlink(newPath, link)) perror_msg("Symlinking %s to %s", newPath, link); free(link); } - free(cmd); } - ini->free(ini); free(newPath); free(path); } - else - free(name); + free(name); + } +// dumpLuaTree(ourSims->simsLua, "simsLua", 0); +// dumpLuaTree(ourSims->byTab, "byTab", 0); - if (-1 != fd) + // Read all the .shini files. + forEachSim(NULL, NULL, simNotFound); +// dumpLuaTree(ourSims->simsLua, "simsLua", 0); +// dumpLuaTree(ourSims->byTab, "byTab", 0); +// dumpLuaTree(ourSims->unsorted, "unsorted", 0); + + // Check for any .shini files not in sims.lua, add them to the unsorted list. + for (i = 0; i < ourSims->num; i++) + free(ourSims->sims[i]); + ourSims->num = 0; + new = dirtree_add_node(0, scEtc, 0); + new->extra = (long) ourSims; + dirtree_handle_callback(new, filterShinis); + for (i = 0; i < ourSims->num; i++) + { + simData *simd = ourSims->byTab->get(ourSims->byTab, ourSims->sims[i], NULL, false); + if (NULL == simd) { - tnm = xmprintf(" '%s', \n", simd->tab); - l = strlen(tnm); - if (l != writeall(fd, tnm, l)) - perror_msg("Writing %s", file); - free(tnm); + V("Shini NOT found in list - %s/%s.shini", scEtc, ourSims->sims[i]); + simNotFound(simd, ourSims->sims[i], "unsorted", 0, 0, 0, 0); + ourSims->doIt = TRUE; } - - free(simd); } +// dumpLuaTree(ourSims->simsLua, "simsLua", 0); +// dumpLuaTree(ourSims->byTab, "byTab", 0); +// dumpLuaTree(ourSims->unsorted, "unsorted", 0); - if (-1 != fd) + // Write the sims.lua_NEW file if needed. + if (ourSims->doIt) { - tnm = " },\n}\nreturn sims\n"; - l = strlen(tnm); - if (l != writeall(fd, tnm, l)) - perror_msg("Writing %s", file); - - xclose(fd); - } - free(file); - - return ourSims; -} + char *tnm = xmprintf("mv -f %s/sims.lua %s/sims.lua.BACKUP", scEtc, scEtc); -void freeSimList(simList *sims) -{ - int i; + if (!WIFEXITED(system(tnm))) + E("mv command failed!"); + free(tnm); - for (i = 0; i < sims->num; i++) - free(sims->sims[i]); - free(sims->sims); + free(file); + file = xmprintf("%s/sims.lua", scEtc); + I("Creating sims %s.", file); - qtreetbl_obj_t obj; - memset((void*) &obj, 0, sizeof(obj)); // start from the minimum. - sims->byTab->lock(sims->byTab); - while (sims->byTab->getnext(sims->byTab, &obj, false) == true) - { - char *name = qmemdup(obj.name, obj.namesize); // keep the name - size_t namesize = obj.namesize; // for removal argument + fd = notstdio(xcreate_stdio(file, O_CREAT | O_WRONLY | O_TRUNC | O_CLOEXEC, S_IRUSR | S_IWUSR)); + if (-1 != fd) { - simData *simd = (simData *) obj.data; + tnm = "sims = -- Note these are .shini / tmux tab short names.\n{\n"; + l = strlen(tnm); + if (l != writeall(fd, tnm, l)) + perror_msg("Writing %s", file); - if (NULL != simd) + qtreetbl_obj_t obj0, obj1; + qLua *q0, *q1; + + memset((void*)&obj0, 0, sizeof(obj0)); + ourSims->simsLua->lock(ourSims->simsLua); + while(ourSims->simsLua->getnext(ourSims->simsLua, &obj0, false) == true) { - free(simd->name); - free(simd->tab); - free(simd->UUID); - free(simd->regionType); - free(simd->estate); - free(simd->owner); - free(simd->paneID); + q0 = obj0.data; + char *type = "unsorted"; + + if (LUA_TTABLE == q0->type) + { + tnm = " {"; + l = strlen(tnm); + if (l != writeall(fd, tnm, l)) + perror_msg("Writing %s", file); + q1 = q0->v.t->get(q0->v.t, "type", NULL, false); + if (NULL != q1) + { + type = q1->v.s; + tnm = xmprintf("['type'] = '%s'; ", type); + l = strlen(tnm); + if (l != writeall(fd, tnm, l)) + perror_msg("Writing %s", file); + free(tnm); + } + q1 = q0->v.t->get(q0->v.t, "number", NULL, false); + if (NULL != q1) + { + tnm = xmprintf("['number'] = %d; ", (int) q1->v.f); + l = strlen(tnm); + if (l != writeall(fd, tnm, l)) + perror_msg("Writing %s", file); + free(tnm); + } + q1 = q0->v.t->get(q0->v.t, "panes", NULL, false); + if (NULL != q1) + { + tnm = xmprintf("['panes'] = %d; ", (int) q1->v.f); + l = strlen(tnm); + if (l != writeall(fd, tnm, l)) + perror_msg("Writing %s", file); + free(tnm); + } + + if (strcmp("unsorted", type) != 0) + { + 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)) + { + tnm = xmprintf("\n '%s',", q1->v.s); + l = strlen(tnm); + if (l != writeall(fd, tnm, l)) + perror_msg("Writing %s", file); + free(tnm); + } + } + q0->v.t->unlock(q0->v.t); + } + else + { + memset((void*)&obj1, 0, sizeof(obj1)); + ourSims->unsorted->lock(ourSims->unsorted); + while(ourSims->unsorted->getnext(ourSims->unsorted, &obj1, false) == true) + { + simData *simd = obj1.data; + + if ((strcmp("number", obj1.name) != 0) && (strcmp("panes", obj1.name) != 0) && (strcmp("type", obj1.name) != 0)) + { + tnm = xmprintf("\n '%s',", simd->tab); + l = strlen(tnm); + if (l != writeall(fd, tnm, l)) + perror_msg("Writing %s", file); + free(tnm); + } + } + ourSims->unsorted->unlock(ourSims->unsorted); + } + } + tnm = "\n },\n"; + l = strlen(tnm); + if (l != writeall(fd, tnm, l)) + perror_msg("Writing %s", file); } - } - sims->byTab->remove_by_obj(sims->byTab, obj.name, obj.namesize); // remove - obj = sims->byTab->find_nearest(sims->byTab, name, namesize, false); // rewind one step back - free(name); // clean up + ourSims->simsLua->unlock(ourSims->simsLua); + tnm = "}\nreturn sims\n"; + l = strlen(tnm); + if (l != writeall(fd, tnm, l)) + perror_msg("Writing %s", file); + + xclose(fd); + } + freeSimList(ourSims); + free(file); + // Reread everything. + file = xmprintf("%s/sims.lua", scEtc); + ourSims = xzalloc(sizeof(simList)); + ourSims->byTab = qtreetbl(0); + ourSims->unsorted = qtreetbl(0); + ourSims->doIt = FALSE; + ourSims->simsLua = Lua2tree(file, "sims"); + forEachSim(NULL, NULL, simNotFound); +// dumpLuaTree(ourSims->simsLua, "simsLua", 0); +// dumpLuaTree(ourSims->byTab, "byTab", 0); +// dumpLuaTree(ourSims->unsorted, "unsorted", 0); } - sims->byTab->unlock(sims->byTab); - sims->byTab->free(sims->byTab); - freeLuaTree(sims->simsLua); + free(file); - free(sims); +// dumpLuaTree(ourSims->simsLua, "simsLua", 0); +// dumpLuaTree(ourSims->byTab, "byTab", 0); + return ourSims; } // Expects either "simXX" or "ROBUST". @@ -1440,76 +1651,8 @@ int checkSimIsRunning(char *sim) return ret; } -//////////////////////////////////////////////////////////////////////////////////////////////////// -// Sim wrangling loop. -//////////////////////////////////////////////////////////////////////////////////////////////////// -typedef void (*simFunction)(simData *simd, char *type, int count, int window, int panes, int pane); -void forEachSim(char *verb, simFunction func) -{ - qtreetbl_obj_t obj0, obj1; - qLua *q0, *q1; - int count = 0, window = 0, panes = 4, pane = 0; - - ourSims->doWait = 1; - 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++; - } - - if (verb) - V("%s sims of type %s, window %d, %d panes per window.", verb, type, window, panes); - 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)) - { - simData *simd = ourSims->byTab->get(ourSims->byTab, q1->v.s, NULL, false); - - if (NULL == simd) - E("Sim %s not found in ini list!", q1->v.s); - else - { - func(simd, type, count, window, panes, pane); - count++; - pane++; - if (pane >= panes) - { - pane = 0; - window++; - } - } - } - } - q0->v.t->unlock(q0->v.t); - } - } - ourSims->simsLua->unlock(ourSims->simsLua); -} -void prepSims(simData *simd, char *type, int count, int window, int panes, int pane) +void prepSims(simData *simd, char *sim, char *type, int count, int window, int panes, int pane) { char *path = xmprintf("%s/%s.shini", scEtc, simd->tab); char *newPath = xmprintf("%s/sim%d/%s.ini", scTemp, count, simd->tab); // Coz OpenSim sucks. @@ -1586,7 +1729,7 @@ void prepSims(simData *simd, char *type, int count, int window, int panes, int p } // Figure out where the sims are running. -void findSimsTmux(simData *simd, char *type, int count, int window, int panes, int pane) +void findSimsTmux(simData *simd, char *sim, char *type, int count, int window, int panes, int pane) { simd->window = window; simd->pane = pane; @@ -1597,7 +1740,7 @@ void findSimsTmux(simData *simd, char *type, int count, int window, int panes, i freeLuaTree(IDs); } -void doSimsThing(simData *simd, char *type, int count, int window, int panes, int pane) +void doSimsThing(simData *simd, char *sim, char *type, int count, int window, int panes, int pane) { // Check if only doing a single sim. int cont = FALSE; @@ -1632,7 +1775,7 @@ void doSimsThing(simData *simd, char *type, int count, int window, int panes, in doTmuxCmd("select-pane -t %s:%s -T '%s'", Tconsole, simd->paneID, simd->tab); snprintf(toybuf, sizeof(toybuf), "mono OpenSim.exe -inidirectory=%s/sim%d", scTemp, count); sendTmuxCmd(simd->paneID, toybuf); - if (0 == ourSims->doWait) + if (0 == ourSims->doIt) { snprintf(toybuf, sizeof(toybuf), "INITIALIZATION COMPLETE FOR %s", simd->name); waitTmuxText(simd->paneID, toybuf); @@ -1645,7 +1788,7 @@ void doSimsThing(simData *simd, char *type, int count, int window, int panes, in { // TODO - some compromise, do a premptive load check if we are not doing a wait anyway. } - ourSims->doWait = ((count + 1) % bulkSims); + ourSims->doIt = ((count + 1) % bulkSims); } break; } @@ -1668,7 +1811,7 @@ void doSimsThing(simData *simd, char *type, int count, int window, int panes, in 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(simd->paneID, toybuf); -// if (0 == doWait) +// if (0 == do) { memset(toybuf, 0, sizeof(toybuf)); snprintf(toybuf, sizeof(toybuf), "Finished writing out OAR for %s", simd->name); @@ -1728,7 +1871,7 @@ void doSimsThing(simData *simd, char *type, int count, int window, int panes, in } } -void stopSims(simData *simd, char *type, int count, int window, int panes, int pane) +void stopSims(simData *simd, char *sim, char *type, int count, int window, int panes, int pane) { // NOTE - these sleeps are guesses, seems to work on my super desktop during testing. while (checkSimIsRunning(simd->tab)) @@ -7668,6 +7811,7 @@ jit library is loaded or the JIT compiler will not be activated. // TODO - See https://stackoverflow.com/questions/2693948/how-do-i-retrieve-the-number-of-processors-on-c-linux, there are more portable ways, this seems to be GNU specific. int cpus = (int) sysconf(_SC_NPROCESSORS_CONF), cpusOnline = (int) sysconf(_SC_NPROCESSORS_ONLN); + ourSims->doIt = 1; if (0 == bulkSims) bulkSims = (cpusOnline / 3) - 1; sysinfo(&info); @@ -7709,7 +7853,7 @@ V("ARGS - %d %d %i |%s| %s |%s|", toys.optc, toys.optflags, currentMode, toys. doTmuxCmd("select-pane -t 0 -T 'ROBUST'", Tcmd, scRun, Tsocket); // Create all the tmux windows, panes, and temporary .ini files coz OpenSim sucketh. - forEachSim("Prepping", prepSims); + forEachSim("Prepping", prepSims, NULL); waitTmuxText(d, "INITIALIZATION COMPLETE FOR ROBUST"); I("ROBUST is done starting up."); free(d); @@ -7721,15 +7865,16 @@ V("ARGS - %d %d %i |%s| %s |%s|", toys.optc, toys.optflags, currentMode, toys. goto finished; } else // Find out where the sims are in tmux. - forEachSim(NULL, findSimsTmux); + forEachSim(NULL, findSimsTmux, NULL); // Do stuff with the sims. - forEachSim("Doing", doSimsThing); + ourSims->doIt = 1; + forEachSim("Doing", doSimsThing, NULL); if ((STOP == currentMode) && (NULL == ourSims->target)) { // Stop all the sims. - forEachSim(NULL, stopSims); + forEachSim(NULL, stopSims, NULL); I("Closing all the other windows."); // First figure out what panes and windows are left. snprintf(toybuf, sizeof(toybuf), "echo 'IDs={' >%s/IDs_ALL.lua", scTemp); -- cgit v1.1