added prefork option

This commit is contained in:
Omar Polo 2021-02-07 12:05:32 +00:00
parent cfb8a77fd4
commit a709ddf5eb
6 changed files with 57 additions and 9 deletions

View File

@ -1,3 +1,7 @@
2021-02-07 Omar Polo <op@omarpolo.com>
* parse.y (option): added prefork option
2021-02-06 Omar Polo <op@omarpolo.com>
* parse.y (locopt): added ``block return'' and ``strip'' options

6
gmid.1
View File

@ -150,6 +150,12 @@ Both argument are strings.
.It Ic port Ar portno
The port to listen on.
By default is 1965.
.It Ic prefork Ar number
Run the specified number of server processes.
This increases the performance and prevents delays when connecting to
a server.
.Nm
runs 3 server processes by default, when not in config-less mode.
.It Ic protocols Ar string
Specify the TLS protocols to enable.
Refer to

42
gmid.c
View File

@ -391,6 +391,8 @@ setup_tls(void)
static int
listener_main(void)
{
drop_priv();
unblock_signals();
load_default_mime(&conf.mime);
load_vhosts();
sandbox();
@ -415,6 +417,9 @@ init_config(void)
conf.chroot = NULL;
conf.user = NULL;
/* we'll change this to 0 when running without config. */
conf.prefork = 3;
}
void
@ -498,6 +503,31 @@ usage(const char *me)
me);
}
static int
spawn_listeners(int *p)
{
int i;
close(p[0]);
exfd = p[1];
for (i = 0; i < conf.prefork -1; ++i) {
switch (fork()) {
case -1:
fatal("fork: %s", strerror(errno));
case 0: /* child */
setproctitle("server(%d)", i+1);
return listener_main();
}
}
if (conf.prefork == 0)
setproctitle("server");
else
setproctitle("server(%d)", conf.prefork);
return listener_main();
}
static int
serve(int argc, char **argv, int *p)
{
@ -538,13 +568,7 @@ serve(int argc, char **argv, int *p)
fatal("fork: %s", strerror(errno));
case 0: /* child */
setproctitle("listener");
close(p[0]);
exfd = p[1];
drop_priv();
unblock_signals();
listener_main();
_exit(0);
return spawn_listeners(p);
default: /* parent */
setproctitle("executor");
@ -663,8 +687,10 @@ main(int argc, char **argv)
if (conf.ipv6)
sock6 = make_socket(conf.port, AF_INET6);
if (configless)
if (configless) {
conf.prefork = 0;
return serve(argc, argv, p);
}
/* wait a sighup and reload the daemon */
for (;;) {

1
gmid.h
View File

@ -109,6 +109,7 @@ struct conf {
struct mime mime;
char *chroot;
char *user;
int prefork;
};
extern struct conf conf;

1
lex.l
View File

@ -60,6 +60,7 @@ type return TTYPE;
chroot return TCHROOT;
user return TUSER;
server return TSERVER;
prefork return TPREFORK;
location return TLOCATION;
cert return TCERT;

12
parse.y
View File

@ -44,6 +44,7 @@ char *ensure_absolute_path(char*);
int check_block_code(int);
char *check_block_fmt(char*);
int check_strip_no(int);
int check_prefork_num(int);
%}
@ -56,7 +57,7 @@ int check_strip_no(int);
}
%token TIPV6 TPORT TPROTOCOLS TMIME TDEFAULT TTYPE
%token TCHROOT TUSER TSERVER
%token TCHROOT TUSER TSERVER TPREFORK
%token TLOCATION TCERT TKEY TROOT TCGI TLANG TINDEX TAUTO
%token TSTRIP TBLOCK TRETURN TENTRYPOINT
%token TERR
@ -82,6 +83,7 @@ option : TIPV6 TBOOL { conf.ipv6 = $2; }
| TMIME TSTRING TSTRING { add_mime(&conf.mime, $2, $3); }
| TCHROOT TSTRING { conf.chroot = $2; }
| TUSER TSTRING { conf.user = $2; }
| TPREFORK TNUM { conf.prefork = check_prefork_num($2); }
;
vhosts : /* empty */
@ -282,3 +284,11 @@ check_strip_no(int n)
yyerror("invalid strip number %d", n);
return n;
}
int
check_prefork_num(int n)
{
if (n <= 0)
yyerror("invalid prefork number %d", n);
return n;
}