From 190df5e63d63954e94fafbc7948431ea637e282e Mon Sep 17 00:00:00 2001 From: onefang Date: Tue, 17 Aug 2021 21:28:30 +1000 Subject: Add member functions to SledjChisl. --- src/sledjchisl/sledjchisl.c | 102 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 83 insertions(+), 19 deletions(-) diff --git a/src/sledjchisl/sledjchisl.c b/src/sledjchisl/sledjchisl.c index 9530844..eb80f1c 100644 --- a/src/sledjchisl/sledjchisl.c +++ b/src/sledjchisl/sledjchisl.c @@ -1217,12 +1217,6 @@ 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; @@ -1843,6 +1837,8 @@ Baby Barby 3548202e-1659-4055-b406-d578ef728fe0 NPC } } +// Forward declare this. +my_ulonglong dbCount(char *table, char *where); void doSimsThing(simData *simd, char *sim, char *type, int count, int window, int panes, int pane) { // Check if only doing a single sim. @@ -1904,24 +1900,32 @@ byTab has the short name as the key, simData as the value. char *last = strchr(sim, ' '); last[0] = '\0'; last++; -// TODO - double check it's a real member. - I("Member %s %s is being backed up to %s/backups/%s_%s-%s.iar in tmux windo %s.", sim, last, scRoot, sim, last, date, ourSims->backup); - snprintf(toybuf, sizeof(toybuf), "save iar -c %s %s / password %s/backups/%s_%s-%s.iar", sim, last, scRoot, sim, last, date); - if (NULL != ourSims->backup) + // Double check it's a real member. + snprintf(toybuf, sizeof(toybuf), "FirstName='%s' and LastName='%s'", sim, last); + if (1 == dbCount("UserAccounts", toybuf)) { - sendTmuxCmd(ourSims->backup, toybuf); -// if (0 == do) + I("Member %s %s is being backed up to %s/backups/%s_%s-%s.iar in tmux windo %s.", sim, last, scRoot, sim, last, date, ourSims->backup); + snprintf(toybuf, sizeof(toybuf), "save iar -c %s %s / password %s/backups/%s_%s-%s.iar", sim, last, scRoot, sim, last, date); + if (NULL != ourSims->backup) { - snprintf(toybuf, sizeof(toybuf), "Saved archive with [[:digit:]]+ items for %s %s", sim, last); - waitTmuxText(ourSims->backup, toybuf); - I("%s is done backing up.", simd->name); + sendTmuxCmd(ourSims->backup, toybuf); +// if (0 == do) + { + snprintf(toybuf, sizeof(toybuf), "Saved archive with [[:digit:]]+ items for %s %s", sim, last); + waitTmuxText(ourSims->backup, toybuf); + I("%s %s is done backing up.", sim, last); + sendTmuxCmd(ourSims->backup, ""); + sendTmuxCmd(ourSims->backup, ""); // TODO - should delete / gitAR the old ones now. // Have a config option for delete / gitAR / rsync. - ourSims->la = waitLoadAverage(ourSims->la, loadAverageInc, simTimeOut); + ourSims->la = waitLoadAverage(ourSims->la, loadAverageInc, simTimeOut); + } } + else + E("Can't find backup sim."); } else - E("Can't find backup sim."); + E("Can't find member %s %s.", sim, last); } else if (checkSimIsRunning(simd->tab)) { @@ -7400,6 +7404,65 @@ void account_html(char *file, reqData *Rd, HTMLfile *thisFile) } +void forEachMember(char *verb, simFunction func, simFunction not) +{ + if (NULL != ourSims->target) + func(NULL, ourSims->target, "Member", 0, 0, 0, 0); + else + { + char *file = xmprintf("%s/.lastTime", scBackup); + char *last = (char *) qfile_load(file, NULL); + char *cmd = xmprintf("date +%%s > %s", file); + +// if (NULL == last) + last = xstrdup("0"); + if (!WIFEXITED(system(cmd))) + E("date command failed!"); + + static dbRequest *users = NULL; + if (NULL == users) + { + static char *szi[] = {NULL}; + static char *szo[] = {"FirstName", "LastName", NULL}; + users = xzalloc(sizeof(dbRequest)); + users->table = "UserAccounts,GridUser"; + users->inParams = szi; + users->outParams = szo; + users->where = xmprintf("UserAccounts.PrincipalID=LEFT(GridUser.UserID,36) and GridUser.Login>%s order by LastName,FirstName", last); + dbRequests->addfirst(dbRequests, &users, sizeof(dbRequest *)); + } + + dbDoSomething(users, FALSE); // LEAKY + rowData *rows = users->rows; + if (rows) + { + qhashtbl_t *row; + +d("Number of rows returned %d", (int) rows->rows->size(rows->rows)); + while (NULL != (row = rows->rows->getat(rows->rows, 0, NULL, true))) + { + char *firstName = row->getstr(row, "FirstName", false); + char *lastName = row->getstr(row, "LastName", false); + char *name = xmprintf("%s %s", firstName, lastName); + +V("Member %s %s", firstName, lastName); + func(NULL, name, "Member", 0, 0, 0, 0); + + free(name); + row->free(row); + rows->rows->removefirst(rows->rows); + } + free(rows->fieldNames); + rows->rows->free(rows->rows); + free(rows); + } + free(cmd); + free(last); + free(file); + } +} + + static void cleanup(void) { C("Caught signal, or quitting, cleaning up."); @@ -7991,7 +8054,7 @@ jit library is loaded or the JIT compiler will not be activated. ourSims->target = xmprintf("%s %s", toys.optargs[1], toys.optargs[2]); else ourSims->target = NULL; -V("Doing %s for %s '%s' %s %s", modeStrings[currentMode], FLAG(m) ? "member" : "", ourSims->target, FLAG(q) ? "quiet" : "", FLAG(a) ? "all" : ""); +//V("Doing %s for %s '%s' %s %s", modeStrings[currentMode], FLAG(m) ? "member" : "", ourSims->target, FLAG(q) ? "quiet" : "", FLAG(a) ? "all" : ""); // Start ROBUST or join the tmux session, or just figure out where the sims are running in tmux. if ((START == currentMode) && !checkSimIsRunning("ROBUST")) @@ -8026,7 +8089,8 @@ V("Doing %s for %s '%s' %s %s", modeStrings[currentMode], FLAG(m) ? "member" : { // Do stuff with the members. ourSims->doIt = 1; - forEachSim("Doing", findWindow, NULL); + // Find the correct window to do backups in. + forEachSim(NULL, findWindow, NULL); forEachMember("Doing", doSimsThing, NULL); } else -- cgit v1.1