diff options
author | schnetter <schnetter@83718e91-0e4f-0410-abf4-91180603181f> | 2005-06-07 09:54:22 +0000 |
---|---|---|
committer | schnetter <schnetter@83718e91-0e4f-0410-abf4-91180603181f> | 2005-06-07 09:54:22 +0000 |
commit | 1b516df1a9c5d9e963f08249c0e917ab15c0a356 (patch) | |
tree | d87c216247a5553df6ce5190fc3ad962eb51bd29 /src/portal.cc | |
parent | f5739f069a23a5fd7f94d8436939d335c16dc996 (diff) |
Increate the default announce interval from one to ten minutes.
Introduce the concept of a "relay host" for announcing: If a relay
host is used, ssh into that host before connecting to the portal.
Try some heuristics to determine the relay host automatically if none
is provided.
git-svn-id: http://svn.cactuscode.org/arrangements/CactusUtils/Formaline/trunk@40 83718e91-0e4f-0410-abf4-91180603181f
Diffstat (limited to 'src/portal.cc')
-rw-r--r-- | src/portal.cc | 185 |
1 files changed, 157 insertions, 28 deletions
diff --git a/src/portal.cc b/src/portal.cc index 0a86256..b5f79a9 100644 --- a/src/portal.cc +++ b/src/portal.cc @@ -12,8 +12,11 @@ #include <string> #include <sstream> +#include <unistd.h> + #include "cctk.h" #include "cctk_Parameters.h" +#include "util_Network.h" #include "portal.hh" @@ -23,9 +26,14 @@ namespace Formaline { using namespace std; + + - - + static bool + is_clean_for_shell (char const * string); + + + portal:: portal (char const * const id, enum state const st) @@ -135,34 +143,14 @@ namespace Formaline // Check that the file name is sane - for (char const * p = scriptfilename; * p; ++ p) + if (! is_clean_for_shell (scriptfilename)) { - if (! isalnum (* p)) + static bool did_complain = false; + if (! did_complain) { - // Allow only certain characters - switch (* p) - { - case '+': - case ',': - case '-': - case '.': - case '/': - case ':': - case '_': - case '~': - break; - default: - // We don't like this character - { - static bool did_complain = false; - if (! did_complain) - { - did_complain = true; - CCTK_WARN (1, "Strange character in file name -- not calling system()"); - return; - } - } - } + did_complain = true; + CCTK_WARN (1, "Strange character in file name -- not calling system()"); + return; } } @@ -178,9 +166,120 @@ namespace Formaline + bool my_use_relay_host = use_relay_host; + char const * my_relay_host = 0; + if (my_use_relay_host) + { + my_relay_host = relay_host; + if (strcmp (my_relay_host, "") == 0) + { + // Determine a good relay host + char run_host [1000]; + Util_GetHostName (run_host, sizeof run_host); + if (strncmp (run_host, "ic", 2) == 0 && strlen (run_host) == 6) + { + // Peyote or Lagavulin + int const node = atoi (run_host + 2); + if (node < 192) + { + // Peyote + my_relay_host = "peyote"; + } + else + { + // Lagavulin + my_relay_host = "lagavulin"; + } + } + else if (strncmp (run_host, "mike", 4) == 0 && strlen (run_host) == 7) + { + // Supermike + my_use_relay_host = false; + } + else + { + // Don't know a good relay host; try without + my_use_relay_host = false; + } + + if (verbose) + { + if (my_use_relay_host) + { + CCTK_VInfo (CCTK_THORNSTRING, + "Using \"%s\" as relay host", my_relay_host); + } + else + { + CCTK_INFO ("Announcing without relay host"); + } + } + } + } + + if (my_use_relay_host) + { + // Check that the relay host name is sane + if (! is_clean_for_shell (my_relay_host)) + { + static bool did_complain = false; + if (! did_complain) + { + did_complain = true; + CCTK_WARN (1, "Strange character in relay host name -- not calling system()"); + return; + } + } + } + + + + char cwd[10000]; + if (my_use_relay_host) + { + // Get the current directory + char * const cwderr = getcwd (cwd, sizeof cwd); + if (cwderr == NULL) { + static bool did_complain = false; + if (! did_complain) + { + did_complain = true; + CCTK_WARN (1, "Cannot determine current working directory"); + return; + } + } + + // Check that the current directory name is sane + if (! is_clean_for_shell (cwd)) + { + static bool did_complain = false; + if (! did_complain) + { + did_complain = true; + CCTK_WARN (1, "Strange character in current directory -- not calling system()"); + return; + } + } + } + else + { + cwd[0] = '\0'; + } + + + // Send the data ostringstream cmdbuf; + if (my_use_relay_host) + { + cmdbuf << "ssh " << my_relay_host << " '" + << "cd " << cwd << " && "; + } cmdbuf << scriptfilenamestr << " < /dev/null > /dev/null 2> /dev/null"; + if (my_use_relay_host) + { + cmdbuf << "'"; + } string const cmdstr = cmdbuf.str(); char const * const cmd = cmdstr.c_str(); @@ -297,5 +396,35 @@ namespace Formaline } + + static bool + is_clean_for_shell (char const * const string) + { + for (char const * p = string; * p; ++ p) + { + if (! isalnum (* p)) + { + // Allow only certain characters + switch (* p) + { + case '+': + case ',': + case '-': + case '.': + case '/': + case ':': + case '_': + case '~': + break; + default: + // We don't like this character + return false; + } + } + } + return true; + } + + } // namespace Formaline |