diff options
author | onefang | 2021-08-17 21:28:30 +1000 |
---|---|---|
committer | onefang | 2021-08-17 21:28:30 +1000 |
commit | 190df5e63d63954e94fafbc7948431ea637e282e (patch) | |
tree | 5cefd2d288e188eaec83a9b78a603f7cbf1bbb52 | |
parent | No more double cleanup(). (diff) | |
download | opensim-SC-190df5e63d63954e94fafbc7948431ea637e282e.zip opensim-SC-190df5e63d63954e94fafbc7948431ea637e282e.tar.gz opensim-SC-190df5e63d63954e94fafbc7948431ea637e282e.tar.bz2 opensim-SC-190df5e63d63954e94fafbc7948431ea637e282e.tar.xz |
Add member functions to SledjChisl.
-rw-r--r-- | src/sledjchisl/sledjchisl.c | 102 |
1 files 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) | |||
1217 | // Sim wrangling loop. | 1217 | // Sim wrangling loop. |
1218 | //////////////////////////////////////////////////////////////////////////////////////////////////// | 1218 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
1219 | typedef void (*simFunction)(simData *simd, char *sim, char *type, int count, int window, int panes, int pane); | 1219 | typedef void (*simFunction)(simData *simd, char *sim, char *type, int count, int window, int panes, int pane); |
1220 | |||
1221 | void forEachMember(char *verb, simFunction func, simFunction not) | ||
1222 | { | ||
1223 | func(NULL, ourSims->target, "Member", 0, 0, 0, 0); | ||
1224 | } | ||
1225 | |||
1226 | void forEachSim(char *verb, simFunction func, simFunction not) | 1220 | void forEachSim(char *verb, simFunction func, simFunction not) |
1227 | { | 1221 | { |
1228 | qtreetbl_obj_t obj0, obj1; | 1222 | qtreetbl_obj_t obj0, obj1; |
@@ -1843,6 +1837,8 @@ Baby Barby 3548202e-1659-4055-b406-d578ef728fe0 NPC | |||
1843 | } | 1837 | } |
1844 | } | 1838 | } |
1845 | 1839 | ||
1840 | // Forward declare this. | ||
1841 | my_ulonglong dbCount(char *table, char *where); | ||
1846 | void doSimsThing(simData *simd, char *sim, char *type, int count, int window, int panes, int pane) | 1842 | void doSimsThing(simData *simd, char *sim, char *type, int count, int window, int panes, int pane) |
1847 | { | 1843 | { |
1848 | // Check if only doing a single sim. | 1844 | // Check if only doing a single sim. |
@@ -1904,24 +1900,32 @@ byTab has the short name as the key, simData as the value. | |||
1904 | char *last = strchr(sim, ' '); | 1900 | char *last = strchr(sim, ' '); |
1905 | 1901 | ||
1906 | last[0] = '\0'; last++; | 1902 | last[0] = '\0'; last++; |
1907 | // TODO - double check it's a real member. | 1903 | // Double check it's a real member. |
1908 | 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); | 1904 | snprintf(toybuf, sizeof(toybuf), "FirstName='%s' and LastName='%s'", sim, last); |
1909 | snprintf(toybuf, sizeof(toybuf), "save iar -c %s %s / password %s/backups/%s_%s-%s.iar", sim, last, scRoot, sim, last, date); | 1905 | if (1 == dbCount("UserAccounts", toybuf)) |
1910 | if (NULL != ourSims->backup) | ||
1911 | { | 1906 | { |
1912 | sendTmuxCmd(ourSims->backup, toybuf); | 1907 | 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); |
1913 | // if (0 == do) | 1908 | snprintf(toybuf, sizeof(toybuf), "save iar -c %s %s / password %s/backups/%s_%s-%s.iar", sim, last, scRoot, sim, last, date); |
1909 | if (NULL != ourSims->backup) | ||
1914 | { | 1910 | { |
1915 | snprintf(toybuf, sizeof(toybuf), "Saved archive with [[:digit:]]+ items for %s %s", sim, last); | 1911 | sendTmuxCmd(ourSims->backup, toybuf); |
1916 | waitTmuxText(ourSims->backup, toybuf); | 1912 | // if (0 == do) |
1917 | I("%s is done backing up.", simd->name); | 1913 | { |
1914 | snprintf(toybuf, sizeof(toybuf), "Saved archive with [[:digit:]]+ items for %s %s", sim, last); | ||
1915 | waitTmuxText(ourSims->backup, toybuf); | ||
1916 | I("%s %s is done backing up.", sim, last); | ||
1917 | sendTmuxCmd(ourSims->backup, ""); | ||
1918 | sendTmuxCmd(ourSims->backup, ""); | ||
1918 | // TODO - should delete / gitAR the old ones now. | 1919 | // TODO - should delete / gitAR the old ones now. |
1919 | // Have a config option for delete / gitAR / rsync. | 1920 | // Have a config option for delete / gitAR / rsync. |
1920 | ourSims->la = waitLoadAverage(ourSims->la, loadAverageInc, simTimeOut); | 1921 | ourSims->la = waitLoadAverage(ourSims->la, loadAverageInc, simTimeOut); |
1922 | } | ||
1921 | } | 1923 | } |
1924 | else | ||
1925 | E("Can't find backup sim."); | ||
1922 | } | 1926 | } |
1923 | else | 1927 | else |
1924 | E("Can't find backup sim."); | 1928 | E("Can't find member %s %s.", sim, last); |
1925 | } | 1929 | } |
1926 | else if (checkSimIsRunning(simd->tab)) | 1930 | else if (checkSimIsRunning(simd->tab)) |
1927 | { | 1931 | { |
@@ -7400,6 +7404,65 @@ void account_html(char *file, reqData *Rd, HTMLfile *thisFile) | |||
7400 | } | 7404 | } |
7401 | 7405 | ||
7402 | 7406 | ||
7407 | void forEachMember(char *verb, simFunction func, simFunction not) | ||
7408 | { | ||
7409 | if (NULL != ourSims->target) | ||
7410 | func(NULL, ourSims->target, "Member", 0, 0, 0, 0); | ||
7411 | else | ||
7412 | { | ||
7413 | char *file = xmprintf("%s/.lastTime", scBackup); | ||
7414 | char *last = (char *) qfile_load(file, NULL); | ||
7415 | char *cmd = xmprintf("date +%%s > %s", file); | ||
7416 | |||
7417 | // if (NULL == last) | ||
7418 | last = xstrdup("0"); | ||
7419 | if (!WIFEXITED(system(cmd))) | ||
7420 | E("date command failed!"); | ||
7421 | |||
7422 | static dbRequest *users = NULL; | ||
7423 | if (NULL == users) | ||
7424 | { | ||
7425 | static char *szi[] = {NULL}; | ||
7426 | static char *szo[] = {"FirstName", "LastName", NULL}; | ||
7427 | users = xzalloc(sizeof(dbRequest)); | ||
7428 | users->table = "UserAccounts,GridUser"; | ||
7429 | users->inParams = szi; | ||
7430 | users->outParams = szo; | ||
7431 | users->where = xmprintf("UserAccounts.PrincipalID=LEFT(GridUser.UserID,36) and GridUser.Login>%s order by LastName,FirstName", last); | ||
7432 | dbRequests->addfirst(dbRequests, &users, sizeof(dbRequest *)); | ||
7433 | } | ||
7434 | |||
7435 | dbDoSomething(users, FALSE); // LEAKY | ||
7436 | rowData *rows = users->rows; | ||
7437 | if (rows) | ||
7438 | { | ||
7439 | qhashtbl_t *row; | ||
7440 | |||
7441 | d("Number of rows returned %d", (int) rows->rows->size(rows->rows)); | ||
7442 | while (NULL != (row = rows->rows->getat(rows->rows, 0, NULL, true))) | ||
7443 | { | ||
7444 | char *firstName = row->getstr(row, "FirstName", false); | ||
7445 | char *lastName = row->getstr(row, "LastName", false); | ||
7446 | char *name = xmprintf("%s %s", firstName, lastName); | ||
7447 | |||
7448 | V("Member %s %s", firstName, lastName); | ||
7449 | func(NULL, name, "Member", 0, 0, 0, 0); | ||
7450 | |||
7451 | free(name); | ||
7452 | row->free(row); | ||
7453 | rows->rows->removefirst(rows->rows); | ||
7454 | } | ||
7455 | free(rows->fieldNames); | ||
7456 | rows->rows->free(rows->rows); | ||
7457 | free(rows); | ||
7458 | } | ||
7459 | free(cmd); | ||
7460 | free(last); | ||
7461 | free(file); | ||
7462 | } | ||
7463 | } | ||
7464 | |||
7465 | |||
7403 | static void cleanup(void) | 7466 | static void cleanup(void) |
7404 | { | 7467 | { |
7405 | C("Caught signal, or quitting, cleaning up."); | 7468 | C("Caught signal, or quitting, cleaning up."); |
@@ -7991,7 +8054,7 @@ jit library is loaded or the JIT compiler will not be activated. | |||
7991 | ourSims->target = xmprintf("%s %s", toys.optargs[1], toys.optargs[2]); | 8054 | ourSims->target = xmprintf("%s %s", toys.optargs[1], toys.optargs[2]); |
7992 | else | 8055 | else |
7993 | ourSims->target = NULL; | 8056 | ourSims->target = NULL; |
7994 | V("Doing %s for %s '%s' %s %s", modeStrings[currentMode], FLAG(m) ? "member" : "", ourSims->target, FLAG(q) ? "quiet" : "", FLAG(a) ? "all" : ""); | 8057 | //V("Doing %s for %s '%s' %s %s", modeStrings[currentMode], FLAG(m) ? "member" : "", ourSims->target, FLAG(q) ? "quiet" : "", FLAG(a) ? "all" : ""); |
7995 | 8058 | ||
7996 | // Start ROBUST or join the tmux session, or just figure out where the sims are running in tmux. | 8059 | // Start ROBUST or join the tmux session, or just figure out where the sims are running in tmux. |
7997 | if ((START == currentMode) && !checkSimIsRunning("ROBUST")) | 8060 | if ((START == currentMode) && !checkSimIsRunning("ROBUST")) |
@@ -8026,7 +8089,8 @@ V("Doing %s for %s '%s' %s %s", modeStrings[currentMode], FLAG(m) ? "member" : | |||
8026 | { | 8089 | { |
8027 | // Do stuff with the members. | 8090 | // Do stuff with the members. |
8028 | ourSims->doIt = 1; | 8091 | ourSims->doIt = 1; |
8029 | forEachSim("Doing", findWindow, NULL); | 8092 | // Find the correct window to do backups in. |
8093 | forEachSim(NULL, findWindow, NULL); | ||
8030 | forEachMember("Doing", doSimsThing, NULL); | 8094 | forEachMember("Doing", doSimsThing, NULL); |
8031 | } | 8095 | } |
8032 | else | 8096 | else |