summaryrefslogtreecommitdiff
path: root/usr.sbin/httpd
diff options
context:
space:
mode:
Diffstat (limited to 'usr.sbin/httpd')
-rw-r--r--usr.sbin/httpd/httpd.h6
-rw-r--r--usr.sbin/httpd/logger.c18
-rw-r--r--usr.sbin/httpd/server.c44
-rw-r--r--usr.sbin/httpd/server_http.c11
4 files changed, 36 insertions, 43 deletions
diff --git a/usr.sbin/httpd/httpd.h b/usr.sbin/httpd/httpd.h
index 95ff26a79f7..f6e25fc4987 100644
--- a/usr.sbin/httpd/httpd.h
+++ b/usr.sbin/httpd/httpd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: httpd.h,v 1.108 2016/08/22 15:02:18 jsing Exp $ */
+/* $OpenBSD: httpd.h,v 1.109 2016/08/26 10:46:39 rzalamena Exp $ */
/*
* Copyright (c) 2006 - 2015 Reyk Floeter <reyk@openbsd.org>
@@ -572,7 +572,7 @@ SPLAY_PROTOTYPE(client_tree, client, clt_nodes, server_client_cmp);
/* server_http.c */
void server_http_init(struct server *);
-void server_http(struct httpd *);
+void server_http(void);
int server_httpdesc_init(struct client *);
void server_read_http(struct bufferevent *, void *);
void server_abort_http(struct client *, unsigned int, const char *);
@@ -667,6 +667,8 @@ const char *print_time(struct timeval *, struct timeval *, char *, size_t);
const char *printb_flags(const uint32_t, const char *);
void getmonotime(struct timeval *);
+extern struct httpd *httpd_env;
+
/* log.c */
void log_init(int, int);
void log_procinit(const char *);
diff --git a/usr.sbin/httpd/logger.c b/usr.sbin/httpd/logger.c
index 01ba59fa663..ba2f8b81b2d 100644
--- a/usr.sbin/httpd/logger.c
+++ b/usr.sbin/httpd/logger.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: logger.c,v 1.16 2016/08/16 18:41:57 tedu Exp $ */
+/* $OpenBSD: logger.c,v 1.17 2016/08/26 10:46:39 rzalamena Exp $ */
/*
* Copyright (c) 2014 Reyk Floeter <reyk@openbsd.org>
@@ -43,7 +43,6 @@ void logger_init(struct privsep *, struct privsep_proc *p, void *);
int logger_start(void);
int logger_log(struct imsg *);
-static struct httpd *env = NULL;
int proc_id;
static uint32_t last_log_id = 0;
@@ -55,7 +54,6 @@ static struct privsep_proc procs[] = {
pid_t
logger(struct privsep *ps, struct privsep_proc *p)
{
- env = ps->ps_env;
return (proc_run(ps, p, procs, nitems(procs), logger_init, NULL));
}
@@ -63,7 +61,7 @@ void
logger_shutdown(void)
{
logger_close();
- config_purge(env, CONFIG_ALL);
+ config_purge(httpd_env, CONFIG_ALL);
}
void
@@ -120,7 +118,7 @@ logger_open_file(const char *name)
iov[1].iov_base = log->log_name;
iov[1].iov_len = strlen(log->log_name) + 1;
- if (proc_composev(env->sc_ps, PROC_PARENT, IMSG_LOG_OPEN,
+ if (proc_composev(httpd_env->sc_ps, PROC_PARENT, IMSG_LOG_OPEN,
iov, 2) != 0) {
log_warn("%s: failed to compose IMSG_LOG_OPEN imsg", __func__);
goto err;
@@ -173,7 +171,7 @@ logger_open_priv(struct imsg *imsg)
if ((size_t)snprintf(name, sizeof(name), "/%s", p) >= sizeof(name))
return (-1);
- if ((len = strlcpy(path, env->sc_logdir, sizeof(path)))
+ if ((len = strlcpy(path, httpd_env->sc_logdir, sizeof(path)))
>= sizeof(path))
return (-1);
@@ -190,7 +188,7 @@ logger_open_priv(struct imsg *imsg)
return (-1);
}
- proc_compose_imsg(env->sc_ps, PROC_LOGGER, -1, IMSG_LOG_OPEN, -1, fd,
+ proc_compose_imsg(httpd_env->sc_ps, PROC_LOGGER, -1, IMSG_LOG_OPEN, -1, fd,
&id, sizeof(id));
DPRINTF("%s: opened log file %s, fd %d", __func__, path, fd);
@@ -285,17 +283,17 @@ logger_dispatch_parent(int fd, struct privsep_proc *p, struct imsg *imsg)
{
switch (imsg->hdr.type) {
case IMSG_CFG_SERVER:
- config_getserver(env, imsg);
+ config_getserver(httpd_env, imsg);
break;
case IMSG_CFG_DONE:
- config_getcfg(env, imsg);
+ config_getcfg(httpd_env, imsg);
break;
case IMSG_CTL_START:
case IMSG_CTL_REOPEN:
logger_start();
break;
case IMSG_CTL_RESET:
- config_getreset(env, imsg);
+ config_getreset(httpd_env, imsg);
break;
case IMSG_LOG_OPEN:
return (logger_open_fd(imsg));
diff --git a/usr.sbin/httpd/server.c b/usr.sbin/httpd/server.c
index 543f53c26e4..b3099d936c5 100644
--- a/usr.sbin/httpd/server.c
+++ b/usr.sbin/httpd/server.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: server.c,v 1.92 2016/08/22 15:02:18 jsing Exp $ */
+/* $OpenBSD: server.c,v 1.93 2016/08/26 10:46:39 rzalamena Exp $ */
/*
* Copyright (c) 2006 - 2015 Reyk Floeter <reyk@openbsd.org>
@@ -75,7 +75,6 @@ volatile int server_clients;
volatile int server_inflight = 0;
uint32_t server_cltid;
-static struct httpd *env = NULL;
int proc_id;
static struct privsep_proc procs[] = {
@@ -87,16 +86,15 @@ pid_t
server(struct privsep *ps, struct privsep_proc *p)
{
pid_t pid;
- env = ps->ps_env;
pid = proc_run(ps, p, procs, nitems(procs), server_init, NULL);
- server_http(env);
+ server_http();
return (pid);
}
void
server_shutdown(void)
{
- config_purge(env, CONFIG_ALL);
+ config_purge(httpd_env, CONFIG_ALL);
usleep(200); /* XXX server needs to shutdown last */
}
@@ -114,7 +112,7 @@ server_privinit(struct server *srv)
* There's no need to open a new socket if a server with the
* same address already exists.
*/
- TAILQ_FOREACH(s, env->sc_servers, srv_entry) {
+ TAILQ_FOREACH(s, httpd_env->sc_servers, srv_entry) {
if (s != srv && s->srv_s != -1 &&
s->srv_conf.port == srv->srv_conf.port &&
sockaddr_cmp((struct sockaddr *)&s->srv_conf.ss,
@@ -271,7 +269,7 @@ server_tls_init(struct server *srv)
void
server_init(struct privsep *ps, struct privsep_proc *p, void *arg)
{
- server_http(ps->ps_env);
+ server_http();
if (config_init(ps->ps_env) == -1)
fatal("failed to initialize configuration");
@@ -290,9 +288,9 @@ server_init(struct privsep *ps, struct privsep_proc *p, void *arg)
#if 0
/* Schedule statistics timer */
- evtimer_set(&env->sc_statev, server_statistics, NULL);
- memcpy(&tv, &env->sc_statinterval, sizeof(tv));
- evtimer_add(&env->sc_statev, &tv);
+ evtimer_set(&ps->ps_env->sc_statev, server_statistics, NULL);
+ memcpy(&tv, &ps->ps_env->sc_statinterval, sizeof(tv));
+ evtimer_add(&ps->ps_env->sc_statev, &tv);
#endif
}
@@ -301,7 +299,7 @@ server_launch(void)
{
struct server *srv;
- TAILQ_FOREACH(srv, env->sc_servers, srv_entry) {
+ TAILQ_FOREACH(srv, httpd_env->sc_servers, srv_entry) {
log_debug("%s: configuring server %s", __func__,
srv->srv_conf.name);
@@ -332,7 +330,7 @@ server_purge(struct server *srv)
if (srv->srv_s != -1)
close(srv->srv_s);
- TAILQ_REMOVE(env->sc_servers, srv, srv_entry);
+ TAILQ_REMOVE(httpd_env->sc_servers, srv, srv_entry);
/* cleanup sessions */
while ((clt =
@@ -391,7 +389,7 @@ server_byaddr(struct sockaddr *addr, in_port_t port)
{
struct server *srv;
- TAILQ_FOREACH(srv, env->sc_servers, srv_entry) {
+ TAILQ_FOREACH(srv, httpd_env->sc_servers, srv_entry) {
if (port == srv->srv_conf.port &&
sockaddr_cmp((struct sockaddr *)&srv->srv_conf.ss,
addr, srv->srv_conf.prefixlen) == 0)
@@ -407,7 +405,7 @@ serverconfig_byid(uint32_t id)
struct server *srv;
struct server_config *srv_conf;
- TAILQ_FOREACH(srv, env->sc_servers, srv_entry) {
+ TAILQ_FOREACH(srv, httpd_env->sc_servers, srv_entry) {
if (srv->srv_conf.id == id)
return (&srv->srv_conf);
TAILQ_FOREACH(srv_conf, &srv->srv_hosts, entry) {
@@ -426,7 +424,7 @@ server_foreach(int (*srv_cb)(struct server *,
struct server *srv;
struct server_config *srv_conf;
- TAILQ_FOREACH(srv, env->sc_servers, srv_entry) {
+ TAILQ_FOREACH(srv, httpd_env->sc_servers, srv_entry) {
if ((srv_cb)(srv, &srv->srv_conf, arg) == -1)
return (-1);
TAILQ_FOREACH(srv_conf, &srv->srv_hosts, entry) {
@@ -444,7 +442,7 @@ server_match(struct server *s2, int match_name)
struct server *s1;
/* Attempt to find matching server. */
- TAILQ_FOREACH(s1, env->sc_servers, srv_entry) {
+ TAILQ_FOREACH(s1, httpd_env->sc_servers, srv_entry) {
if ((s1->srv_conf.flags & SRVFLAG_LOCATION) != 0)
continue;
if (match_name) {
@@ -1091,7 +1089,7 @@ server_sendlog(struct server_config *srv_conf, int cmd, const char *emsg, ...)
iov[1].iov_base = msg;
iov[1].iov_len = strlen(msg) + 1;
- if (proc_composev(env->sc_ps, PROC_LOGGER, cmd, iov, 2) != 0) {
+ if (proc_composev(httpd_env->sc_ps, PROC_LOGGER, cmd, iov, 2) != 0) {
log_warn("%s: failed to compose imsg", __func__);
return;
}
@@ -1193,25 +1191,25 @@ server_dispatch_parent(int fd, struct privsep_proc *p, struct imsg *imsg)
{
switch (imsg->hdr.type) {
case IMSG_CFG_MEDIA:
- config_getmedia(env, imsg);
+ config_getmedia(httpd_env, imsg);
break;
case IMSG_CFG_AUTH:
- config_getauth(env, imsg);
+ config_getauth(httpd_env, imsg);
break;
case IMSG_CFG_SERVER:
- config_getserver(env, imsg);
+ config_getserver(httpd_env, imsg);
break;
case IMSG_CFG_TLS:
- config_gettls(env, imsg);
+ config_gettls(httpd_env, imsg);
break;
case IMSG_CFG_DONE:
- config_getcfg(env, imsg);
+ config_getcfg(httpd_env, imsg);
break;
case IMSG_CTL_START:
server_launch();
break;
case IMSG_CTL_RESET:
- config_getreset(env, imsg);
+ config_getreset(httpd_env, imsg);
break;
default:
return (-1);
diff --git a/usr.sbin/httpd/server_http.c b/usr.sbin/httpd/server_http.c
index b69805a3d5d..968d51a72d0 100644
--- a/usr.sbin/httpd/server_http.c
+++ b/usr.sbin/httpd/server_http.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: server_http.c,v 1.109 2016/07/27 11:02:41 reyk Exp $ */
+/* $OpenBSD: server_http.c,v 1.110 2016/08/26 10:46:39 rzalamena Exp $ */
/*
* Copyright (c) 2006 - 2015 Reyk Floeter <reyk@openbsd.org>
@@ -49,17 +49,12 @@ int server_http_authenticate(struct server_config *,
char *server_expand_http(struct client *, const char *,
char *, size_t);
-static struct httpd *env = NULL;
-
static struct http_method http_methods[] = HTTP_METHODS;
static struct http_error http_errors[] = HTTP_ERRORS;
void
-server_http(struct httpd *x_env)
+server_http(void)
{
- if (x_env != NULL)
- env = x_env;
-
DPRINTF("%s: sorting lookup tables, pid %d", __func__, getpid());
/* Sort the HTTP lookup arrays */
@@ -435,7 +430,7 @@ server_read_http(struct bufferevent *bev, void *arg)
done:
if (clt->clt_toread != 0)
bufferevent_disable(bev, EV_READ);
- server_response(env, clt);
+ server_response(httpd_env, clt);
return;
}
if (clt->clt_done) {