From a2cde5278e90004f63f689f63f34d092e8d61676 Mon Sep 17 00:00:00 2001 From: onefang Date: Fri, 13 Aug 2021 03:27:44 +1000 Subject: Start of dealing with members in the "sim" loop. --- src/sledjchisl/sledjchisl.c | 89 +++++++++++++++++++++++++++++++-------------- 1 file changed, 62 insertions(+), 27 deletions(-) (limited to 'src') diff --git a/src/sledjchisl/sledjchisl.c b/src/sledjchisl/sledjchisl.c index 7180383..9be746f 100644 --- a/src/sledjchisl/sledjchisl.c +++ b/src/sledjchisl/sledjchisl.c @@ -1215,6 +1215,12 @@ static int filterShinis(struct dirtree *node) // Sim wrangling loop. //////////////////////////////////////////////////////////////////////////////////////////////////// typedef void (*simFunction)(simData *simd, char *sim, char *type, int count, int window, int panes, int pane); + +void forEachMember(char *verb, simFunction func, simFunction not) +{ +func(NULL, ourSims->target, "Member", 0, 0, 0, 0); +} + void forEachSim(char *verb, simFunction func, simFunction not) { qtreetbl_obj_t obj0, obj1; @@ -1349,6 +1355,7 @@ void freeSimList(simList *sims) sims->byTab->free(sims->byTab); freeLuaTree(sims->simsLua); freeLuaTree(sims->unsorted); + free(sims->target); free(sims); } @@ -1679,8 +1686,6 @@ int checkSimIsRunning(char *sim) free(path); return ret; } - - 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); @@ -1821,8 +1826,21 @@ void doSimsThing(simData *simd, char *sim, char *type, int count, int window, in { // Check if only doing a single sim. int cont = FALSE; - if (NULL != ourSims->target) + + if (FLAG(m)) + { +// TODO - check if it's a real user. + } + else if (NULL != ourSims->target) { +/* TODO - maybe? +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. +*/ cont = TRUE; snprintf(toybuf, sizeof(toybuf), "%s.shini", simd->tab); if @@ -1831,17 +1849,18 @@ void doSimsThing(simData *simd, char *sim, char *type, int count, int window, in (strcmp(ourSims->target, simd->tab) == 0) || (strcmp(ourSims->target, toybuf) == 0) ) - cont = FALSE; + cont = FALSE; snprintf(toybuf, sizeof(toybuf), "%s.ini", simd->tab); if (strcmp(ourSims->target, toybuf) == 0) cont = FALSE; snprintf(toybuf, sizeof(toybuf), "sim%d.ini", count); if (strcmp(ourSims->target, toybuf) == 0) cont = FALSE; - if (cont) - return; } + if (cont) + return; + switch (currentMode) { case START : // "start 'Welcome sim'" "start Welcome.shini" "Welcome.shini" "start Welcome.ini" "start Welcome" "start" start everything @@ -1852,20 +1871,24 @@ void doSimsThing(simData *simd, char *sim, char *type, int count, int window, in case BACKUP : // "backup -m 'onefang rejected'" "backup 'Welcome sim'" "backup Welcome.shini" "Welcome.shini backup" "backup Welcome.ini" "backup Welcome" "backup" backup everything { // TODO - If it's not a sim code, and not a sim name, it's an account inventory. - if (checkSimIsRunning(simd->tab)) + struct timeval tv; + time_t curtime; + char date[DATE_TIME_LEN]; + + gettimeofday(&tv, NULL); + curtime = tv.tv_sec; + strftime(date, DATE_TIME_LEN, "%F_%T", localtime(&curtime)); + if (FLAG(m)) + { + I("Member %s is being backed up to %s/backups/%s-%s.iar.", sim, scRoot, sim, date); + } + else if (checkSimIsRunning(simd->tab)) { - struct timeval tv; - time_t curtime; - char date[DATE_TIME_LEN]; - // 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 // keep in mind some old files had munged names like "Tiffanie_s_Paradise-2021-06-23_05:11:38.oar" - gettimeofday(&tv, NULL); - curtime = tv.tv_sec; - 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); + I("Sim %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 == do) @@ -1906,7 +1929,11 @@ void doSimsThing(simData *simd, char *sim, char *type, int count, int window, in case STATUS : // "status 'Welcome sim'" "status Welcome.shini" "Welcome.shini status" "status Welcome.ini" "status Welcome" "status" status everything { // TODO - report CPU and memory used as well. - if (checkSimIsRunning(simd->tab)) + if (FLAG(m)) + { +// TODO - report level, online status, and location of member. + } + else if (checkSimIsRunning(simd->tab)) I("%s is running in Tmux tab [%d:%s](pane %d) tmux ID %s, from %s/sim%d", simd->name, window, type, pane, simd->paneID, scTemp, count); else I("%s is not running.", simd->name); @@ -7953,9 +7980,18 @@ V("Doing %s for %s '%s' %s %s", modeStrings[currentMode], FLAG(m) ? "member" : else // Find out where the sims are in tmux. forEachSim(NULL, findSimsTmux, NULL); - // Do stuff with the sims. - ourSims->doIt = 1; - forEachSim("Doing", doSimsThing, NULL); + if (FLAG(m)) + { + // Do stuff with the members. + ourSims->doIt = 1; + forEachMember("Doing", doSimsThing, NULL); + } + else + { + // Do stuff with the sims. + ourSims->doIt = 1; + forEachSim("Doing", doSimsThing, NULL); + } if ((STOP == currentMode) && (NULL == ourSims->target)) { @@ -8377,14 +8413,7 @@ sendReply: fcgiDone: FCGI_Finish(); - - struct timespec now; - if (-1 == clock_gettime(CLOCK_REALTIME, &now)) - perror_msg("Unable to get the time."); - double n = (now.tv_sec * 1000000000.0) + now.tv_nsec; - double t = (Rd->then.tv_sec * 1000000000.0) + Rd->then.tv_nsec; - T("Finished web request, took %lf seconds for %s %s://%s%s -> %s%s", (n - t) / 1000000000.0, Rd->Method, Rd->Scheme, Rd->Host, Rd->RUri, webRoot, Rd->Path); - + snprintf(toybuf, sizeof(toybuf), " for %s %s://%s%s -> %s%s", Rd->Method, Rd->Scheme, Rd->Host, Rd->RUri, webRoot, Rd->Path); if (NULL != Rd->outQuery) free(Rd->outQuery); if (NULL != Rd->shs.name) free(Rd->shs.name); Rd->shs.name = NULL; @@ -8405,6 +8434,12 @@ fcgiDone: if (Rd->lnk) free(Rd->lnk); free(Rd->RUri); + struct timespec now; + if (-1 == clock_gettime(CLOCK_REALTIME, &now)) + perror_msg("Unable to get the time."); + double n = (now.tv_sec * 1000000000.0) + now.tv_nsec; + double t = (Rd->then.tv_sec * 1000000000.0) + Rd->then.tv_nsec; + T("Finished web request, took %lf seconds%s", (n - t) / 1000000000.0, toybuf); free(Rd); } -- cgit v1.1