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

From:
Stefan Sperling <stsp@stsp.name>
Subject:
gotwebd no-config startup
To:
gameoftrees@openbsd.org
Date:
Fri, 29 Jul 2022 12:45:25 +0200

Download raw body.

Thread
The comments are lies, gotwebd doesn't work without a config file.
It segfaults instead.

ok?

diff 06ba6b54c127173003258cd28d72fd0b8cf6ffbf 278d4be54018f28153a3fdb34575fee54075ed9e
commit - 06ba6b54c127173003258cd28d72fd0b8cf6ffbf
commit + 278d4be54018f28153a3fdb34575fee54075ed9e
blob - e624bc6b2182b136d6389e4baad9c214e8c5c4fd
blob + 9691c93542610a12b3f27d039d14910701d61348
--- gotwebd/parse.y
+++ gotwebd/parse.y
@@ -815,21 +815,30 @@ 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();
+		/* just return, as we don't require a conf file */
+		return (0);
+	}
+
 	yyparse();
 	errors = file->errors;
 	closefile(file);
@@ -851,10 +860,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);