diff options
-rw-r--r-- | gmid.1 | 12 | ||||
-rw-r--r-- | gmid.c | 28 | ||||
-rw-r--r-- | gmid.h | 1 | ||||
-rw-r--r-- | lex.l | 1 | ||||
-rw-r--r-- | parse.y | 5 | ||||
-rwxr-xr-x | regress/runtime | 3 |
6 files changed, 20 insertions, 30 deletions
@@ -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 set of features 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 quotes, .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. @@ -32,9 +32,7 @@ struct vhost hosts[HOSTSLEN]; -int goterror; - -int exfd; +int exfd, foreground, goterror; struct conf conf; @@ -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 @@ -475,9 +473,6 @@ listener_main(void) load_default_mime(&conf.mime); - if (!conf.foreground && daemon(0, 1) == -1) - exit(1); - sock4 = make_socket(conf.port, AF_INET); sock6 = -1; if (conf.ipv6) @@ -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)); } @@ -95,7 +95,6 @@ struct mime { }; struct conf { - int foreground; int port; int ipv6; uint32_t protos; @@ -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; @@ -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) diff --git a/regress/runtime b/regress/runtime index ca87701..bc0f0ee 100755 --- a/regress/runtime +++ b/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. |