aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ge.c16
-rw-r--r--gmid.c32
-rw-r--r--gmid.h3
-rw-r--r--server.c32
4 files changed, 40 insertions, 43 deletions
diff --git a/ge.c b/ge.c
index 1ed3f58..5681ee2 100644
--- a/ge.c
+++ b/ge.c
@@ -41,6 +41,12 @@ static const struct option opts[] = {
};
void
+drop_priv(void)
+{
+ return;
+}
+
+void
load_local_cert(struct vhost *h, const char *hostname, const char *dir)
{
char *cert, *key;
@@ -176,8 +182,7 @@ serve(const char *host, int port, const char *dir, struct tls *ctx)
freeaddrinfo(res0);
log_notice(NULL, "serving %s on port %d", dir, port);
- loop(ctx, sock, -1, NULL);
- return 0;
+ return server_main(ctx, NULL, sock, -1);
}
static __dead void
@@ -241,10 +246,6 @@ main(int argc, char **argv)
if (certs_dir == NULL)
certs_dir = data_dir();
- if (load_default_mime(&conf.mime) == -1)
- fatal("can't load default mime types");
- sort_mime(&conf.mime);
-
/* set up the implicit vhost and location */
host = xcalloc(1, sizeof(*host));
@@ -272,9 +273,6 @@ main(int argc, char **argv)
free(tmp);
}
- if ((loc->dirfd = open(loc->dir, O_RDONLY|O_DIRECTORY)) == -1)
- fatal("can't open %s", loc->dir);
-
/* setup tls */
if ((tlsconf = tls_config_new()) == NULL)
diff --git a/gmid.c b/gmid.c
index 936f80c..a79ad60 100644
--- a/gmid.c
+++ b/gmid.c
@@ -58,24 +58,6 @@ dummy_handler(int signo)
return;
}
-void
-load_vhosts(void)
-{
- struct vhost *h;
- struct location *l;
-
- TAILQ_FOREACH(h, &hosts, vhosts) {
- TAILQ_FOREACH(l, &h->locations, locations) {
- if (*l->dir == '\0')
- continue;
- l->dirfd = open(l->dir, O_RDONLY | O_DIRECTORY);
- if (l->dirfd == -1)
- fatal("open %s for domain %s: %s", l->dir,
- h->domain, strerror(errno));
- }
- }
-}
-
int
make_socket(int port, int family)
{
@@ -184,18 +166,6 @@ setup_tls(void)
fatal("tls_configure: %s", tls_error(ctx));
}
-static int
-listener_main(struct imsgbuf *ibuf)
-{
- drop_priv();
- if (load_default_mime(&conf.mime) == -1)
- fatal("load_default_mime: %s", strerror(errno));
- sort_mime(&conf.mime);
- load_vhosts();
- loop(ctx, sock4, sock6, ibuf);
- return 0;
-}
-
void
init_config(void)
{
@@ -364,7 +334,7 @@ serve(void)
close(p[0]);
imsg_init(&servibuf[i], p[1]);
setproctitle("server");
- _exit(listener_main(&servibuf[i]));
+ _exit(server_main(ctx, &servibuf[i], sock4, sock6));
default:
close(p[1]);
imsg_init(&servibuf[i], p[0]);
diff --git a/gmid.h b/gmid.h
index 0bf0e63..a0a44a3 100644
--- a/gmid.h
+++ b/gmid.h
@@ -296,7 +296,6 @@ enum imsg_type {
/* gmid.c */
char *data_dir(void);
void load_local_cert(struct vhost*, const char*, const char*);
-void load_vhosts(void);
int make_socket(int, int);
void setup_tls(void);
void init_config(void);
@@ -348,7 +347,7 @@ void client_write(struct bufferevent *, void *);
void start_reply(struct client*, int, const char*);
void client_close(struct client *);
struct client *client_by_id(int);
-void loop(struct tls*, int, int, struct imsgbuf*);
+int server_main(struct tls *, struct imsgbuf *, int, int);
int client_tree_cmp(struct client *, struct client *);
SPLAY_PROTOTYPE(client_tree_id, client, entry, client_tree_cmp);
diff --git a/server.c b/server.c
index 8027b5f..083b5c2 100644
--- a/server.c
+++ b/server.c
@@ -1367,7 +1367,7 @@ handle_siginfo(int fd, short ev, void *d)
log_info(NULL, "%d connected clients", connected_clients);
}
-void
+static void
loop(struct tls *ctx_, int sock4, int sock6, struct imsgbuf *ibuf)
{
ctx = ctx_;
@@ -1404,6 +1404,36 @@ loop(struct tls *ctx_, int sock4, int sock6, struct imsgbuf *ibuf)
_exit(0);
}
+static void
+load_vhosts(void)
+{
+ struct vhost *h;
+ struct location *l;
+
+ TAILQ_FOREACH(h, &hosts, vhosts) {
+ TAILQ_FOREACH(l, &h->locations, locations) {
+ if (*l->dir == '\0')
+ continue;
+ l->dirfd = open(l->dir, O_RDONLY | O_DIRECTORY);
+ if (l->dirfd == -1)
+ fatal("open %s for domain %s: %s", l->dir,
+ h->domain, strerror(errno));
+ }
+ }
+}
+
+int
+server_main(struct tls *ctx_, struct imsgbuf *ibuf, int sock4, int sock6)
+{
+ drop_priv();
+ if (load_default_mime(&conf.mime) == -1)
+ fatal("can't load default mime: %s", strerror(errno));
+ sort_mime(&conf.mime);
+ load_vhosts();
+ loop(ctx_, sock4, sock6, ibuf);
+ return 0;
+}
+
int
client_tree_cmp(struct client *a, struct client *b)
{