"GOT", but the "O" is a cute, smiling pufferfish. Index | Thread | Search

From:
Stefan Sperling <stsp@stsp.name>
Subject:
Re: gotwebd no-config startup
To:
gameoftrees@openbsd.org
Date:
Tue, 2 Aug 2022 23:27:19 +0200

Download raw body.

Thread
On Fri, Jul 29, 2022 at 08:56:19AM -0600, Tracey Emery wrote:
> On Fri, Jul 29, 2022 at 04:41:21PM +0200, Stefan Sperling wrote:
> > On Fri, Jul 29, 2022 at 08:18:36AM -0600, Tracey Emery wrote:
> > > >  
> > > >  	/* just add default server if no config specified */
> > > > -	if (gotwebd->server_cnt == 0) {
> > > > -		new_srv = conf_new_server(D_SITENAME);
> > > > -		log_debug("%s: adding default server %s", __func__, D_SITENAME);
> > > > -	}
> > > > +	if (gotwebd->server_cnt == 0)
> > > > +		add_default_server();
> > > >  
> > > not needed
> > > -------------------
> > 
> > Are you sure? There are two cases, one where the file does not exist at all,
> > and one where the file exists but is empty. As I understand the above code,
> > it tries to handle an empty config file?
> > 
> 
> No, you're correct. I forgot about the empty config file scenario.

This works for me in my test setup, without a config file, and with
an empty config file. Basically it is my previous diff + the
sockets_parse_sockets() call you suggested.

-----------------------------------------------
commit 915dd6737d3480ea0796952c719378bbf4b2cb6f (gotwebd-noconf)
from: Stefan Sperling <stsp@stsp.name>
date: Tue Aug  2 21:24:49 2022 UTC
 
 make gotwebd start up without a config file
 
diff d7c808b798d30921f53b27c8789f3449e86bc8d8 915dd6737d3480ea0796952c719378bbf4b2cb6f
commit - d7c808b798d30921f53b27c8789f3449e86bc8d8
commit + 915dd6737d3480ea0796952c719378bbf4b2cb6f
blob - e624bc6b2182b136d6389e4baad9c214e8c5c4fd
blob + ecce1768fa5b41babe7ad5226f47933e94aeaf64
--- gotwebd/parse.y
+++ gotwebd/parse.y
@@ -815,21 +815,31 @@ closefile(struct file *xfile)
 	free(xfile);
 }
 
+static void
+add_default_server(void)
+{
+	new_srv = conf_new_server(D_SITENAME);
+	log_debug("%s: adding default server %s", __func__, D_SITENAME);
+}
+
 int
 parse_config(const char *filename, struct gotwebd *env)
 {
 	struct sym *sym, *next;
 
-	file = newfile(filename, 0);
-	if (file == NULL)
-		/* just return, as we don't require a conf file */
-		return (0);
-
 	if (config_init(env) == -1)
 		fatalx("failed to initialize configuration");
 
 	gotwebd = env;
 
+	file = newfile(filename, 0);
+	if (file == NULL) {
+		add_default_server();
+		sockets_parse_sockets(env);
+		/* just return, as we don't require a conf file */
+		return (0);
+	}
+
 	yyparse();
 	errors = file->errors;
 	closefile(file);
@@ -851,10 +861,8 @@ parse_config(const char *filename, struct gotwebd *env
 		return (-1);
 
 	/* just add default server if no config specified */
-	if (gotwebd->server_cnt == 0) {
-		new_srv = conf_new_server(D_SITENAME);
-		log_debug("%s: adding default server %s", __func__, D_SITENAME);
-	}
+	if (gotwebd->server_cnt == 0)
+		add_default_server();
 
 	/* setup our listening sockets */
 	sockets_parse_sockets(env);