Commit Diff


commit - 5eb3fc905f5e3bd2f2d586fb1e0ceda879500b3e
commit + f0a01fc742e83b3f4736b5d64af3ab18148afc5a
blob - e69c10860b5e61366d2de0a7607f218f3e22bb0a
blob + 94403c060db24d84cacd1d5fb1b03af8df57770c
--- ChangeLog
+++ ChangeLog
@@ -1,4 +1,6 @@
 2021-10-09  Omar Polo  <op@omarpolo.com>
+
+	* parse.y (print_conf): multiple -n to dump the parsed configuration
 
 	* contrib/gencert: add gencert, a simple script to generate self-signed certs
 
blob - b9944ead3b4311d8c30bbd6705224a4a736a2e70
blob + 39121037af40309a08e71b3e26653c447be9d02f
--- gmid.1
+++ gmid.1
@@ -62,6 +62,8 @@ in the config file if present.
 Stays and logs on the foreground.
 .It Fl n
 Check that the configuration is valid, but don't start the server.
+If specified two or more time, dump the configuration in addition to
+verify it.
 .It Fl P Pa pidfile
 Write daemon's pid to the given location.
 .Ar pidfile
blob - f0ffa3ef389cff98e442c2da2c9c20de1ad98dab
blob + 1b91e298a97cc3d37d1a5d4ff58af35f3b2ed3e3
--- gmid.c
+++ gmid.c
@@ -589,7 +589,7 @@ main(int argc, char **argv)
 			return 0;
 
 		case 'n':
-			conftest = 1;
+			conftest++;
 			break;
 
 		case 'P':
@@ -639,7 +639,9 @@ main(int argc, char **argv)
 		if (config_path == NULL)
 			fatal("missing configuration");
 		parse_conf(config_path);
-		puts("config OK");
+		fprintf(stderr, "config OK\n");
+		if (conftest > 1)
+			print_conf();
 		return 0;
 	}
 
blob - a691b751848c60f07699c64b85205891353b2d08
blob + ecd53a26758d1f5c8b06a71a2d45c722a2155544
--- gmid.h
+++ gmid.h
@@ -291,6 +291,7 @@ void		 drop_priv(void);
 
 void		 yyerror(const char*, ...);
 void		 parse_conf(const char*);
+void		 print_conf(void);
 int		 cmdline_symset(char *);
 
 /* log.c */
blob - 54282a36b33c7144b66bf3b0984a1efb84c0e595
blob + 255be767e5e0e7036a0052ae4030359d73847cf0
--- parse.y
+++ parse.y
@@ -811,6 +811,33 @@ parse_conf(const char *filename)
 		exit(1);
 }
 
+void
+print_conf(void)
+{
+	struct vhost	*h;
+	/* struct location	*l; */
+	/* struct envlist	*e; */
+	/* struct alist	*a; */
+
+	if (conf.chroot != NULL)
+		printf("chroot \"%s\"\n", conf.chroot);
+	printf("ipv6 %s\n", conf.ipv6 ? "on" : "off");
+	/* XXX: defined mimes? */
+	printf("port %d\n", conf.port);
+	printf("prefork %d\n", conf.prefork);
+	/* XXX: protocols? */
+	if (conf.user != NULL)
+		printf("user \"%s\"\n", conf.user);
+
+	TAILQ_FOREACH(h, &hosts, vhosts) {
+		printf("\nserver \"%s\" {\n", h->domain);
+		printf("	cert \"%s\"\n", h->cert);
+		printf("	key \"%s\"\n", h->key);
+		/* TODO: print locations... */
+		printf("}\n");
+	}
+}
+
 int
 symset(const char *name, const char *val, int persist)
 {