changeset 1034:0000cfa65cbb

daemon: make bind address configurable The socket bind address can now be specified via the scgi-host config knob. The default is localhost. Signed-off-by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
author Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
date Wed, 05 Aug 2020 19:43:16 -0400
parents 29e9acfeebeb
children 795556be4cba
files config.c config.cmake config.h.in daemon.c lisplint.c
diffstat 5 files changed, 16 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/config.c	Fri Jul 24 20:03:18 2020 -0400
+++ b/config.c	Wed Aug 05 19:43:16 2020 -0400
@@ -81,14 +81,16 @@
 	*ret = sexpr_alist_lookup_val(lv, vname);
 }
 
-static void config_load_scgi_port(struct val *lv)
+static void config_load_scgi_hostport(struct val *lv)
 {
-	uint64_t tmp;
+	uint64_t port;
 
-	config_load_u64(lv, CONFIG_SCGI_PORT, &tmp, DEFAULT_SCGI_PORT);
+	config_load_str(lv, CONFIG_SCGI_HOST, &config.scgi_host,
+			DEFAULT_SCGI_HOST);
+	config_load_u64(lv, CONFIG_SCGI_PORT, &port, DEFAULT_SCGI_PORT);
 
-	if (tmp < 65536)
-		config.scgi_port = tmp;
+	if (port < 65536)
+		config.scgi_port = port;
 	else
 		config.scgi_port = DEFAULT_SCGI_PORT;
 }
@@ -130,7 +132,7 @@
 		lv = NULL;
 	}
 
-	config_load_scgi_port(lv);
+	config_load_scgi_hostport(lv);
 	config_load_scgi_threads(lv);
 	config_load_u64(lv, CONFIG_HTML_INDEX_STORIES, &config.html_index_stories,
 			DEFAULT_HTML_INDEX_STORIES);
@@ -164,6 +166,7 @@
 
 	val_putref(lv);
 
+	DBG("config.scgi_host = %s", str_cstr(config.scgi_host));
 	DBG("config.scgi_port = %u", config.scgi_port);
 	DBG("config.scgi_threads = %d", config.scgi_threads);
 	DBG("config.html_index_stories = %"PRIu64, config.html_index_stories);
--- a/config.cmake	Fri Jul 24 20:03:18 2020 -0400
+++ b/config.cmake	Wed Aug 05 19:43:16 2020 -0400
@@ -36,6 +36,7 @@
 	endif()
 endmacro()
 
+set_default(DEFAULT_SCGI_HOST		"localhost")
 set_default(DEFAULT_SCGI_PORT		2014)
 
 set_default(DEFAULT_HTML_INDEX_STORIES	10)
--- a/config.h.in	Fri Jul 24 20:03:18 2020 -0400
+++ b/config.h.in	Wed Aug 05 19:43:16 2020 -0400
@@ -26,6 +26,7 @@
 #cmakedefine HAVE_PRIV_H 1
 
 /* settings */
+#cmakedefine DEFAULT_SCGI_HOST		"${DEFAULT_SCGI_HOST}"
 #cmakedefine DEFAULT_SCGI_PORT		${DEFAULT_SCGI_PORT}
 
 #cmakedefine DEFAULT_HTML_INDEX_STORIES	${DEFAULT_HTML_INDEX_STORIES}
@@ -51,6 +52,7 @@
  * config alist symbol names
  */
 
+#define CONFIG_SCGI_HOST		"scgi-host"
 #define CONFIG_SCGI_PORT		"scgi-port"
 #define CONFIG_SCGI_THREADS		"scgi-threads"
 #define CONFIG_HTML_INDEX_STORIES	"html-index-stories"
@@ -78,6 +80,7 @@
 #include <stdint.h>
 
 struct config {
+	struct str *scgi_host;
 	uint16_t scgi_port;
 	int scgi_threads;
 	uint64_t html_index_stories;
--- a/daemon.c	Fri Jul 24 20:03:18 2020 -0400
+++ b/daemon.c	Wed Aug 05 19:43:16 2020 -0400
@@ -145,8 +145,8 @@
 	if (ret)
 		goto err;
 
-	ret = scgisvc(NULL, config.scgi_port, config.scgi_threads,
-		      &ops, NULL);
+	ret = scgisvc(str_cstr(config.scgi_host), config.scgi_port,
+		      config.scgi_threads, &ops, NULL);
 	if (ret)
 		goto err;
 
--- a/lisplint.c	Fri Jul 24 20:03:18 2020 -0400
+++ b/lisplint.c	Wed Aug 05 19:43:16 2020 -0400
@@ -130,6 +130,7 @@
 {
 	bool ret;
 
+	ret = check_type(fname, lv, CONFIG_SCGI_HOST, VT_STR, false);
 	ret = check_type(fname, lv, CONFIG_SCGI_PORT, VT_INT, false);
 	ret = check_type(fname, lv, CONFIG_SCGI_THREADS, VT_INT, false) && ret;
 	ret = check_type(fname, lv, CONFIG_HTML_INDEX_STORIES, VT_INT, false) && ret;