aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/sledjchisl/sledjchisl.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/sledjchisl/sledjchisl.c89
1 files changed, 62 insertions, 27 deletions
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)
1215// Sim wrangling loop. 1215// Sim wrangling loop.
1216//////////////////////////////////////////////////////////////////////////////////////////////////// 1216////////////////////////////////////////////////////////////////////////////////////////////////////
1217typedef void (*simFunction)(simData *simd, char *sim, char *type, int count, int window, int panes, int pane); 1217typedef void (*simFunction)(simData *simd, char *sim, char *type, int count, int window, int panes, int pane);
1218
1219void forEachMember(char *verb, simFunction func, simFunction not)
1220{
1221func(NULL, ourSims->target, "Member", 0, 0, 0, 0);
1222}
1223
1218void forEachSim(char *verb, simFunction func, simFunction not) 1224void forEachSim(char *verb, simFunction func, simFunction not)
1219{ 1225{
1220 qtreetbl_obj_t obj0, obj1; 1226 qtreetbl_obj_t obj0, obj1;
@@ -1349,6 +1355,7 @@ void freeSimList(simList *sims)
1349 sims->byTab->free(sims->byTab); 1355 sims->byTab->free(sims->byTab);
1350 freeLuaTree(sims->simsLua); 1356 freeLuaTree(sims->simsLua);
1351 freeLuaTree(sims->unsorted); 1357 freeLuaTree(sims->unsorted);
1358 free(sims->target);
1352 1359
1353 free(sims); 1360 free(sims);
1354} 1361}
@@ -1679,8 +1686,6 @@ int checkSimIsRunning(char *sim)
1679 free(path); 1686 free(path);
1680 return ret; 1687 return ret;
1681} 1688}
1682
1683
1684void prepSims(simData *simd, char *sim, char *type, int count, int window, int panes, int pane) 1689void prepSims(simData *simd, char *sim, char *type, int count, int window, int panes, int pane)
1685{ 1690{
1686 char *path = xmprintf("%s/%s.shini", scEtc, simd->tab); 1691 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
1821{ 1826{
1822 // Check if only doing a single sim. 1827 // Check if only doing a single sim.
1823 int cont = FALSE; 1828 int cont = FALSE;
1824 if (NULL != ourSims->target) 1829
1830 if (FLAG(m))
1831 {
1832// TODO - check if it's a real user.
1833 }
1834 else if (NULL != ourSims->target)
1825 { 1835 {
1836/* TODO - maybe?
1837byTab has the short name as the key, simData as the value.
1838 Iterate through it looking for target sims if specified in the sledjchisl arguments.
1839 Which can be short name, long name, foo.shini file name.
1840 Though short name is a direct lookup, and "foo.shini" we can strip off the .shini and direct lookup the short name.
1841 So only need to iterate if it's a long name.
1842 Keep in mind the argument might be a user name for IAR backups. Or perhaps a UUID.
1843*/
1826 cont = TRUE; 1844 cont = TRUE;
1827 snprintf(toybuf, sizeof(toybuf), "%s.shini", simd->tab); 1845 snprintf(toybuf, sizeof(toybuf), "%s.shini", simd->tab);
1828 if 1846 if
@@ -1831,17 +1849,18 @@ void doSimsThing(simData *simd, char *sim, char *type, int count, int window, in
1831 (strcmp(ourSims->target, simd->tab) == 0) || 1849 (strcmp(ourSims->target, simd->tab) == 0) ||
1832 (strcmp(ourSims->target, toybuf) == 0) 1850 (strcmp(ourSims->target, toybuf) == 0)
1833 ) 1851 )
1834 cont = FALSE; 1852 cont = FALSE;
1835 snprintf(toybuf, sizeof(toybuf), "%s.ini", simd->tab); 1853 snprintf(toybuf, sizeof(toybuf), "%s.ini", simd->tab);
1836 if (strcmp(ourSims->target, toybuf) == 0) 1854 if (strcmp(ourSims->target, toybuf) == 0)
1837 cont = FALSE; 1855 cont = FALSE;
1838 snprintf(toybuf, sizeof(toybuf), "sim%d.ini", count); 1856 snprintf(toybuf, sizeof(toybuf), "sim%d.ini", count);
1839 if (strcmp(ourSims->target, toybuf) == 0) 1857 if (strcmp(ourSims->target, toybuf) == 0)
1840 cont = FALSE; 1858 cont = FALSE;
1841 if (cont)
1842 return;
1843 } 1859 }
1844 1860
1861 if (cont)
1862 return;
1863
1845 switch (currentMode) 1864 switch (currentMode)
1846 { 1865 {
1847 case START : // "start 'Welcome sim'" "start Welcome.shini" "Welcome.shini" "start Welcome.ini" "start Welcome" "start" start everything 1866 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
1852 1871
1853 case BACKUP : // "backup -m 'onefang rejected'" "backup 'Welcome sim'" "backup Welcome.shini" "Welcome.shini backup" "backup Welcome.ini" "backup Welcome" "backup" backup everything 1872 case BACKUP : // "backup -m 'onefang rejected'" "backup 'Welcome sim'" "backup Welcome.shini" "Welcome.shini backup" "backup Welcome.ini" "backup Welcome" "backup" backup everything
1854 { // TODO - If it's not a sim code, and not a sim name, it's an account inventory. 1873 { // TODO - If it's not a sim code, and not a sim name, it's an account inventory.
1855 if (checkSimIsRunning(simd->tab)) 1874 struct timeval tv;
1875 time_t curtime;
1876 char date[DATE_TIME_LEN];
1877
1878 gettimeofday(&tv, NULL);
1879 curtime = tv.tv_sec;
1880 strftime(date, DATE_TIME_LEN, "%F_%T", localtime(&curtime));
1881 if (FLAG(m))
1882 {
1883 I("Member %s is being backed up to %s/backups/%s-%s.iar.", sim, scRoot, sim, date);
1884 }
1885 else if (checkSimIsRunning(simd->tab))
1856 { 1886 {
1857 struct timeval tv;
1858 time_t curtime;
1859 char date[DATE_TIME_LEN];
1860
1861// TODO - should collect names of existing backups, both tmux / ini name and proper name. 1887// TODO - should collect names of existing backups, both tmux / ini name and proper name.
1862// Scan backups directory once before this for loop, add details to sims list. 1888// Scan backups directory once before this for loop, add details to sims list.
1863// strip off the last bit of file name (YYYY-mm-dd_HH:MM:SS.oar) to get the name 1889// strip off the last bit of file name (YYYY-mm-dd_HH:MM:SS.oar) to get the name
1864// keep in mind some old files had munged names like "Tiffanie_s_Paradise-2021-06-23_05:11:38.oar" 1890// keep in mind some old files had munged names like "Tiffanie_s_Paradise-2021-06-23_05:11:38.oar"
1865 gettimeofday(&tv, NULL); 1891 I("Sim %s is being backed up to %s/backups/%s-%s.oar.", simd->name, scRoot, simd->tab, date);
1866 curtime = tv.tv_sec;
1867 strftime(date, DATE_TIME_LEN, "%F_%T", localtime(&curtime));
1868 I("%s is being backed up to %s/backups/%s-%s.oar.", simd->name, scRoot, simd->tab, date);
1869 snprintf(toybuf, sizeof(toybuf), "save oar --all %s/backups/%s-%s.oar", scRoot, simd->tab, date); 1892 snprintf(toybuf, sizeof(toybuf), "save oar --all %s/backups/%s-%s.oar", scRoot, simd->tab, date);
1870 sendTmuxCmd(simd->paneID, toybuf); 1893 sendTmuxCmd(simd->paneID, toybuf);
1871// if (0 == do) 1894// if (0 == do)
@@ -1906,7 +1929,11 @@ void doSimsThing(simData *simd, char *sim, char *type, int count, int window, in
1906 case STATUS : // "status 'Welcome sim'" "status Welcome.shini" "Welcome.shini status" "status Welcome.ini" "status Welcome" "status" status everything 1929 case STATUS : // "status 'Welcome sim'" "status Welcome.shini" "Welcome.shini status" "status Welcome.ini" "status Welcome" "status" status everything
1907 { 1930 {
1908// TODO - report CPU and memory used as well. 1931// TODO - report CPU and memory used as well.
1909 if (checkSimIsRunning(simd->tab)) 1932 if (FLAG(m))
1933 {
1934// TODO - report level, online status, and location of member.
1935 }
1936 else if (checkSimIsRunning(simd->tab))
1910 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); 1937 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);
1911 else 1938 else
1912 I("%s is not running.", simd->name); 1939 I("%s is not running.", simd->name);
@@ -7953,9 +7980,18 @@ V("Doing %s for %s '%s' %s %s", modeStrings[currentMode], FLAG(m) ? "member" :
7953 else // Find out where the sims are in tmux. 7980 else // Find out where the sims are in tmux.
7954 forEachSim(NULL, findSimsTmux, NULL); 7981 forEachSim(NULL, findSimsTmux, NULL);
7955 7982
7956 // Do stuff with the sims. 7983 if (FLAG(m))
7957 ourSims->doIt = 1; 7984 {
7958 forEachSim("Doing", doSimsThing, NULL); 7985 // Do stuff with the members.
7986 ourSims->doIt = 1;
7987 forEachMember("Doing", doSimsThing, NULL);
7988 }
7989 else
7990 {
7991 // Do stuff with the sims.
7992 ourSims->doIt = 1;
7993 forEachSim("Doing", doSimsThing, NULL);
7994 }
7959 7995
7960 if ((STOP == currentMode) && (NULL == ourSims->target)) 7996 if ((STOP == currentMode) && (NULL == ourSims->target))
7961 { 7997 {
@@ -8377,14 +8413,7 @@ sendReply:
8377 8413
8378fcgiDone: 8414fcgiDone:
8379 FCGI_Finish(); 8415 FCGI_Finish();
8380 8416 snprintf(toybuf, sizeof(toybuf), " for %s %s://%s%s -> %s%s", Rd->Method, Rd->Scheme, Rd->Host, Rd->RUri, webRoot, Rd->Path);
8381 struct timespec now;
8382 if (-1 == clock_gettime(CLOCK_REALTIME, &now))
8383 perror_msg("Unable to get the time.");
8384 double n = (now.tv_sec * 1000000000.0) + now.tv_nsec;
8385 double t = (Rd->then.tv_sec * 1000000000.0) + Rd->then.tv_nsec;
8386 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);
8387
8388 if (NULL != Rd->outQuery) free(Rd->outQuery); 8417 if (NULL != Rd->outQuery) free(Rd->outQuery);
8389 if (NULL != Rd->shs.name) free(Rd->shs.name); 8418 if (NULL != Rd->shs.name) free(Rd->shs.name);
8390 Rd->shs.name = NULL; 8419 Rd->shs.name = NULL;
@@ -8405,6 +8434,12 @@ fcgiDone:
8405 if (Rd->lnk) free(Rd->lnk); 8434 if (Rd->lnk) free(Rd->lnk);
8406 free(Rd->RUri); 8435 free(Rd->RUri);
8407 8436
8437 struct timespec now;
8438 if (-1 == clock_gettime(CLOCK_REALTIME, &now))
8439 perror_msg("Unable to get the time.");
8440 double n = (now.tv_sec * 1000000000.0) + now.tv_nsec;
8441 double t = (Rd->then.tv_sec * 1000000000.0) + Rd->then.tv_nsec;
8442 T("Finished web request, took %lf seconds%s", (n - t) / 1000000000.0, toybuf);
8408 free(Rd); 8443 free(Rd);
8409 } 8444 }
8410 8445