Commit Diff


commit - 7957cbd9aad6ace179287b2ddcbae0b14a25a90d
commit + 46af8c6cfe1f1ec15d93bc58791f4596c610785b
blob - 4aff056d6605ac7c46cf82ca8a818e8eb72fb316
blob + 487afdd27f0a98a858342c49dc5edd6cb9e90b28
--- gmid.1
+++ gmid.1
@@ -20,7 +20,7 @@
 .Sh SYNOPSIS
 .Nm
 .Bk -words
-.Op Fl n
+.Op Fl fn
 .Op Fl c Ar config
 |
 .Op Fl 6h
@@ -38,6 +38,8 @@ It can run without a configuration file with a limited
 available.
 If a configuration file is given, no other flags shall be given,
 except for
+.Fl f
+and
 .Fl n .
 .Pp
 .Nm
@@ -48,6 +50,8 @@ The options are as follows:
 .Bl -tag -width 14m
 .It Fl c Pa config
 Specify the configuration file.
+.It Fl f
+Stays and logs on the foreground.
 .It Fl n
 Check that the configuration is valid, but don't start the server.
 .El
@@ -121,12 +125,6 @@ A string is a sequence of characters wrapped in double
 .Dq like this .
 .Ss Global Options
 .Bl -tag -width 12m
-.It Ic daemon Ar bool
-Enable or disables the daemon mode.
-In daemon mode
-.Nm
-will log to syslog and fork in the background.
-By default is on.
 .It Ic ipv6 Ar bool
 Enable or disable IPv6 support.
 By default is off.
blob - 09a1d6fcfe20dc7f4b1feacd5e0027944c7b0e1d
blob + f9811b9299a58f40b069bfc26c9db82d3f729b26
--- gmid.c
+++ gmid.c
@@ -32,10 +32,8 @@
 
 struct vhost hosts[HOSTSLEN];
 
-int goterror;
+int exfd, foreground, goterror;
 
-int exfd;
-
 struct conf conf;
 
 struct tls *ctx;
@@ -47,7 +45,7 @@ fatal(const char *fmt, ...)
 
 	va_start(ap, fmt);
 
-	if (conf.foreground) {
+	if (foreground) {
 		vfprintf(stderr, fmt, ap);
 		fprintf(stderr, "\n");
 	} else
@@ -85,7 +83,7 @@ logs(int priority, struct client *c,
 	if (vasprintf(&fmted, fmt, ap) == -1)
 		fatal("vasprintf: %s", strerror(errno));
 
-	if (conf.foreground)
+	if (foreground)
 		fprintf(stderr, "%s:%s %s\n", hbuf, sbuf, fmted);
 	else {
 		if (asprintf(&s, "%s:%s %s", hbuf, sbuf, fmted) == -1)
@@ -152,7 +150,7 @@ log_request(struct client *c, char *meta, size_t l)
 	if ((t = gmid_strnchr(meta, '\r', l)) == NULL)
 		t = meta + len;
 
-	if (conf.foreground)
+	if (foreground)
 		fprintf(stderr, "%s:%s GET %s %.*s\n", hbuf, sbuf, b,
 		    (int)(t - meta), meta);
 	else
@@ -474,9 +472,6 @@ listener_main(void)
 	int sock4, sock6;
 
 	load_default_mime(&conf.mime);
-
-	if (!conf.foreground && daemon(0, 1) == -1)
-		exit(1);
 
 	sock4 = make_socket(conf.port, AF_INET);
 	sock6 = -1;
@@ -500,7 +495,6 @@ init_config(void)
 	for (i = 0; i < HOSTSLEN; ++i)
 		hosts[i].dirfd = -1;
 
-	conf.foreground = 0;
 	conf.port = 1965;
 	conf.ipv6 = 0;
 	conf.protos = TLS_PROTOCOL_TLSv1_2 | TLS_PROTOCOL_TLSv1_3;
@@ -544,7 +538,7 @@ void
 usage(const char *me)
 {
 	fprintf(stderr,
-	    "USAGE: %s [-n] [-c config] | [-6h] [-d certs-dir] [-H host]"
+	    "USAGE: %s [-fn] [-c config] | [-6h] [-d certs-dir] [-H host]"
 	    "       [-p port] [-x cgi] [dir]",
 	    me);
 }
@@ -558,7 +552,7 @@ main(int argc, char **argv)
 
 	init_config();
 
-	while ((ch = getopt(argc, argv, "6c:d:H:hnp:x:")) != -1) {
+	while ((ch = getopt(argc, argv, "6c:d:fH:hnp:x:")) != -1) {
 		switch (ch) {
 		case '6':
 			conf.ipv6 = 1;
@@ -574,6 +568,10 @@ main(int argc, char **argv)
 			configless = 1;
 			break;
 
+		case 'f':
+			foreground = 1;
+			break;
+
 		case 'H':
 			hostname = optarg;
 			configless = 1;
@@ -614,8 +612,6 @@ main(int argc, char **argv)
 
 		parse_conf(config_path);
 	} else {
-		conf.foreground = 1;
-
 		if (hostname == NULL)
 			hostname = "localhost";
 		if (certs_dir == NULL)
@@ -657,9 +653,9 @@ main(int argc, char **argv)
 	signal(SIGINFO, sig_handler);
 #endif
 	signal(SIGUSR2, sig_handler);
+	signal(SIGHUP, SIG_IGN);
 
-	if (!conf.foreground) {
-		signal(SIGHUP, SIG_IGN);
+	if (!foreground && !configless) {
 		if (daemon(1, 1) == -1)
 			fatal("daemon: %s", strerror(errno));
 	}
blob - 47a053630219f8ad6fcf58063659192f45fcc53e
blob + 862792f230182cda45b185648eac56aabb4efe95
--- gmid.h
+++ gmid.h
@@ -95,7 +95,6 @@ struct mime {
 };
 
 struct conf {
-	int		 foreground;
 	int		 port;
 	int		 ipv6;
 	uint32_t	 protos;
blob - 099b3c4b19d822ba495bb7d4980f114d99cbd54f
blob + f7e041d20e78bf48c7a58a601b7b971c85b95495
--- lex.l
+++ lex.l
@@ -51,7 +51,6 @@
 on		yylval.num = 1; return TBOOL;
 off		yylval.num = 0; return TBOOL;
 
-daemon		return TDAEMON;
 ipv6		return TIPV6;
 port		return TPORT;
 protocols	return TPROTOCOLS;
blob - 97934599fd9039217e0a83785418fb3fb5a25d6f
blob + 56a393577063eca8a92d8c78bb7c85f1941e56bd
--- parse.y
+++ parse.y
@@ -45,7 +45,7 @@ extern void yyerror(const char*);
 	int		 num;
 }
 
-%token TDAEMON TIPV6 TPORT TPROTOCOLS TMIME TDEFAULT TTYPE
+%token TIPV6 TPORT TPROTOCOLS TMIME TDEFAULT TTYPE
 %token TCHROOT TUSER TSERVER
 %token TLOCATION TCERT TKEY TROOT TCGI TLANG TINDEX TAUTO
 %token TERR
@@ -62,8 +62,7 @@ options		: /* empty */
 		| options option
 		;
 
-option		: TDAEMON TBOOL		{ conf.foreground = !$2; }
-		| TIPV6 TBOOL		{ conf.ipv6 = $2; }
+option		: TIPV6 TBOOL		{ conf.ipv6 = $2; }
 		| TPORT TNUM		{ conf.port = $2; }
 		| TPROTOCOLS TSTRING {
 			if (tls_config_parse_protocols(&conf.protos, $2) == -1)
blob - ca87701f35435c53dcc1f64a02f7f06b21ff1509
blob + bc0f0eee574a4bd360e659e3c4c26ed9164098ed
--- regress/runtime
+++ regress/runtime
@@ -6,7 +6,6 @@ set -e
 # generates a configuration file reg.conf
 config() {
 	cat <<EOF > reg.conf
-daemon off
 ipv6 off
 port 10965
 $1
@@ -43,7 +42,7 @@ raw() {
 
 run() {
 	# filter out logs for GET requests
-	(./../gmid -c reg.conf 2>&1 | grep -v GET) >&2 &
+	(./../gmid -f -c reg.conf 2>&1 | grep -v GET) >&2 &
 	pid=$!
 	# give gmid time to bind the port, otherwise we end up
 	# executing gg when gmid isn't ready yet.