diff options
-rw-r--r-- | src/Startup.c | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/src/Startup.c b/src/Startup.c index 440a888..57e43a5 100644 --- a/src/Startup.c +++ b/src/Startup.c @@ -87,7 +87,9 @@ static int thread_started = 0; static int http_actualport=5555; /* bad bad static var (should use GH) */ int HTTP_Startup(void) { + int use_port; httpState state; + char *environ_port; DECLARE_CCTK_PARAMETERS @@ -99,7 +101,29 @@ int HTTP_Startup(void) } #endif - http_actualport = port; + /* get HTTPD port to use from the 'port' parameter or the shell environment */ + use_port = port; + environ_port = getenv ("HTTPD_PORT"); + if (environ_port) + { + use_port = atoi (environ_port); + if (use_port >= 1 && use_port <= 65535) + { + CCTK_VInfo (CCTK_THORNSTRING, "Environment variable HTTPD_PORT is set to " + "%d and will override parameter setting from 'HTTPD::port'", + use_port); + } + else + { + CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, + "Environment variable HTTPD_PORT is set to '%s' which cannot " + "be parsed as a valid port number. Using parameter setting " + "'HTTPD::port = %d' instead.", environ_port, (int) port); + use_port = port; + } + } + http_actualport = use_port; + if(CCTK_MyProc(NULL) == 0) { /* Does the server provide any pages by default ? */ @@ -108,11 +132,11 @@ int HTTP_Startup(void) HTTP_RegisterPages(); } - http_actualport = HTTP_SetupServer(port, queue_length, hunt); + http_actualport = HTTP_SetupServer(use_port, queue_length, hunt); } /* Do we need to redirect to a master server ? */ - HTTP_SetupRedirect(port,queue_length,hunt); + HTTP_SetupRedirect(use_port,queue_length,hunt); HTTP_UpdateState(NULL, &state); |