From 3029625955a8a6ca455cc47b0c5a5bbff27db1cc Mon Sep 17 00:00:00 2001 From: onefang Date: Wed, 18 Aug 2021 18:25:00 +1000 Subject: Try to cater for several ways of screwing up the working directory. --- src/sledjchisl/sledjchisl.c | 125 ++++++++++++++++++++++++++++++++------------ 1 file changed, 91 insertions(+), 34 deletions(-) diff --git a/src/sledjchisl/sledjchisl.c b/src/sledjchisl/sledjchisl.c index aae3031..189fd2d 100644 --- a/src/sledjchisl/sledjchisl.c +++ b/src/sledjchisl/sledjchisl.c @@ -7611,13 +7611,35 @@ static void cleanup(void) } +int scanForConfigs(char **cPaths) +{ + int result = FALSE, i; + struct stat st; + + for (i = 0; cPaths[i]; i++) + { + if (('/' == cPaths[i][0]) || ('~' == cPaths[i][0])) + snprintf(toybuf, sizeof(toybuf), "%s", cPaths[i]); + else + snprintf(toybuf, sizeof(toybuf), "%s/%s", pwd, cPaths[i]); + + if (qfile_exist(toybuf)) + { + I("Loading configuration file (maybe) - %s", toybuf); + Lua2hashtbl(toybuf, configs, "config"); + result = TRUE; + } + } + return result; +} + //////////////////////////////////////////////////////////////////////////////////////////////////// // Main function. //////////////////////////////////////////////////////////////////////////////////////////////////// void sledjchisl_main(void) { char *cmd = *toys.optargs; - char *tmp; + char *tmp, *t0, *t1; struct stat statbuf; int status, result, i; void *vd; @@ -7625,6 +7647,7 @@ void sledjchisl_main(void) if(FLAG(v)) VERBOSE = TRUE; + V("SledjChisl command - %s", toys.argv[0]); V("SledjChisl arguments - %d %d", toys.optc, toys.optflags); for (i = 0; i < toys.optc; i++) V(" argument %d %s", i, toys.optargs[i] ); @@ -7639,8 +7662,6 @@ void sledjchisl_main(void) V("OpenSSL version: %s", OPENSSL_VERSION_TEXT); V("qLibc version: qLibc only git tags for version numbers. Sooo, 2.4.4, unless I forgot to update this."); V("toybox version: %s", TOYBOX_VERSION); - - dbRequests = qlist(0); sigatexit(cleanup); @@ -7704,51 +7725,87 @@ jit library is loaded or the JIT compiler will not be activated. */ luaL_openlibs(L); // Load Lua libraries. - // Load the config scripts. -// TODO - should add something like current working directory here. Gets complicated, may have to go up or down a bit. +/* Load the config scripts. +Normally we start in /opt/opensim_SC/current/bin + sledjchisl here is a symlink to ../src/build/toybox/toybox or ../src/build/toybox/generated/unstripped/toybox + So that .sledjChisl.conf.lua is found, which is normally a symlink to ../src/.sledjChisl.conf.lua + +Other possibilities - + Normally sledjchisl isn't in the path, though it is once our tmux is running. + No doubt someone will put it in the path, so then we can start anywhere. + Someone could run it from a downloaded opensim-SC and run it from that bin, then it's not installed. +*/ char *cPaths[] = { - ".sledjChisl.conf.lua", "/etc/sledjChisl.conf.lua", // "/etc/sledjChisl.d/*.lua", "~/.sledjChisl.conf.lua", // "~/.config/sledjChisl/*.lua", NULL }; - struct stat st; - for (i = 0; cPaths[i]; i++) + char *oPaths[] = { - if (('/' == cPaths[i][0]) || ('~' == cPaths[i][0])) - snprintf(toybuf, sizeof(toybuf), "%s", cPaths[i]); - else - snprintf(toybuf, sizeof(toybuf), "%s/%s", pwd, cPaths[i]); + ".sledjChisl.conf.lua", + "./etc/sledjChisl.conf.lua", + NULL + }; - if (qfile_exist(toybuf)) + result = scanForConfigs(cPaths); + result = result | scanForConfigs(oPaths); + if (result) + { + if ((tmp = configs->getstr(configs, "scRoot", false)) != NULL) {scRoot = tmp; V("Setting scRoot = %s", scRoot);} + snprintf(toybuf, sizeof(toybuf), "%s/current/bin", scRoot); + t0 = realpath(pwd, NULL); + t1 = realpath(toybuf, NULL); + if (strcmp(t0, t1) != 0) { - I("Loading configuration file (maybe) - %s", toybuf); - Lua2hashtbl(toybuf, configs, "config"); + I("Not in the configured scRoot. %s != %s", t0, t1); + if (qfile_exist(toybuf)) + { + chdir(toybuf); + result = scanForConfigs(cPaths); + result = result | scanForConfigs(oPaths); + } + else + C("The configured scRoot doesn't exist! Might need to actually install this. %s", scRoot); } + free(t1); + } + + if (result) + { + DEBUG = configs->getint(configs, "debug"); + V("Setting DEBUG = %d", DEBUG); + if ((vd = configs->get (configs, "loadAverageInc", NULL, false)) != NULL) {loadAverageInc = *((float *) vd); V("Setting loadAverageInc = %f", loadAverageInc);} + if ((vd = configs->get (configs, "simTimeOut", NULL, false)) != NULL) {simTimeOut = (int) *((float *) vd); V("Setting simTimeOut = %d", simTimeOut);} + if ((vd = configs->get (configs, "bulkSims", NULL, false)) != NULL) {bulkSims = (int) *((float *) vd); V("Setting bulkSims = %d", bulkSims);} + if ((tmp = configs->getstr(configs, "scRoot", false)) != NULL) {scRoot = tmp; V("Setting scRoot = %s", scRoot);} + if ((tmp = configs->getstr(configs, "scUser", false)) != NULL) {scUser = tmp; V("Setting scUser = %s", scUser);} + if ((tmp = configs->getstr(configs, "Tconsole", false)) != NULL) {Tconsole = tmp; V("Setting Tconsole = %s", Tconsole);} + if ((tmp = configs->getstr(configs, "Tsocket", false)) != NULL) {Tsocket = tmp; V("Setting Tsocket = %s", Tsocket);} + if ((tmp = configs->getstr(configs, "Ttab", false)) != NULL) {Ttab = tmp; V("Setting Ttab = %s", Ttab);} + if ((tmp = configs->getstr(configs, "backupIARsim", false)) != NULL) {backupIARsim = tmp; V("Setting backupIARsim = %s", backupIARsim);} + if ((tmp = configs->getstr(configs, "webRoot", false)) != NULL) {webRoot = tmp; V("Setting webRoot = %s", webRoot);} + if ((tmp = configs->getstr(configs, "URL", false)) != NULL) {URL = tmp; V("Setting URL = %s", URL);} + if ((vd = configs->get (configs, "seshRenew", NULL, false)) != NULL) {seshRenew = (int) *((float *) vd); V("Setting seshRenew = %d", seshRenew);} + if ((vd = configs->get (configs, "idleTimeOut", NULL, false)) != NULL) {idleTimeOut = (int) *((float *) vd); V("Setting idleTimeOut = %d", idleTimeOut);} + if ((vd = configs->get (configs, "seshTimeOut", NULL, false)) != NULL) {seshTimeOut = (int) *((float *) vd); V("Setting seshTimeOut = %d", seshTimeOut);} + if ((vd = configs->get (configs, "newbieTimeOut", NULL, false)) != NULL) {newbieTimeOut = (int) *((float *) vd); V("Setting newbieTimeOut = %d", newbieTimeOut);} + if ((tmp = configs->getstr(configs, "ToS", false)) != NULL) {ToS = tmp; V("Setting ToS = %s", ToS);} + if ((tmp = configs->getstr(configs, "webIframers", false)) != NULL) {webIframers = tmp; V("Setting webIframers = %s", webIframers);} } - DEBUG = configs->getint(configs, "debug"); - V("Setting DEBUG = %d", DEBUG); - if ((vd = configs->get (configs, "loadAverageInc", NULL, false)) != NULL) {loadAverageInc = *((float *) vd); V("Setting loadAverageInc = %f", loadAverageInc);} - if ((vd = configs->get (configs, "simTimeOut", NULL, false)) != NULL) {simTimeOut = (int) *((float *) vd); V("Setting simTimeOut = %d", simTimeOut);} - if ((vd = configs->get (configs, "bulkSims", NULL, false)) != NULL) {bulkSims = (int) *((float *) vd); V("Setting bulkSims = %d", bulkSims);} - if ((tmp = configs->getstr(configs, "scRoot", false)) != NULL) {scRoot = tmp; V("Setting scRoot = %s", scRoot);} - if ((tmp = configs->getstr(configs, "scUser", false)) != NULL) {scUser = tmp; V("Setting scUser = %s", scUser);} - if ((tmp = configs->getstr(configs, "Tconsole", false)) != NULL) {Tconsole = tmp; V("Setting Tconsole = %s", Tconsole);} - if ((tmp = configs->getstr(configs, "Tsocket", false)) != NULL) {Tsocket = tmp; V("Setting Tsocket = %s", Tsocket);} - if ((tmp = configs->getstr(configs, "Ttab", false)) != NULL) {Ttab = tmp; V("Setting Ttab = %s", Ttab);} - if ((tmp = configs->getstr(configs, "backupIARsim", false)) != NULL) {backupIARsim = tmp; V("Setting backupIARsim = %s", backupIARsim);} - if ((tmp = configs->getstr(configs, "webRoot", false)) != NULL) {webRoot = tmp; V("Setting webRoot = %s", webRoot);} - if ((tmp = configs->getstr(configs, "URL", false)) != NULL) {URL = tmp; V("Setting URL = %s", URL);} - if ((vd = configs->get (configs, "seshRenew", NULL, false)) != NULL) {seshRenew = (int) *((float *) vd); V("Setting seshRenew = %d", seshRenew);} - if ((vd = configs->get (configs, "idleTimeOut", NULL, false)) != NULL) {idleTimeOut = (int) *((float *) vd); V("Setting idleTimeOut = %d", idleTimeOut);} - if ((vd = configs->get (configs, "seshTimeOut", NULL, false)) != NULL) {seshTimeOut = (int) *((float *) vd); V("Setting seshTimeOut = %d", seshTimeOut);} - if ((vd = configs->get (configs, "newbieTimeOut", NULL, false)) != NULL) {newbieTimeOut = (int) *((float *) vd); V("Setting newbieTimeOut = %d", newbieTimeOut);} - if ((tmp = configs->getstr(configs, "ToS", false)) != NULL) {ToS = tmp; V("Setting ToS = %s", ToS);} - if ((tmp = configs->getstr(configs, "webIframers", false)) != NULL) {webIframers = tmp; V("Setting webIframers = %s", webIframers);} + else + C("No sledjChisl.conf.lua found!"); + + snprintf(toybuf, sizeof(toybuf), "%s/current/bin", scRoot); + t1 = realpath(toybuf, NULL); + if (strcmp(t0, t1)) + C("scRoot moved unexpectedly, check your sledjChisl.conf.lua files! %s != %s", t0, t1); + free(t1); + free(t0); + //////////////////////////////////////////////////////////////////////////////////////////////////// -- cgit v1.1