mirror of https://github.com/omar-polo/gmid.git
move fastcgi from global var to the config struct
while here also make them a list rather than a fixed-size array.
This commit is contained in:
parent
1962764c62
commit
5d22294a59
39
config.c
39
config.c
|
@ -32,6 +32,8 @@ config_init(void)
|
|||
|
||||
TAILQ_INIT(&hosts);
|
||||
|
||||
TAILQ_INIT(&conf.fcgi);
|
||||
|
||||
conf.port = 1965;
|
||||
conf.ipv6 = 0;
|
||||
conf.protos = TLS_PROTOCOL_TLSv1_2 | TLS_PROTOCOL_TLSv1_3;
|
||||
|
@ -48,6 +50,7 @@ void
|
|||
config_free(void)
|
||||
{
|
||||
struct privsep *ps;
|
||||
struct fcgi *f, *tf;
|
||||
struct vhost *h, *th;
|
||||
struct location *l, *tl;
|
||||
struct proxy *p, *tp;
|
||||
|
@ -67,12 +70,17 @@ config_free(void)
|
|||
}
|
||||
|
||||
free_mime(&conf.mime);
|
||||
TAILQ_FOREACH_SAFE(f, &conf.fcgi, fcgi, tf) {
|
||||
TAILQ_REMOVE(&conf.fcgi, f, fcgi);
|
||||
free(f);
|
||||
}
|
||||
memset(&conf, 0, sizeof(conf));
|
||||
|
||||
conf.ps = ps;
|
||||
conf.sock4 = conf.sock6 = -1;
|
||||
conf.protos = TLS_PROTOCOL_TLSv1_2 | TLS_PROTOCOL_TLSv1_3;
|
||||
init_mime(&conf.mime);
|
||||
TAILQ_INIT(&conf.fcgi);
|
||||
|
||||
TAILQ_FOREACH_SAFE(h, &hosts, vhosts, th) {
|
||||
free(h->cert_path);
|
||||
|
@ -117,8 +125,6 @@ config_free(void)
|
|||
TAILQ_REMOVE(&hosts, h, vhosts);
|
||||
free(h);
|
||||
}
|
||||
|
||||
memset(fcgi, 0, sizeof(fcgi));
|
||||
}
|
||||
|
||||
static int
|
||||
|
@ -236,10 +242,11 @@ config_send_socks(struct conf *conf)
|
|||
}
|
||||
|
||||
int
|
||||
config_send(struct conf *conf, struct fcgi *fcgi, struct vhosthead *hosts)
|
||||
config_send(struct conf *conf, struct vhosthead *hosts)
|
||||
{
|
||||
struct privsep *ps = conf->ps;
|
||||
struct etm *m;
|
||||
struct fcgi *fcgi;
|
||||
struct vhost *h;
|
||||
struct location *l;
|
||||
struct proxy *p;
|
||||
|
@ -272,11 +279,10 @@ config_send(struct conf *conf, struct fcgi *fcgi, struct vhosthead *hosts)
|
|||
if (proc_flush_imsg(ps, PROC_SERVER, -1) == -1)
|
||||
return -1;
|
||||
|
||||
for (i = 0; i < FCGI_MAX; ++i) {
|
||||
if (*fcgi[i].path == '\0')
|
||||
break;
|
||||
TAILQ_FOREACH(fcgi, &conf->fcgi, fcgi) {
|
||||
log_debug("sending fastcgi %s", fcgi->path);
|
||||
if (proc_compose(ps, PROC_SERVER, IMSG_RECONF_FCGI,
|
||||
&fcgi[i], sizeof(fcgi[i])) == -1)
|
||||
fcgi, sizeof(*fcgi)) == -1)
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -442,13 +448,13 @@ config_recv(struct conf *conf, struct imsg *imsg)
|
|||
static struct proxy *p;
|
||||
struct privsep *ps = conf->ps;
|
||||
struct etm m;
|
||||
struct fcgi *f;
|
||||
struct fcgi *fcgi;
|
||||
struct vhost *vh, vht;
|
||||
struct location *loc;
|
||||
struct envlist *env;
|
||||
struct alist *alias;
|
||||
struct proxy *proxy;
|
||||
size_t i, datalen;
|
||||
size_t datalen;
|
||||
|
||||
datalen = IMSG_DATA_SIZE(imsg);
|
||||
|
||||
|
@ -501,16 +507,11 @@ config_recv(struct conf *conf, struct imsg *imsg)
|
|||
break;
|
||||
|
||||
case IMSG_RECONF_FCGI:
|
||||
for (i = 0; i < FCGI_MAX; ++i) {
|
||||
f = &fcgi[i];
|
||||
if (*f->path != '\0')
|
||||
continue;
|
||||
IMSG_SIZE_CHECK(imsg, f);
|
||||
memcpy(f, imsg->data, datalen);
|
||||
break;
|
||||
}
|
||||
if (i == FCGI_MAX)
|
||||
fatalx("recv too many fcgi");
|
||||
IMSG_SIZE_CHECK(imsg, fcgi);
|
||||
fcgi = xcalloc(1, sizeof(*fcgi));
|
||||
memcpy(fcgi, imsg->data, datalen);
|
||||
log_debug("received fcgi %s", fcgi->path);
|
||||
TAILQ_INSERT_TAIL(&conf->fcgi, fcgi, fcgi);
|
||||
break;
|
||||
|
||||
case IMSG_RECONF_HOST:
|
||||
|
|
1
ge.c
1
ge.c
|
@ -34,7 +34,6 @@
|
|||
struct conf conf;
|
||||
int privsep_process;
|
||||
|
||||
struct fcgi fcgi[FCGI_MAX]; /* just because it's referenced */
|
||||
struct vhosthead hosts = TAILQ_HEAD_INITIALIZER(hosts);
|
||||
|
||||
static const struct option opts[] = {
|
||||
|
|
4
gmid.c
4
gmid.c
|
@ -58,8 +58,6 @@ static const struct option longopts[] = {
|
|||
{NULL, 0, NULL, 0},
|
||||
};
|
||||
|
||||
struct fcgi fcgi[FCGI_MAX];
|
||||
|
||||
struct vhosthead hosts;
|
||||
|
||||
int sock4, sock6;
|
||||
|
@ -316,7 +314,7 @@ main_configure(struct conf *conf)
|
|||
if (proc_compose(ps, PROC_SERVER, IMSG_RECONF_START, NULL, 0) == -1)
|
||||
return -1;
|
||||
|
||||
if (config_send(conf, fcgi, &hosts) == -1)
|
||||
if (config_send(conf, &hosts) == -1)
|
||||
return -1;
|
||||
|
||||
if (proc_compose(ps, PROC_SERVER, IMSG_RECONF_END, NULL, 0) == -1)
|
||||
|
|
8
gmid.h
8
gmid.h
|
@ -80,7 +80,6 @@
|
|||
#define FCGI_NAME_MAX 511
|
||||
#define FCGI_VAL_MAX 511
|
||||
|
||||
#define FCGI_MAX 32
|
||||
#define PROC_MAX_INSTANCES 16
|
||||
|
||||
/* forward declaration */
|
||||
|
@ -103,12 +102,13 @@ struct parser {
|
|||
const char *err;
|
||||
};
|
||||
|
||||
TAILQ_HEAD(fcgihead, fcgi);
|
||||
struct fcgi {
|
||||
int id;
|
||||
char path[PATH_MAX];
|
||||
char port[32];
|
||||
TAILQ_ENTRY(fcgi) fcgi;
|
||||
};
|
||||
extern struct fcgi fcgi[FCGI_MAX];
|
||||
|
||||
TAILQ_HEAD(proxyhead, proxy);
|
||||
struct proxy {
|
||||
|
@ -224,6 +224,8 @@ struct conf {
|
|||
struct event evsock4;
|
||||
int sock6;
|
||||
struct event evsock6;
|
||||
|
||||
struct fcgihead fcgi;
|
||||
};
|
||||
|
||||
extern const char *config_path;
|
||||
|
@ -338,7 +340,7 @@ void log_request(struct client *, char *, size_t);
|
|||
/* config.c */
|
||||
void config_init(void);
|
||||
void config_free(void);
|
||||
int config_send(struct conf *, struct fcgi *, struct vhosthead *);
|
||||
int config_send(struct conf *, struct vhosthead *);
|
||||
int config_recv(struct conf *, struct imsg *);
|
||||
|
||||
/* parse.y */
|
||||
|
|
25
parse.y
25
parse.y
|
@ -1124,27 +1124,24 @@ int
|
|||
fastcgi_conf(const char *path, const char *port)
|
||||
{
|
||||
struct fcgi *f;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < FCGI_MAX; ++i) {
|
||||
f = &fcgi[i];
|
||||
|
||||
if (*f->path == '\0') {
|
||||
f->id = i;
|
||||
(void) strlcpy(f->path, path, sizeof(f->path));
|
||||
if (port != NULL)
|
||||
(void) strlcpy(f->port, port, sizeof(f->port));
|
||||
return i;
|
||||
}
|
||||
int i = 0;
|
||||
|
||||
TAILQ_FOREACH(f, &conf.fcgi, fcgi) {
|
||||
if (!strcmp(f->path, path) &&
|
||||
((port == NULL && *f->port == '\0') ||
|
||||
!strcmp(f->port, port)))
|
||||
return i;
|
||||
++i;
|
||||
}
|
||||
|
||||
yyerror("too much `fastcgi' rules defined.");
|
||||
return -1;
|
||||
f = xcalloc(1, sizeof(*f));
|
||||
f->id = i;
|
||||
(void)strlcpy(f->path, path, sizeof(f->path));
|
||||
if (port != NULL)
|
||||
(void)strlcpy(f->port, port, sizeof(f->port));
|
||||
TAILQ_INSERT_TAIL(&conf.fcgi, f, fcgi);
|
||||
|
||||
return f->id;
|
||||
}
|
||||
|
||||
void
|
||||
|
|
13
server.c
13
server.c
|
@ -734,13 +734,22 @@ fcgi_open_conn(struct fcgi *f)
|
|||
static int
|
||||
apply_fastcgi(struct client *c)
|
||||
{
|
||||
int id;
|
||||
int id, i = 0;
|
||||
struct fcgi *f;
|
||||
|
||||
if ((id = vhost_fastcgi(c->host, c->iri.path)) == -1)
|
||||
return 0;
|
||||
|
||||
f = &fcgi[id];
|
||||
TAILQ_FOREACH(f, &conf.fcgi, fcgi) {
|
||||
if (i == id)
|
||||
break;
|
||||
++i;
|
||||
}
|
||||
|
||||
if (f == NULL) {
|
||||
log_warnx("can't find fcgi #%d", id);
|
||||
return 0;
|
||||
}
|
||||
|
||||
log_debug("opening fastcgi connection for (%s,%s)",
|
||||
f->path, f->port);
|
||||
|
|
Loading…
Reference in New Issue