diff options
-rw-r--r-- | src/sledjchisl/sledjchisl.c | 241 |
1 files changed, 118 insertions, 123 deletions
diff --git a/src/sledjchisl/sledjchisl.c b/src/sledjchisl/sledjchisl.c index 12c03cd..5d81ee2 100644 --- a/src/sledjchisl/sledjchisl.c +++ b/src/sledjchisl/sledjchisl.c | |||
@@ -7430,12 +7430,12 @@ jit library is loaded or the JIT compiler will not be activated. | |||
7430 | } | 7430 | } |
7431 | 7431 | ||
7432 | 7432 | ||
7433 | if (!isWeb) | ||
7434 | { | ||
7433 | //////////////////////////////////////////////////////////////////////////////////////////////////// | 7435 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
7434 | // Figure out what and where we are. | 7436 | // Figure out what and where we are. |
7435 | //////////////////////////////////////////////////////////////////////////////////////////////////// | 7437 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
7436 | // TODO - still a bit chicken and egg here about the tmux socket and reading configs from scEtc /.sledjChisl.conf.lua | 7438 | // TODO - still a bit chicken and egg here about the tmux socket and reading configs from scEtc /.sledjChisl.conf.lua |
7437 | if (!isWeb) | ||
7438 | { | ||
7439 | I("Outputting to a terminal, not a web server."); | 7439 | I("Outputting to a terminal, not a web server."); |
7440 | // Check if we are already running inside the proper tmux server. | 7440 | // Check if we are already running inside the proper tmux server. |
7441 | char *eTMUX = getenv("TMUX"); | 7441 | char *eTMUX = getenv("TMUX"); |
@@ -7655,11 +7655,125 @@ jit library is loaded or the JIT compiler will not be activated. | |||
7655 | } | 7655 | } |
7656 | 7656 | ||
7657 | 7657 | ||
7658 | if (!isWeb) | ||
7659 | { | ||
7658 | //////////////////////////////////////////////////////////////////////////////////////////////////// | 7660 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
7659 | // Start of web wrangling section. | 7661 | // Start of OpenSim wrangling section. |
7660 | //////////////////////////////////////////////////////////////////////////////////////////////////// | 7662 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
7661 | if (isWeb) | 7663 | struct sysinfo info; |
7664 | // 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. | ||
7665 | int cpus = (int) sysconf(_SC_NPROCESSORS_CONF), cpusOnline = (int) sysconf(_SC_NPROCESSORS_ONLN); | ||
7666 | |||
7667 | if (0 == bulkSims) | ||
7668 | bulkSims = (cpusOnline / 3) - 1; | ||
7669 | sysinfo(&info); | ||
7670 | ourSims->la = info.loads[0]/65536.0; | ||
7671 | I("There are %i CPUs, %i of them are online. Doing %i sims at once. LoadAverage = %f", cpus, cpusOnline, bulkSims, ourSims->la); | ||
7672 | |||
7673 | if (0 == toys.optc) | ||
7674 | ; | ||
7675 | else if (strcmp(toys.optargs[0], "create") == 0) | ||
7676 | currentMode = CREATE; | ||
7677 | else if (strcmp(toys.optargs[0], "start") == 0) | ||
7678 | currentMode = START; | ||
7679 | else if (strcmp(toys.optargs[0], "backup") == 0) | ||
7680 | currentMode = BACKUP; | ||
7681 | else if (strcmp(toys.optargs[0], "gitar") == 0) | ||
7682 | currentMode = GITAR; | ||
7683 | else if (strcmp(toys.optargs[0], "status") == 0) | ||
7684 | currentMode = STATUS; | ||
7685 | else if (strcmp(toys.optargs[0], "stop") == 0) | ||
7686 | currentMode = STOP; | ||
7687 | else | ||
7688 | ourSims->target = toys.optargs[0]; | ||
7689 | if (2 == toys.optc) | ||
7690 | ourSims->target = toys.optargs[1]; | ||
7691 | V("ARGS - %d %d %i |%s| %s |%s|", toys.optc, toys.optflags, currentMode, toys.optargs[0], toys.optargs[1], ourSims->target); | ||
7692 | |||
7693 | // Start ROBUST or join the tmux session, or just figure out where the sims are running in tmux. | ||
7694 | if ((START == currentMode) && !checkSimIsRunning("ROBUST")) | ||
7695 | { | ||
7696 | char *d = xmprintf("%s.{right}", Ttab); | ||
7697 | char *c = xmprintf("cd %s/current/bin", scRoot); | ||
7698 | |||
7699 | I("ROBUST is starting up."); | ||
7700 | sendTmuxCmd(d, c); | ||
7701 | free(c); | ||
7702 | c = xmprintf("mono Robust.exe -inidirectory=%s/config/ROBUST", scRoot); | ||
7703 | sendTmuxCmd(d, c); | ||
7704 | free(c); | ||
7705 | doTmuxCmd("select-pane -t 0 -T 'ROBUST'", Tcmd, scRun, Tsocket); | ||
7706 | |||
7707 | // Create all the tmux windows, panes, and temporary .ini files coz OpenSim sucketh. | ||
7708 | forEachSim("Prepping", prepSims); | ||
7709 | waitTmuxText(d, "INITIALIZATION COMPLETE FOR ROBUST"); | ||
7710 | I("ROBUST is done starting up."); | ||
7711 | free(d); | ||
7712 | } | ||
7713 | else if ((0 == toys.optc) && (checkSimIsRunning("ROBUST"))) | ||
7714 | { | ||
7715 | // Join the session. | ||
7716 | doTmuxCmd("select-window -t '%s' \\; attach-session -t '%s'", Tconsole, Tconsole); | ||
7717 | goto finished; | ||
7718 | } | ||
7719 | else // Find out where the sims are in tmux. | ||
7720 | forEachSim(NULL, findSimsTmux); | ||
7721 | |||
7722 | // Do stuff with the sims. | ||
7723 | forEachSim("Doing", doSimsThing); | ||
7724 | |||
7725 | if ((STOP == currentMode) && (NULL == ourSims->target)) | ||
7726 | { | ||
7727 | // Stop all the sims. | ||
7728 | forEachSim(NULL, stopSims); | ||
7729 | I("Closing all the other windows."); | ||
7730 | // First figure out what panes and windows are left. | ||
7731 | snprintf(toybuf, sizeof(toybuf), "echo 'IDs={' >%s/IDs_ALL.lua", scTemp); | ||
7732 | system(toybuf); | ||
7733 | doTmuxCmd("list-panes -s -F '\"#{window_id}.#{pane_id}\",' >> %s/IDs_ALL.lua", scTemp); | ||
7734 | snprintf(toybuf, sizeof(toybuf), "echo '}\nreturn IDs' >>%s/IDs_ALL.lua", scTemp); | ||
7735 | system(toybuf); | ||
7736 | snprintf(toybuf, sizeof(toybuf), "%s/IDs_ALL.lua", scTemp); | ||
7737 | qtreetbl_t *IDs = Lua2tree(toybuf, "IDs"); | ||
7738 | |||
7739 | qtreetbl_obj_t obj0; | ||
7740 | memset((void*)&obj0, 0, sizeof(obj0)); | ||
7741 | IDs->lock(IDs); | ||
7742 | while(IDs->getnext(IDs, &obj0, false) == true) | ||
7743 | { | ||
7744 | qLua *q0 = obj0.data; | ||
7745 | |||
7746 | if ('0' != q0->v.s[1]) | ||
7747 | doTmuxCmd("kill-pane -t %s", q0->v.s); | ||
7748 | } | ||
7749 | IDs->unlock(IDs); | ||
7750 | freeLuaTree(IDs); | ||
7751 | |||
7752 | char *c = xmprintf("rm -fr %s/*", scTemp); | ||
7753 | if (!WIFEXITED(system(c))) | ||
7754 | E("rm command failed! %s", c); | ||
7755 | free(c); | ||
7756 | } | ||
7757 | else if (START == currentMode) | ||
7758 | { | ||
7759 | if (checkSimIsRunning("ROBUST") && (NULL == ourSims->target)) | ||
7760 | { | ||
7761 | // TODO - remove this once we handle the fcgi stuff ourselves. | ||
7762 | I("Starting the web stuff."); | ||
7763 | char *c = xmprintf("spawn-fcgi -n -u %s -s %s/sledjchisl.socket -M 0660 -G www-data -- /usr/bin/valgrind --leak-check=full sledjchisl", | ||
7764 | scUser, scCache, scRoot); | ||
7765 | sendTmuxCmd(Ttab, c); | ||
7766 | free(c); | ||
7767 | } | ||
7768 | else | ||
7769 | I("NOT Starting the web stuff."); | ||
7770 | } | ||
7771 | } | ||
7772 | else | ||
7662 | { | 7773 | { |
7774 | //////////////////////////////////////////////////////////////////////////////////////////////////// | ||
7775 | // Start of web wrangling section. | ||
7776 | //////////////////////////////////////////////////////////////////////////////////////////////////// | ||
7663 | char **initialEnv = environ; | 7777 | char **initialEnv = environ; |
7664 | char *tmp0, *tmp1; | 7778 | char *tmp0, *tmp1; |
7665 | int count = 0, entries, bytes; | 7779 | int count = 0, entries, bytes; |
@@ -8031,8 +8145,6 @@ fcgiDone: | |||
8031 | 8145 | ||
8032 | FCGI_fprintf(FCGI_stderr, "Stopped SledjChisl web server.\n"); | 8146 | FCGI_fprintf(FCGI_stderr, "Stopped SledjChisl web server.\n"); |
8033 | D("Stopped SledjChisl web server."); | 8147 | D("Stopped SledjChisl web server."); |
8034 | |||
8035 | goto finished; | ||
8036 | } | 8148 | } |
8037 | //////////////////////////////////////////////////////////////////////////////////////////////////// | 8149 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
8038 | // End of web wrangling section. | 8150 | // End of web wrangling section. |
@@ -8040,123 +8152,6 @@ fcgiDone: | |||
8040 | 8152 | ||
8041 | 8153 | ||
8042 | 8154 | ||
8043 | //////////////////////////////////////////////////////////////////////////////////////////////////// | ||
8044 | // Start of OpenSim wrangling section. | ||
8045 | //////////////////////////////////////////////////////////////////////////////////////////////////// | ||
8046 | struct sysinfo info; | ||
8047 | // 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. | ||
8048 | int cpus = (int) sysconf(_SC_NPROCESSORS_CONF), cpusOnline = (int) sysconf(_SC_NPROCESSORS_ONLN); | ||
8049 | |||
8050 | if (0 == bulkSims) | ||
8051 | bulkSims = (cpusOnline / 3) - 1; | ||
8052 | sysinfo(&info); | ||
8053 | ourSims->la = info.loads[0]/65536.0; | ||
8054 | I("There are %i CPUs, %i of them are online. Doing %i sims at once. LoadAverage = %f", cpus, cpusOnline, bulkSims, ourSims->la); | ||
8055 | |||
8056 | if (0 == toys.optc) | ||
8057 | ; | ||
8058 | else if (strcmp(toys.optargs[0], "create") == 0) | ||
8059 | currentMode = CREATE; | ||
8060 | else if (strcmp(toys.optargs[0], "start") == 0) | ||
8061 | currentMode = START; | ||
8062 | else if (strcmp(toys.optargs[0], "backup") == 0) | ||
8063 | currentMode = BACKUP; | ||
8064 | else if (strcmp(toys.optargs[0], "gitar") == 0) | ||
8065 | currentMode = GITAR; | ||
8066 | else if (strcmp(toys.optargs[0], "status") == 0) | ||
8067 | currentMode = STATUS; | ||
8068 | else if (strcmp(toys.optargs[0], "stop") == 0) | ||
8069 | currentMode = STOP; | ||
8070 | else | ||
8071 | ourSims->target = toys.optargs[0]; | ||
8072 | if (2 == toys.optc) | ||
8073 | ourSims->target = toys.optargs[1]; | ||
8074 | V("ARGS - %d %d %i |%s| %s |%s|", toys.optc, toys.optflags, currentMode, toys.optargs[0], toys.optargs[1], ourSims->target); | ||
8075 | |||
8076 | // Start ROBUST or join the tmux session, or just figure out where the sims are running in tmux. | ||
8077 | if ((START == currentMode) && !checkSimIsRunning("ROBUST")) | ||
8078 | { | ||
8079 | char *d = xmprintf("%s.{right}", Ttab); | ||
8080 | char *c = xmprintf("cd %s/current/bin", scRoot); | ||
8081 | |||
8082 | I("ROBUST is starting up."); | ||
8083 | sendTmuxCmd(d, c); | ||
8084 | free(c); | ||
8085 | c = xmprintf("mono Robust.exe -inidirectory=%s/config/ROBUST", scRoot); | ||
8086 | sendTmuxCmd(d, c); | ||
8087 | free(c); | ||
8088 | doTmuxCmd("select-pane -t 0 -T 'ROBUST'", Tcmd, scRun, Tsocket); | ||
8089 | |||
8090 | // Create all the tmux windows, panes, and temporary .ini files coz OpenSim sucketh. | ||
8091 | forEachSim("Prepping", prepSims); | ||
8092 | waitTmuxText(d, "INITIALIZATION COMPLETE FOR ROBUST"); | ||
8093 | I("ROBUST is done starting up."); | ||
8094 | free(d); | ||
8095 | } | ||
8096 | else if ((0 == toys.optc) && (checkSimIsRunning("ROBUST"))) | ||
8097 | { | ||
8098 | // Join the session. | ||
8099 | doTmuxCmd("select-window -t '%s' \\; attach-session -t '%s'", Tconsole, Tconsole); | ||
8100 | goto finished; | ||
8101 | } | ||
8102 | else // Find out where the sims are in tmux. | ||
8103 | forEachSim(NULL, findSimsTmux); | ||
8104 | |||
8105 | // Do stuff with the sims. | ||
8106 | forEachSim("Doing", doSimsThing); | ||
8107 | |||
8108 | if (START == currentMode) | ||
8109 | { | ||
8110 | if (checkSimIsRunning("ROBUST") && (NULL == ourSims->target)) | ||
8111 | { | ||
8112 | // TODO - remove this once we handle the fcgi stuff ourselves. | ||
8113 | I("Starting the web stuff."); | ||
8114 | char *c = xmprintf("spawn-fcgi -n -u %s -s %s/sledjchisl.socket -M 0660 -G www-data -- " | ||
8115 | "/usr/bin/valgrind --leak-check=full sledjchisl", | ||
8116 | scUser, scCache, scRoot); | ||
8117 | sendTmuxCmd(Ttab, c); | ||
8118 | free(c); | ||
8119 | } | ||
8120 | else | ||
8121 | I("NOT Starting the web stuff."); | ||
8122 | } | ||
8123 | else if ((STOP == currentMode) && (NULL == ourSims->target)) | ||
8124 | { | ||
8125 | // Stop all the sims. | ||
8126 | forEachSim(NULL, stopSims); | ||
8127 | I("Closing all the other windows."); | ||
8128 | // First figure out what panes and windows are left. | ||
8129 | snprintf(toybuf, sizeof(toybuf), "echo 'IDs={' >%s/IDs_ALL.lua", scTemp); | ||
8130 | system(toybuf); | ||
8131 | doTmuxCmd("list-panes -s -F '\"#{window_id}.#{pane_id}\",' >> %s/IDs_ALL.lua", scTemp); | ||
8132 | snprintf(toybuf, sizeof(toybuf), "echo '}\nreturn IDs' >>%s/IDs_ALL.lua", scTemp); | ||
8133 | system(toybuf); | ||
8134 | snprintf(toybuf, sizeof(toybuf), "%s/IDs_ALL.lua", scTemp); | ||
8135 | qtreetbl_t *IDs = Lua2tree(toybuf, "IDs"); | ||
8136 | |||
8137 | qtreetbl_obj_t obj0; | ||
8138 | memset((void*)&obj0, 0, sizeof(obj0)); | ||
8139 | IDs->lock(IDs); | ||
8140 | while(IDs->getnext(IDs, &obj0, false) == true) | ||
8141 | { | ||
8142 | qLua *q0 = obj0.data; | ||
8143 | |||
8144 | if ('0' != q0->v.s[1]) | ||
8145 | doTmuxCmd("kill-pane -t %s", q0->v.s); | ||
8146 | } | ||
8147 | IDs->unlock(IDs); | ||
8148 | freeLuaTree(IDs); | ||
8149 | |||
8150 | char *c = xmprintf("rm -fr %s/*", scTemp); | ||
8151 | if (!WIFEXITED(system(c))) | ||
8152 | E("rm command failed! %s", c); | ||
8153 | free(c); | ||
8154 | } | ||
8155 | //////////////////////////////////////////////////////////////////////////////////////////////////// | ||
8156 | // End of OpenSim wrangling section. | ||
8157 | //////////////////////////////////////////////////////////////////////////////////////////////////// | ||
8158 | |||
8159 | |||
8160 | /* | 8155 | /* |
8161 | double sum; | 8156 | double sum; |
8162 | 8157 | ||