commit - e45334e6ae0b658a2d3d4f47bc3e9ddfdb83a44f
commit + af1dab18702cf135aa80bf15065f73050c915347
blob - 5c38d746a682d6e1236ba2f29690b65d0e0e0016
blob + 185bc0aea4001aef1ef15e1443722b95c8d94cbe
--- config.c
+++ config.c
#include "log.h"
#include "proc.h"
-void
-config_init(void)
+struct conf *
+config_new(void)
{
- memset(&conf, 0, sizeof(conf));
+ struct conf *conf;
- TAILQ_INIT(&conf.fcgi);
- TAILQ_INIT(&conf.hosts);
+ conf = xcalloc(1, sizeof(*conf));
- conf.port = 1965;
- conf.ipv6 = 0;
- conf.protos = TLS_PROTOCOL_TLSv1_2 | TLS_PROTOCOL_TLSv1_3;
+ TAILQ_INIT(&conf->fcgi);
+ TAILQ_INIT(&conf->hosts);
- init_mime(&conf.mime);
+ conf->port = 1965;
+ conf->ipv6 = 0;
+ conf->protos = TLS_PROTOCOL_TLSv1_2 | TLS_PROTOCOL_TLSv1_3;
- conf.prefork = 3;
+ init_mime(&conf->mime);
- conf.sock4 = -1;
- conf.sock6 = -1;
+ conf->prefork = 3;
+
+ conf->sock4 = -1;
+ conf->sock6 = -1;
+
+ return conf;
}
void
-config_free(void)
+config_purge(struct conf *conf)
{
struct privsep *ps;
struct fcgi *f, *tf;
struct envlist *e, *te;
struct alist *a, *ta;
- ps = conf.ps;
+ ps = conf->ps;
- if (conf.sock4 != -1) {
- event_del(&conf.evsock4);
- close(conf.sock4);
+ if (conf->sock4 != -1) {
+ event_del(&conf->evsock4);
+ close(conf->sock4);
}
- if (conf.sock6 != -1) {
- event_del(&conf.evsock6);
- close(conf.sock6);
+ if (conf->sock6 != -1) {
+ event_del(&conf->evsock6);
+ close(conf->sock6);
}
- free_mime(&conf.mime);
- TAILQ_FOREACH_SAFE(f, &conf.fcgi, fcgi, tf) {
- TAILQ_REMOVE(&conf.fcgi, f, fcgi);
+ free_mime(&conf->mime);
+ TAILQ_FOREACH_SAFE(f, &conf->fcgi, fcgi, tf) {
+ TAILQ_REMOVE(&conf->fcgi, f, fcgi);
free(f);
}
- TAILQ_FOREACH_SAFE(h, &conf.hosts, vhosts, th) {
+ TAILQ_FOREACH_SAFE(h, &conf->hosts, vhosts, th) {
free(h->cert_path);
free(h->key_path);
free(h->ocsp_path);
free(p);
}
- TAILQ_REMOVE(&conf.hosts, h, vhosts);
+ TAILQ_REMOVE(&conf->hosts, h, vhosts);
free(h);
}
- memset(&conf, 0, sizeof(conf));
+ 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_INIT(&conf.hosts);
+ 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_INIT(&conf->hosts);
}
static int
switch (imsg->hdr.type) {
case IMSG_RECONF_START:
- config_free();
+ config_purge(conf);
h = NULL;
p = NULL;
break;
fatalx("missing socket for IMSG_RECONF_SOCK4");
conf->sock4 = imsg->fd;
event_set(&conf->evsock4, conf->sock4, EV_READ|EV_PERSIST,
- do_accept, NULL);
+ do_accept, conf);
break;
case IMSG_RECONF_SOCK6:
fatalx("missing socket for IMSG_RECONF_SOCK6");
conf->sock6 = imsg->fd;
event_set(&conf->evsock6, conf->sock6, EV_READ|EV_PERSIST,
- do_accept, NULL);
+ do_accept, conf);
break;
case IMSG_RECONF_FCGI:
blob - 47ed883805ee02ede1a49148a7c24de2765bc410
blob + 36b9dd9e410f68e5a4b59ffe052cf44e14b96857
--- ge.c
+++ ge.c
#include "log.h"
-struct conf conf;
int privsep_process;
static const struct option opts[] = {
}
static int
-serve(const char *host, int port, const char *dir)
+serve(struct conf *conf, const char *host, int port, const char *dir)
{
struct addrinfo hints, *res, *res0;
int r, error, saved_errno, sock = -1;
event_init();
/* cheating */
- conf.sock4 = sock;
- event_set(&conf.evsock4, conf.sock4, EV_READ|EV_PERSIST,
- do_accept, NULL);
+ conf->sock4 = sock;
+ event_set(&conf->evsock4, conf->sock4, EV_READ|EV_PERSIST,
+ do_accept, conf);
server_init(NULL, NULL, NULL);
- if (server_configure_done(&conf) == -1)
+ if (server_configure_done(conf) == -1)
fatalx("server configuration failed");
log_info("serving %s on port %d", dir, port);
int
main(int argc, char **argv)
{
+ struct conf *conf;
struct vhost *host;
struct location *loc;
const char *errstr, *certs_dir = NULL, *hostname = "localhost";
log_init(1, LOG_DAEMON);
log_setverbose(0);
- config_init();
+ conf = config_new();
while ((ch = getopt_long(argc, argv, "d:H:hp:Vv", opts, NULL)) != -1) {
switch (ch) {
usage();
break;
case 'p':
- conf.port = strtonum(optarg, 0, UINT16_MAX, &errstr);
+ conf->port = strtonum(optarg, 0, UINT16_MAX, &errstr);
if (errstr)
fatalx("port number is %s: %s", errstr,
optarg);
usage();
/* prepare the configuration */
- init_mime(&conf.mime);
+ init_mime(&conf->mime);
if (certs_dir == NULL)
certs_dir = data_dir();
/* set up the implicit vhost and location */
host = xcalloc(1, sizeof(*host));
- TAILQ_INSERT_HEAD(&conf.hosts, host, vhosts);
+ TAILQ_INSERT_HEAD(&conf->hosts, host, vhosts);
loc = xcalloc(1, sizeof(*loc));
loc->fcgi = -1;
/* start the server */
signal(SIGPIPE, SIG_IGN);
setproctitle("%s", loc->dir);
- return serve(hostname, conf.port, loc->dir);
+ return serve(conf, hostname, conf->port, loc->dir);
}
blob - 7a7a47d59153945a0f83db89e815b90bdcf2b801
blob + 1a796d2268061ad537a0bf8be69a618ce59687c8
--- gmid.c
+++ gmid.c
const char *config_path = "/etc/gmid.conf";
const char *pidfile;
-struct conf conf;
-
static void
usage(void)
{
void
log_request(struct client *c, char *meta, size_t l)
{
+ struct conf *conf = c->conf;
char hbuf[NI_MAXHOST], sbuf[NI_MAXSERV], b[GEMINI_URL_LEN];
char *fmted;
const char *t;
if (ec == -1)
err(1, "asprintf");
- proc_compose(conf.ps, PROC_LOGGER, IMSG_LOG_REQUEST,
+ proc_compose(conf->ps, PROC_LOGGER, IMSG_LOG_REQUEST,
fmted, ec + 1);
free(fmted);
int
main(int argc, char **argv)
{
+ struct conf *conf;
struct privsep *ps;
const char *errstr, *title = NULL;
size_t i;
/* log to stderr until daemonized */
log_init(1, LOG_DAEMON);
- config_init();
while ((ch = getopt_long(argc, argv, opts, longopts, NULL)) != -1) {
switch (ch) {
if (argc - optind != 0)
usage();
- parse_conf(config_path);
- if (*conf.chroot != '\0' && *conf.user == '\0')
+ conf = config_new();
+
+ parse_conf(conf, config_path);
+ if (*conf->chroot != '\0' && *conf->user == '\0')
fatalx("can't chroot without a user to switch to after.");
if (conftest) {
if ((ps = calloc(1, sizeof(*ps))) == NULL)
fatal("calloc");
- ps->ps_env = &conf;
- conf.ps = ps;
- if (*conf.user) {
+ ps->ps_env = conf;
+ conf->ps = ps;
+ if (*conf->user) {
if (geteuid())
fatalx("need root privileges");
- if ((ps->ps_pw = getpwnam(conf.user)) == NULL)
- fatalx("unknown user %s", conf.user);
+ if ((ps->ps_pw = getpwnam(conf->user)) == NULL)
+ fatalx("unknown user %s", conf->user);
}
- ps->ps_instances[PROC_SERVER] = conf.prefork;
+ ps->ps_instances[PROC_SERVER] = conf->prefork;
ps->ps_instance = proc_instance;
if (title != NULL)
ps->ps_title[proc_id] = title;
- if (*conf.chroot != '\0') {
+ if (*conf->chroot != '\0') {
for (i = 0; i < nitems(procs); ++i)
- procs[i].p_chroot = conf.chroot;
+ procs[i].p_chroot = conf->chroot;
}
log_init(debug, LOG_DAEMON);
proc_connect(ps);
- if (main_configure(&conf) == -1)
+ if (main_configure(conf) == -1)
fatal("configuration failed");
event_dispatch();
- main_shutdown(&conf);
+ main_shutdown(conf);
/* NOTREACHED */
return 0;
}
}
log_debug("%s: config file %s", __func__, config_path);
- config_free();
- parse_conf(config_path); /* XXX should handle error here */
+ config_purge(conf);
+ parse_conf(conf, config_path); /* XXX should handle error here */
main_configure(conf);
}
main_shutdown(struct conf *conf)
{
proc_kill(conf->ps);
- config_free();
+ config_purge(conf);
free(conf->ps);
/* free(conf); */
blob - 20e20561ad8897f10d46b36c5dc54841afa437e0
blob + 0e99e135a60502c3ccdf154fde2eb2c05e1d9e52
--- gmid.h
+++ gmid.h
};
extern const char *config_path;
-extern struct conf conf;
extern int servpipes[PROC_MAX_INSTANCES];
extern int privsep_process;
};
struct client {
+ struct conf *conf;
uint32_t id;
struct tls *ctx;
char *req;
void log_request(struct client *, char *, size_t);
/* config.c */
-void config_init(void);
-void config_free(void);
+struct conf *config_new(void);
+void config_purge(struct conf *);
int config_send(struct conf *);
int config_recv(struct conf *, struct imsg *);
/* parse.y */
void yyerror(const char*, ...);
-void parse_conf(const char*);
+void parse_conf(struct conf *, const char*);
void print_conf(void);
int cmdline_symset(char *);
int add_mime(struct mime*, const char*, const char*);
int load_default_mime(struct mime*);
void sort_mime(struct mime *);
-const char *mime(struct vhost*, const char*);
+const char *mime(struct conf *, struct vhost*, const char*);
void free_mime(struct mime *);
/* server.c */
blob - 9197c8b131e1e9c670c9d7bf13635eaa8b9b1919
blob + 6176c2a11cae4e0677a0fd92707df08778b42fd0
--- mime.c
+++ mime.c
}
const char *
-mime(struct vhost *host, const char *path)
+mime(struct conf *conf, struct vhost *host, const char *path)
{
const char *def, *ext;
struct etm *t;
if ((ext = path_ext(path)) == NULL)
return def;
- t = bsearch(ext, conf.mime.t, conf.mime.len, sizeof(*conf.mime.t),
+ t = bsearch(ext, conf->mime.t, conf->mime.len, sizeof(*conf->mime.t),
mime_find);
if (t != NULL)
return t->mime;
blob - d4ac93a011e898d39a759ea126c85333b8b9368d
blob + de0405b9c92b72911abcfbe7bf85806d153eb714
--- parse.y
+++ parse.y
#include "log.h"
+struct conf *conf;
+
TAILQ_HEAD(files, file) files = TAILQ_HEAD_INITIALIZER(files);
static struct file {
TAILQ_ENTRY(file) entry;
;
option : CHROOT string {
- if (strlcpy(conf.chroot, $2, sizeof(conf.chroot)) >=
- sizeof(conf.chroot))
+ if (strlcpy(conf->chroot, $2, sizeof(conf->chroot)) >=
+ sizeof(conf->chroot))
yyerror("chroot path too long");
free($2);
}
- | IPV6 bool { conf.ipv6 = $2; }
- | PORT NUM { conf.port = check_port_num($2); }
- | PREFORK NUM { conf.prefork = check_prefork_num($2); }
+ | IPV6 bool { conf->ipv6 = $2; }
+ | PORT NUM { conf->port = check_port_num($2); }
+ | PREFORK NUM { conf->prefork = check_prefork_num($2); }
| PROTOCOLS string {
- if (tls_config_parse_protocols(&conf.protos, $2) == -1)
+ if (tls_config_parse_protocols(&conf->protos, $2) == -1)
yyerror("invalid protocols string \"%s\"", $2);
free($2);
}
| USER string {
- if (strlcpy(conf.user, $2, sizeof(conf.user)) >=
- sizeof(conf.user))
+ if (strlcpy(conf->user, $2, sizeof(conf->user)) >=
+ sizeof(conf->user))
yyerror("user name too long");
free($2);
}
vhost : SERVER string {
host = new_vhost();
- TAILQ_INSERT_HEAD(&conf.hosts, host, vhosts);
+ TAILQ_INSERT_HEAD(&conf->hosts, host, vhosts);
loc = new_location();
TAILQ_INSERT_HEAD(&host->locations, loc, locations);
;
medianamesl : numberstring {
- if (add_mime(&conf.mime, current_media, $1) == -1)
+ if (add_mime(&conf->mime, current_media, $1) == -1)
err(1, "add_mime");
free($1);
}
}
void
-parse_conf(const char *filename)
+parse_conf(struct conf *c, const char *filename)
{
struct sym *sym, *next;
+
+ conf = c;
file = pushfile(filename, 0);
if (file == NULL)
/* struct envlist *e; */
/* struct alist *a; */
- if (*conf.chroot != '\0')
- printf("chroot \"%s\"\n", conf.chroot);
- printf("ipv6 %s\n", conf.ipv6 ? "on" : "off");
+ if (*conf->chroot != '\0')
+ 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);
+ printf("port %d\n", conf->port);
+ printf("prefork %d\n", conf->prefork);
/* XXX: protocols? */
- if (*conf.user != '\0')
- printf("user \"%s\"\n", conf.user);
+ if (*conf->user != '\0')
+ printf("user \"%s\"\n", conf->user);
- TAILQ_FOREACH(h, &conf.hosts, vhosts) {
+ TAILQ_FOREACH(h, &conf->hosts, vhosts) {
printf("\nserver \"%s\" {\n", h->domain);
printf(" cert \"%s\"\n", h->cert);
printf(" key \"%s\"\n", h->key);
struct fcgi *f;
int i = 0;
- TAILQ_FOREACH(f, &conf.fcgi, fcgi) {
+ TAILQ_FOREACH(f, &conf->fcgi, fcgi) {
if (!strcmp(f->path, path) &&
((port == NULL && *f->port == '\0') ||
!strcmp(f->port, port)))
(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);
+ TAILQ_INSERT_TAIL(&conf->fcgi, f, fcgi);
return f->id;
}
blob - f3dfbd2ea5fd93fedc7ea006d82cbcf592de9fcb
blob + df7253b8a7c6a656bc519e4118cb726ce0821cab
--- regress/puny-test.c
+++ regress/puny-test.c
#include "../gmid.h"
-/* to make the linker happy */
-struct conf conf;
-
const struct suite {
const char *src;
const char *res;
blob - dd7dcc875e069678853006010393e58f52d7e815
blob + 6ae720a4a1e6d36b707e495b7e0acc3f43cacabf
--- server.c
+++ server.c
switch (check_path(c, c->iri.path, &c->pfd)) {
case FILE_EXISTS:
c->type = REQUEST_FILE;
- start_reply(c, SUCCESS, mime(c->host, c->iri.path));
+ start_reply(c, SUCCESS, mime(c->conf, c->host, c->iri.path));
return;
case FILE_DIRECTORY:
handle_handshake(int fd, short ev, void *d)
{
struct client *c = d;
+ struct conf *conf = c->conf;
struct vhost *h;
struct alist *a;
const char *servname;
goto err;
}
- TAILQ_FOREACH(h, &conf.hosts, vhosts) {
+ TAILQ_FOREACH(h, &conf->hosts, vhosts) {
if (matches(h->domain, c->domain))
goto found;
TAILQ_FOREACH(a, &h->aliases, aliases) {
static void
fmt_sbuf(const char *fmt, struct client *c, const char *path)
{
+ struct conf *conf = c->conf;
size_t i;
char buf[32];
strlcat(c->sbuf, c->iri.query, sizeof(c->sbuf));
break;
case 'P':
- snprintf(buf, sizeof(buf), "%d", conf.port);
+ snprintf(buf, sizeof(buf), "%d", conf->port);
strlcat(c->sbuf, buf, sizeof(c->sbuf));
memset(buf, 0, sizeof(buf));
break;
if ((id = vhost_fastcgi(c->host, c->iri.path)) == -1)
return 0;
- TAILQ_FOREACH(f, &conf.fcgi, fcgi) {
+ TAILQ_FOREACH(f, &c->conf->fcgi, fcgi) {
if (i == id)
break;
++i;
switch (check_path(c, c->iri.path, &c->pfd)) {
case FILE_EXISTS:
c->type = REQUEST_FILE;
- start_reply(c, SUCCESS, mime(c->host, c->iri.path));
+ start_reply(c, SUCCESS, mime(c->conf, c->host, c->iri.path));
break;
case FILE_DIRECTORY:
void
do_accept(int sock, short et, void *d)
{
+ struct conf *conf = d;
struct client *c;
struct sockaddr_storage addr;
struct sockaddr *saddr;
mark_nonblock(fd);
c = xcalloc(1, sizeof(*c));
+ c->conf = conf;
c->id = ++server_client_id;
c->fd = fd;
c->pfd = -1;
}
static void
-setup_tls(void)
+setup_tls(struct conf *conf)
{
struct tls_config *tlsconf;
struct vhost *h;
tls_config_verify_client_optional(tlsconf);
tls_config_insecure_noverifycert(tlsconf);
- if (tls_config_set_protocols(tlsconf, conf.protos) == -1)
+ if (tls_config_set_protocols(tlsconf, conf->protos) == -1)
fatalx("tls_config_set_protocols: %s",
tls_config_error(tlsconf));
- h = TAILQ_FIRST(&conf.hosts);
+ h = TAILQ_FIRST(&conf->hosts);
/* we need to set something, then we can add how many key we want */
if (tls_config_set_keypair_mem(tlsconf, h->cert, h->certlen,
}
static void
-load_vhosts(void)
+load_vhosts(struct conf *conf)
{
struct vhost *h;
struct location *l;
- TAILQ_FOREACH(h, &conf.hosts, vhosts) {
+ TAILQ_FOREACH(h, &conf->hosts, vhosts) {
TAILQ_FOREACH(l, &h->locations, locations) {
if (*l->dir == '\0')
continue;
if (load_default_mime(&conf->mime) == -1)
fatal("can't load default mime");
sort_mime(&conf->mime);
- setup_tls();
- load_vhosts();
+ setup_tls(conf);
+ load_vhosts(conf);
if (conf->sock4 != -1)
event_add(&conf->evsock4, NULL);
if (conf->sock6 != -1)