[multiple] prefer (connection *) to (srv *)

convert all log_error_write() to log_error() and pass (log_error_st *)

use con->errh in preference to srv->errh (even though currently same)

avoid passing (server *) when previously used only for logging (errh)
personal/stbuehler/ci-build
Glenn Strauss 2019-11-25 01:54:08 -05:00
parent 644725127f
commit 010c28949c
81 changed files with 2121 additions and 2241 deletions

View File

@ -8,9 +8,6 @@
#include <stdlib.h>
#include <limits.h>
#include <errno.h>
#include <assert.h>
__attribute_cold__
static void array_extend(array * const a, uint32_t n) {
a->size += n;

View File

@ -86,6 +86,7 @@ typedef struct {
const buffer *error_handler;
const buffer *error_handler_404;
const buffer *errorfile_prefix;
log_error_st *errh;
unsigned short max_keep_alive_requests;
unsigned short max_keep_alive_idle;
@ -211,7 +212,6 @@ struct connection {
int mode; /* DIRECT (0) or plugin id */
int async_callback;
log_error_st *errh;
server *srv;
void **plugin_ctx; /* plugin connection specific config */
@ -230,8 +230,8 @@ struct connection {
http_method_t error_handler_saved_method;
struct server_socket *srv_socket; /* reference to the server-socket */
int (* network_write)(struct server *srv, struct connection *con, chunkqueue *cq, off_t max_bytes);
int (* network_read)(struct server *srv, struct connection *con, chunkqueue *cq, off_t max_bytes);
int (* network_write)(struct connection *con, chunkqueue *cq, off_t max_bytes);
int (* network_read)(struct connection *con, chunkqueue *cq, off_t max_bytes);
};
typedef struct {
@ -322,7 +322,7 @@ struct server {
struct stat_cache *stat_cache;
struct fdevents *ev;
int (* network_backend_write)(struct server *srv, int fd, chunkqueue *cq, off_t max_bytes);
int (* network_backend_write)(int fd, chunkqueue *cq, off_t max_bytes, log_error_st *errh);
handler_t (* request_env)(struct server *srv, connection *con);
/* buffers */

View File

@ -503,7 +503,7 @@ void chunkqueue_steal(chunkqueue *dest, chunkqueue *src, off_t len) {
}
}
static chunk *chunkqueue_get_append_tempfile(server *srv, chunkqueue *cq) {
static chunk *chunkqueue_get_append_tempfile(chunkqueue *cq, log_error_st *errh) {
chunk *c;
buffer *template = buffer_init_string("/var/tmp/lighttpd-upload-XXXXXX");
int fd = -1;
@ -525,9 +525,8 @@ static chunk *chunkqueue_get_append_tempfile(server *srv, chunkqueue *cq) {
if (fd < 0) {
/* (report only the last error to mkstemp()
* if multiple temp dirs attempted) */
log_error_write(srv, __FILE__, __LINE__, "sbs",
"opening temp-file failed:",
template, strerror(errno));
log_perror(errh, __FILE__, __LINE__,
"opening temp-file failed: %s", template->ptr);
buffer_free(template);
return NULL;
}
@ -541,7 +540,7 @@ static chunk *chunkqueue_get_append_tempfile(server *srv, chunkqueue *cq) {
return c;
}
int chunkqueue_append_mem_to_tempfile(server *srv, chunkqueue *dest, const char *mem, size_t len) {
int chunkqueue_append_mem_to_tempfile(chunkqueue *dest, const char *mem, size_t len, log_error_st *errh) {
chunk *dst_c;
ssize_t written;
@ -569,9 +568,8 @@ int chunkqueue_append_mem_to_tempfile(server *srv, chunkqueue *dest, const char
int rc = close(dst_c->file.fd);
dst_c->file.fd = -1;
if (0 != rc) {
log_error_write(srv, __FILE__, __LINE__, "sbss",
"close() temp-file", dst_c->mem, "failed:",
strerror(errno));
log_perror(errh, __FILE__, __LINE__,
"close() temp-file %s failed", dst_c->mem->ptr);
return -1;
}
dst_c = NULL;
@ -580,7 +578,7 @@ int chunkqueue_append_mem_to_tempfile(server *srv, chunkqueue *dest, const char
dst_c = NULL;
}
if (NULL == dst_c && NULL == (dst_c = chunkqueue_get_append_tempfile(srv, dest))) {
if (NULL == dst_c && NULL == (dst_c = chunkqueue_get_append_tempfile(dest, errh))) {
return -1;
}
#ifdef __COVERITY__
@ -609,9 +607,8 @@ int chunkqueue_append_mem_to_tempfile(server *srv, chunkqueue *dest, const char
} else {
int retry = (errno == ENOSPC && dest->tempdirs && ++dest->tempdir_idx < dest->tempdirs->used);
if (!retry) {
log_error_write(srv, __FILE__, __LINE__, "sbs",
"write() temp-file", dst_c->mem, "failed:",
strerror(errno));
log_perror(errh, __FILE__, __LINE__,
"write() temp-file %s failed", dst_c->mem->ptr);
}
if (0 == chunk_remaining_length(dst_c)) {
@ -621,9 +618,8 @@ int chunkqueue_append_mem_to_tempfile(server *srv, chunkqueue *dest, const char
int rc = close(dst_c->file.fd);
dst_c->file.fd = -1;
if (0 != rc) {
log_error_write(srv, __FILE__, __LINE__, "sbss",
"close() temp-file", dst_c->mem, "failed:",
strerror(errno));
log_perror(errh, __FILE__, __LINE__,
"close() temp-file %s failed", dst_c->mem->ptr);
return -1;
}
}
@ -637,7 +633,7 @@ int chunkqueue_append_mem_to_tempfile(server *srv, chunkqueue *dest, const char
return -1;
}
int chunkqueue_steal_with_tempfiles(server *srv, chunkqueue *dest, chunkqueue *src, off_t len) {
int chunkqueue_steal_with_tempfiles(chunkqueue *dest, chunkqueue *src, off_t len, log_error_st *errh) {
while (len > 0) {
chunk *c = src->first;
off_t clen = 0, use;
@ -676,7 +672,7 @@ int chunkqueue_steal_with_tempfiles(server *srv, chunkqueue *dest, chunkqueue *s
case MEM_CHUNK:
/* store "use" bytes from memory chunk in tempfile */
if (0 != chunkqueue_append_mem_to_tempfile(srv, dest, c->mem->ptr + c->offset, use)) {
if (0 != chunkqueue_append_mem_to_tempfile(dest, c->mem->ptr + c->offset, use, errh)) {
return -1;
}
@ -783,7 +779,7 @@ void chunkqueue_compact_mem(chunkqueue *cq, size_t clen) {
* no data added/removed from chunkqueue; consolidated only */
}
int chunkqueue_open_file_chunk(server *srv, chunkqueue *cq) {
int chunkqueue_open_file_chunk(chunkqueue *cq, log_error_st *errh) {
chunk* const c = cq->first;
off_t offset, toSend;
struct stat st;
@ -798,7 +794,7 @@ int chunkqueue_open_file_chunk(server *srv, chunkqueue *cq) {
if (-1 == c->file.fd) {
/* (permit symlinks; should already have been checked. However, TOC-TOU remains) */
if (-1 == (c->file.fd = fdevent_open_cloexec(c->mem->ptr, 1, O_RDONLY, 0))) {
log_error_write(srv, __FILE__, __LINE__, "ssb", "open failed:", strerror(errno), c->mem);
log_perror(errh, __FILE__, __LINE__, "open failed: %s",c->mem->ptr);
return -1;
}
}
@ -807,12 +803,12 @@ int chunkqueue_open_file_chunk(server *srv, chunkqueue *cq) {
if (c->file.is_temp) return 0;
if (-1 == fstat(c->file.fd, &st)) {
log_error_write(srv, __FILE__, __LINE__, "ss", "fstat failed:", strerror(errno));
log_perror(errh, __FILE__, __LINE__, "fstat failed");
return -1;
}
if (offset > st.st_size || toSend > st.st_size || offset > st.st_size - toSend) {
log_error_write(srv, __FILE__, __LINE__, "sb", "file shrunk:", c->mem);
log_error(errh, __FILE__, __LINE__, "file shrunk: %s", c->mem->ptr);
return -1;
}

View File

@ -9,6 +9,8 @@
#include "buffer.h"
#include "array.h"
struct log_error_st; /*(declaration)*/
typedef struct chunk {
struct chunk *next;
enum { MEM_CHUNK, FILE_CHUNK } type;
@ -85,8 +87,7 @@ buffer * chunkqueue_append_buffer_open(chunkqueue *cq);
void chunkqueue_append_buffer_commit(chunkqueue *cq);
struct server; /*(declaration)*/
int chunkqueue_append_mem_to_tempfile(struct server *srv, chunkqueue *cq, const char *mem, size_t len);
int chunkqueue_append_mem_to_tempfile(chunkqueue *cq, const char *mem, size_t len, struct log_error_st *errh);
/* functions to handle buffers to read into: */
/* obtain/reserve memory in chunkqueue at least len (input) size,
@ -109,10 +110,9 @@ void chunkqueue_mark_written(chunkqueue *cq, off_t len);
void chunkqueue_remove_finished_chunks(chunkqueue *cq);
void chunkqueue_steal(chunkqueue *dest, chunkqueue *src, off_t len);
struct server;
int chunkqueue_steal_with_tempfiles(struct server *srv, chunkqueue *dest, chunkqueue *src, off_t len);
int chunkqueue_steal_with_tempfiles(chunkqueue *dest, chunkqueue *src, off_t len, struct log_error_st *errh);
int chunkqueue_open_file_chunk(struct server *srv, chunkqueue *cq);
int chunkqueue_open_file_chunk(chunkqueue *cq, struct log_error_st *errh);
void chunkqueue_compact_mem(chunkqueue *cq, size_t clen);

View File

@ -270,7 +270,7 @@ static void config_cond_result_trace(connection *con, const data_config *dc, int
case COND_RESULT_TRUE: msg = "true"; break;
default: msg = "invalid cond_result_t"; break;
}
log_error(con->errh, __FILE__, __LINE__, "%d (%s) result: %s",
log_error(con->conf.errh, __FILE__, __LINE__, "%d (%s) result: %s",
dc->context_ndx, "uncached"+(cached ? 2 : 0), msg);
}
@ -305,16 +305,16 @@ static int config_addrstr_eq_remote_ip_mask(connection *con, const char *addrstr
sock_addr addr;
if (1 == sock_addr_inet_pton(&addr, addrstr, AF_INET, 0)) {
if (nm_bits > 32) {
log_error(con->errh, __FILE__, __LINE__, "ERROR: ipv4 netmask too large: %d", nm_bits);
log_error(con->conf.errh, __FILE__, __LINE__, "ERROR: ipv4 netmask too large: %d", nm_bits);
return -1;
}
} else if (1 == sock_addr_inet_pton(&addr, addrstr, AF_INET6, 0)) {
if (nm_bits > 128) {
log_error(con->errh, __FILE__, __LINE__, "ERROR: ipv6 netmask too large: %d", nm_bits);
log_error(con->conf.errh, __FILE__, __LINE__, "ERROR: ipv6 netmask too large: %d", nm_bits);
return -1;
}
} else {
log_error(con->errh, __FILE__, __LINE__, "ERROR: ip addr is invalid: %s", addrstr);
log_error(con->conf.errh, __FILE__, __LINE__, "ERROR: ip addr is invalid: %s", addrstr);
return -1;
}
return sock_addr_is_addr_eq_bits(&addr, rmt, nm_bits);
@ -327,21 +327,21 @@ static int config_addrbuf_eq_remote_ip_mask(connection *con, const buffer *strin
char addrstr[64]; /*(larger than INET_ADDRSTRLEN and INET6_ADDRSTRLEN)*/
if (*err) {
log_error(con->errh, __FILE__, __LINE__, "ERROR: non-digit found in netmask: %s %s", string->ptr, err);
log_error(con->conf.errh, __FILE__, __LINE__, "ERROR: non-digit found in netmask: %s %s", string->ptr, err);
return -1;
}
if (nm_bits <= 0) {
if (*(nm_slash+1) == '\0') {
log_error(con->errh, __FILE__, __LINE__, "ERROR: no number after / %s", string->ptr);
log_error(con->conf.errh, __FILE__, __LINE__, "ERROR: no number after / %s", string->ptr);
} else {
log_error(con->errh, __FILE__, __LINE__, "ERROR: invalid netmask <= 0: %s %s", string->ptr, err);
log_error(con->conf.errh, __FILE__, __LINE__, "ERROR: invalid netmask <= 0: %s %s", string->ptr, err);
}
return -1;
}
if (addrstrlen >= sizeof(addrstr)) {
log_error(con->errh, __FILE__, __LINE__, "ERROR: address string too long: %s", string->ptr);
log_error(con->conf.errh, __FILE__, __LINE__, "ERROR: address string too long: %s", string->ptr);
return -1;
}
@ -368,7 +368,7 @@ static cond_result_t config_check_cond_nocache(connection *con, const data_confi
* if the parent is not decided yet or false, we can't be true either
*/
if (debug_cond) {
log_error(con->errh, __FILE__, __LINE__, "go parent %s", dc->parent->key.ptr);
log_error(con->conf.errh, __FILE__, __LINE__, "go parent %s", dc->parent->key.ptr);
}
switch (config_check_cond_cached(con, dc->parent, debug_cond)) {
@ -391,7 +391,7 @@ static cond_result_t config_check_cond_nocache(connection *con, const data_confi
* was evaluated as "false" (not unset/skipped/true)
*/
if (debug_cond) {
log_error(con->errh, __FILE__, __LINE__, "go prev %s", dc->prev->key.ptr);
log_error(con->conf.errh, __FILE__, __LINE__, "go prev %s", dc->prev->key.ptr);
}
/* make sure prev is checked first */
@ -411,7 +411,7 @@ static cond_result_t config_check_cond_nocache(connection *con, const data_confi
if (!(con->conditional_is_valid & (1 << dc->comp))) {
if (debug_cond) {
log_error(con->errh, __FILE__, __LINE__, "%d %s not available yet",
log_error(con->conf.errh, __FILE__, __LINE__, "%d %s not available yet",
dc->comp,
dc->key.ptr);
}
@ -505,6 +505,7 @@ static cond_result_t config_check_cond_nocache(connection *con, const data_confi
case COMP_HTTP_QUERY_STRING:
l = con->uri.query;
if (NULL == l->ptr) l = (buffer *)&empty_string;
break;
case COMP_SERVER_SOCKET:
@ -525,12 +526,12 @@ static cond_result_t config_check_cond_nocache(connection *con, const data_confi
}
if (NULL == l) { /*(should not happen)*/
log_error(con->errh, __FILE__, __LINE__,
log_error(con->conf.errh, __FILE__, __LINE__,
"%s () compare to NULL", dc->comp_key->ptr);
return COND_RESULT_FALSE;
}
else if (debug_cond) {
log_error(con->errh, __FILE__, __LINE__,
log_error(con->conf.errh, __FILE__, __LINE__,
"%s (%s) compare to %s", dc->comp_key->ptr, l->ptr, dc->string.ptr);
}
@ -566,7 +567,7 @@ static cond_result_t config_check_cond_calc(connection *con, const int context_n
con->srv->config_context->data[context_ndx];
const int debug_cond = con->conf.log_condition_handling;
if (debug_cond) {
log_error(con->errh, __FILE__, __LINE__,
log_error(con->conf.errh, __FILE__, __LINE__,
"=== start of condition block ===");
}
return config_check_cond_nocache_calc(con, dc, debug_cond, cache);
@ -604,10 +605,11 @@ static void config_cond_clear_node(cond_cache_t * const cond_cache, const data_c
*
* if the item is COND_LAST_ELEMENT we reset all items
*/
void config_cond_cache_reset_item(server *srv, connection *con, comp_key_t item) {
void config_cond_cache_reset_item(connection *con, comp_key_t item) {
cond_cache_t * const cond_cache = con->cond_cache;
for (uint32_t i = 0; i < srv->config_context->used; ++i) {
const data_config *dc = (data_config *)srv->config_context->data[i];
const array * const config_context = con->srv->config_context;
for (uint32_t i = 0; i < config_context->used; ++i) {
const data_config *dc = (data_config *)config_context->data[i];
if (item == dc->comp) {
/* clear local_result */
@ -621,11 +623,11 @@ void config_cond_cache_reset_item(server *srv, connection *con, comp_key_t item)
/**
* reset the config cache to its initial state at connection start
*/
void config_cond_cache_reset(server *srv, connection *con) {
void config_cond_cache_reset(connection *con) {
con->conditional_is_valid = 0;
/* resetting all entries; no need to follow children as in config_cond_cache_reset_item */
/* static_assert(0 == COND_RESULT_UNSET); */
const uint32_t used = srv->config_context->used;
const uint32_t used = con->srv->config_context->used;
if (used > 1)
memset(con->cond_cache, 0, used*sizeof(cond_cache_t));
}

View File

@ -231,7 +231,7 @@ static int config_burl_normalize_cond (server *srv) {
#if defined(HAVE_MYSQL) || (defined(HAVE_LDAP_H) && defined(HAVE_LBER_H) && defined(HAVE_LIBLDAP) && defined(HAVE_LIBLBER))
static void config_warn_authn_module (server *srv, const char *module, size_t len) {
for (size_t i = 0; i < srv->config_context->used; ++i) {
for (uint32_t i = 0; i < srv->config_context->used; ++i) {
const data_config *config = (data_config const*)srv->config_context->data[i];
const data_unset *du = array_get_element_klen(config->value, CONST_STR_LEN("auth.backend"));
if (NULL != du && du->type == TYPE_STRING) {
@ -240,7 +240,12 @@ static void config_warn_authn_module (server *srv, const char *module, size_t le
buffer_copy_string_len(srv->tmp_buf, CONST_STR_LEN("mod_authn_"));
buffer_append_string_len(srv->tmp_buf, module, len);
array_insert_value(srv->srvconf.modules, CONST_BUF_LEN(srv->tmp_buf));
log_error_write(srv, __FILE__, __LINE__, "SSSsSSS", "Warning: please add \"mod_authn_", module, "\" to server.modules list in lighttpd.conf. A future release of lighttpd 1.4.x will not automatically load mod_authn_", module, "and lighttpd will fail to start up since your lighttpd.conf uses auth.backend = \"", module, "\".");
log_error(srv->errh, __FILE__, __LINE__,
"Warning: please add \"mod_authn_%s\" to server.modules list "
"in lighttpd.conf. A future release of lighttpd 1.4.x will "
"not automatically load mod_authn_%s and lighttpd will fail "
"to start up since your lighttpd.conf uses "
"auth.backend = \"%s\".", module, module, module);
return;
}
}
@ -250,14 +255,19 @@ static void config_warn_authn_module (server *srv, const char *module, size_t le
#ifdef USE_OPENSSL_CRYPTO
static void config_warn_openssl_module (server *srv) {
for (size_t i = 0; i < srv->config_context->used; ++i) {
for (uint32_t i = 0; i < srv->config_context->used; ++i) {
const data_config *config = (data_config const*)srv->config_context->data[i];
for (size_t j = 0; j < config->value->used; ++j) {
for (uint32_t j = 0; j < config->value->used; ++j) {
data_unset *du = config->value->data[j];
if (0 == strncmp(du->key.ptr, "ssl.", sizeof("ssl.")-1)) {
/* mod_openssl should be loaded after mod_extforward */
array_insert_value(srv->srvconf.modules, CONST_STR_LEN("mod_openssl"));
log_error_write(srv, __FILE__, __LINE__, "S", "Warning: please add \"mod_openssl\" to server.modules list in lighttpd.conf. A future release of lighttpd 1.4.x *will not* automatically load mod_openssl and lighttpd *will not* use SSL/TLS where your lighttpd.conf contains ssl.* directives");
log_error(srv->errh, __FILE__, __LINE__,
"Warning: please add \"mod_openssl\" to server.modules list "
"in lighttpd.conf. A future release of lighttpd 1.4.x "
"*will not* automatically load mod_openssl and lighttpd "
"*will not* use SSL/TLS where your lighttpd.conf contains "
"ssl.* directives");
return;
}
}
@ -942,6 +952,7 @@ static int config_insert(server *srv) {
}
}
p->defaults.errh = srv->errh;
p->defaults.max_keep_alive_requests = 100;
p->defaults.max_keep_alive_idle = 5;
p->defaults.max_read_idle = 60;
@ -1461,7 +1472,7 @@ static int config_tokenizer(server *srv, tokenizer_t *t, int *token_id, buffer *
*token_id = tid;
return 1;
} else if (t->offset < t->size) {
log_error_write(srv, __FILE__, __LINE__, "Dsb", tid, ",", token);
log_error(srv->errh, __FILE__, __LINE__, "%d, %s", tid, token->ptr);
}
return 0;
}
@ -1524,8 +1535,8 @@ static int config_parse_file_stream(server *srv, config_t *context, const char *
stream s;
if (0 != stream_open(&s, fn)) {
log_error(srv->errh, __FILE__, __LINE__,
"opening configfile %s failed: %s", fn, strerror(errno));
log_perror(srv->errh, __FILE__, __LINE__,
"opening configfile %s failed", fn);
return -1;
}
@ -1566,12 +1577,12 @@ int config_parse_file(server *srv, config_t *context, const char *fn) {
ret = 0; /* not an error if no files match glob pattern */
}
else {
log_error_write(srv, __FILE__, __LINE__, "sb", "include file not found: ", filename);
log_error(srv->errh, __FILE__, __LINE__, "include file not found: %s", filename->ptr);
}
break;
case GLOB_ABORTED:
case GLOB_NOSPACE:
log_error_write(srv, __FILE__, __LINE__, "sbss", "glob()", filename, "failed:", strerror(errno));
log_perror(srv->errh, __FILE__, __LINE__, "glob() %s failed", filename->ptr);
break;
}
@ -1601,22 +1612,20 @@ int config_parse_cmd(server *srv, config_t *context, const char *cmd) {
char oldpwd[PATH_MAX];
if (NULL == getcwd(oldpwd, sizeof(oldpwd))) {
log_error_write(srv, __FILE__, __LINE__, "s",
"cannot get cwd", strerror(errno));
log_perror(srv->errh, __FILE__, __LINE__, "getcwd()");
return -1;
}
if (!buffer_string_is_empty(context->basedir)) {
if (0 != chdir(context->basedir->ptr)) {
log_error_write(srv, __FILE__, __LINE__, "sbs",
"cannot change directory to", context->basedir, strerror(errno));
log_perror(srv->errh, __FILE__, __LINE__,
"cannot change directory to %s", context->basedir->ptr);
return -1;
}
}
if (pipe(fds)) {
log_error_write(srv, __FILE__, __LINE__, "ss",
"pipe failed: ", strerror(errno));
log_perror(srv->errh, __FILE__, __LINE__, "pipe()");
ret = -1;
}
else {
@ -1631,8 +1640,7 @@ int config_parse_cmd(server *srv, config_t *context, const char *cmd) {
fdevent_setfd_cloexec(fds[0]);
pid = fdevent_fork_execve(args[0], args, NULL, -1, fds[1], -1, -1);
if (-1 == pid) {
log_error_write(srv, __FILE__, __LINE__, "SSss",
"fork/exec(", cmd, "):", strerror(errno));
log_perror(srv->errh, __FILE__, __LINE__, "fork/exec(%s)", cmd);
ret = -1;
}
else {
@ -1647,21 +1655,20 @@ int config_parse_cmd(server *srv, config_t *context, const char *cmd) {
if (rd >= 0) buffer_commit(out, (size_t)rd);
} while (rd > 0 || (-1 == rd && errno == EINTR));
if (0 != rd) {
log_error_write(srv, __FILE__, __LINE__, "SSss",
"read \"", cmd, "\" failed:", strerror(errno));
log_perror(srv->errh, __FILE__, __LINE__, "read \"%s\"", cmd);
ret = -1;
}
close(fds[0]);
fds[0] = -1;
while (-1 == (wpid = waitpid(pid, &wstatus, 0)) && errno == EINTR) ;
if (wpid != pid) {
log_error_write(srv, __FILE__, __LINE__, "SSss",
"waitpid \"", cmd, "\" failed:", strerror(errno));
log_perror(srv->errh, __FILE__, __LINE__, "waitpid \"%s\"",cmd);
ret = -1;
}
if (0 != wstatus) {
log_error_write(srv, __FILE__, __LINE__, "SSsd",
"command \"", cmd, "\" exited non-zero:", WEXITSTATUS(wstatus));
log_error(srv->errh, __FILE__, __LINE__,
"command \"%s\" exited non-zero: %d",
cmd, WEXITSTATUS(wstatus));
ret = -1;
}
@ -1675,8 +1682,8 @@ int config_parse_cmd(server *srv, config_t *context, const char *cmd) {
}
if (0 != chdir(oldpwd)) {
log_error_write(srv, __FILE__, __LINE__, "sss",
"cannot change directory to", oldpwd, strerror(errno));
log_perror(srv->errh, __FILE__, __LINE__,
"cannot change directory to %s", oldpwd);
ret = -1;
}
return ret;
@ -1761,13 +1768,15 @@ int config_set_defaults(server *srv) {
if (!buffer_string_is_empty(srv->srvconf.changeroot)) {
if (-1 == stat(srv->srvconf.changeroot->ptr, &st1)) {
log_error_write(srv, __FILE__, __LINE__, "sb",
"server.chroot doesn't exist:", srv->srvconf.changeroot);
log_error(srv->errh, __FILE__, __LINE__,
"server.chroot doesn't exist: %s",
srv->srvconf.changeroot->ptr);
return -1;
}
if (!S_ISDIR(st1.st_mode)) {
log_error_write(srv, __FILE__, __LINE__, "sb",
"server.chroot isn't a directory:", srv->srvconf.changeroot);
log_error(srv->errh, __FILE__, __LINE__,
"server.chroot isn't a directory: %s",
srv->srvconf.changeroot->ptr);
return -1;
}
}
@ -1793,11 +1802,11 @@ int config_set_defaults(server *srv) {
buffer_string_set_length(b, len); /*(truncate)*/
buffer_append_string_buffer(b, &ds->value);
if (-1 == stat(b->ptr, &st1)) {
log_error_write(srv, __FILE__, __LINE__, "sb",
"server.upload-dirs doesn't exist:", b);
log_error(srv->errh, __FILE__, __LINE__,
"server.upload-dirs doesn't exist: %s", b->ptr);
} else if (!S_ISDIR(st1.st_mode)) {
log_error_write(srv, __FILE__, __LINE__, "sb",
"server.upload-dirs isn't a directory:", b);
log_error(srv->errh, __FILE__, __LINE__,
"server.upload-dirs isn't a directory: %s", b->ptr);
}
}
}
@ -1807,8 +1816,7 @@ int config_set_defaults(server *srv) {
srv->srvconf.upload_temp_file_size);
if (buffer_string_is_empty(s->document_root)) {
log_error_write(srv, __FILE__, __LINE__, "s",
"document-root is not set");
log_error(srv->errh, __FILE__, __LINE__, "document-root is not set");
return -1;
}

View File

@ -8,7 +8,6 @@
#include "log.h"
#include "response.h"
#include <errno.h>
#include <stdlib.h>
#include <string.h>
@ -109,9 +108,7 @@ static int connection_handle_read_post_chunked_crlf(chunkqueue *cq) {
return 0;
}
handler_t connection_handle_read_post_error(server *srv, connection *con, int http_status) {
UNUSED(srv);
handler_t connection_handle_read_post_error(connection *con, int http_status) {
con->keep_alive = 0;
/*(do not change status if response headers already set and possibly sent)*/
@ -123,7 +120,7 @@ handler_t connection_handle_read_post_error(server *srv, connection *con, int ht
return HANDLER_FINISHED;
}
static handler_t connection_handle_read_post_chunked(server *srv, connection *con, chunkqueue *cq, chunkqueue *dst_cq) {
static handler_t connection_handle_read_post_chunked(connection *con, chunkqueue *cq, chunkqueue *dst_cq) {
/* con->conf.max_request_size is in kBytes */
const off_t max_request_size = (off_t)con->conf.max_request_size << 10;
@ -142,29 +139,29 @@ static handler_t connection_handle_read_post_chunked(server *srv, connection *co
unsigned char *s = (unsigned char *)c->mem->ptr+c->offset;
for (unsigned char u;(u=(unsigned char)hex2int(*s))!=0xFF;++s) {
if (te_chunked > (off_t)(1uLL<<(8*sizeof(off_t)-5))-1) {
log_error_write(srv, __FILE__, __LINE__, "s",
"chunked data size too large -> 400");
log_error(con->conf.errh, __FILE__, __LINE__,
"chunked data size too large -> 400");
/* 400 Bad Request */
return connection_handle_read_post_error(srv, con, 400);
return connection_handle_read_post_error(con, 400);
}
te_chunked <<= 4;
te_chunked |= u;
}
while (*s == ' ' || *s == '\t') ++s;
if (*s != '\r' && *s != ';') {
log_error_write(srv, __FILE__, __LINE__, "s",
"chunked header invalid chars -> 400");
log_error(con->conf.errh, __FILE__, __LINE__,
"chunked header invalid chars -> 400");
/* 400 Bad Request */
return connection_handle_read_post_error(srv, con, 400);
return connection_handle_read_post_error(con, 400);
}
if (hsz >= 1024) {
/* prevent theoretical integer overflow
* casting to (size_t) and adding 2 (for "\r\n") */
log_error_write(srv, __FILE__, __LINE__, "s",
"chunked header line too long -> 400");
log_error(con->conf.errh, __FILE__, __LINE__,
"chunked header line too long -> 400");
/* 400 Bad Request */
return connection_handle_read_post_error(srv, con, 400);
return connection_handle_read_post_error(con, 400);
}
if (0 == te_chunked) {
@ -188,7 +185,7 @@ static handler_t connection_handle_read_post_chunked(server *srv, connection *co
* potentially received by backend, if in the future
* these trailers are added to request headers)*/
if ((off_t)buffer_string_length(c->mem) - c->offset
< srv->srvconf.max_request_field_size) {
< con->srv->srvconf.max_request_field_size) {
break;
}
else {
@ -216,11 +213,11 @@ static handler_t connection_handle_read_post_chunked(server *srv, connection *co
if (0 !=max_request_size
&& (max_request_size < te_chunked
|| max_request_size - te_chunked < dst_cq->bytes_in)) {
log_error_write(srv, __FILE__, __LINE__, "sos",
"request-size too long:",
dst_cq->bytes_in + te_chunked, "-> 413");
log_error(con->conf.errh, __FILE__, __LINE__,
"request-size too long: %lld -> 413",
(long long)(dst_cq->bytes_in + te_chunked));
/* 413 Payload Too Large */
return connection_handle_read_post_error(srv, con, 413);
return connection_handle_read_post_error(con, 413);
}
te_chunked += 2; /*(for trailing "\r\n" after chunked data)*/
@ -231,10 +228,10 @@ static handler_t connection_handle_read_post_chunked(server *srv, connection *co
/*(likely better ways to handle chunked header crossing chunkqueue
* chunks, but this situation is not expected to occur frequently)*/
if ((off_t)buffer_string_length(c->mem) - c->offset >= 1024) {
log_error_write(srv, __FILE__, __LINE__, "s",
"chunked header line too long -> 400");
log_error(con->conf.errh, __FILE__, __LINE__,
"chunked header line too long -> 400");
/* 400 Bad Request */
return connection_handle_read_post_error(srv, con, 400);
return connection_handle_read_post_error(con, 400);
}
else if (!connection_handle_read_post_cq_compact(cq)) {
break;
@ -248,9 +245,10 @@ static handler_t connection_handle_read_post_chunked(server *srv, connection *co
/* avoid buffering request bodies <= 64k on disk */
chunkqueue_steal(dst_cq, cq, len);
}
else if (0 != chunkqueue_steal_with_tempfiles(srv,dst_cq,cq,len)) {
else if (0 != chunkqueue_steal_with_tempfiles(dst_cq, cq, len,
con->conf.errh)) {
/* 500 Internal Server Error */
return connection_handle_read_post_error(srv, con, 500);
return connection_handle_read_post_error(con, 500);
}
te_chunked -= len;
len = cq->bytes_in - cq->bytes_out;
@ -260,10 +258,10 @@ static handler_t connection_handle_read_post_chunked(server *srv, connection *co
if (2 == te_chunked) {
if (-1 == connection_handle_read_post_chunked_crlf(cq)) {
log_error_write(srv, __FILE__, __LINE__, "s",
"chunked data missing end CRLF -> 400");
log_error(con->conf.errh, __FILE__, __LINE__,
"chunked data missing end CRLF -> 400");
/* 400 Bad Request */
return connection_handle_read_post_error(srv, con, 400);
return connection_handle_read_post_error(con, 400);
}
chunkqueue_mark_written(cq, 2);/*consume \r\n at end of chunk data*/
te_chunked -= 2;
@ -275,21 +273,20 @@ static handler_t connection_handle_read_post_chunked(server *srv, connection *co
return HANDLER_GO_ON;
}
static handler_t connection_handle_read_body_unknown(server *srv, connection *con, chunkqueue *cq, chunkqueue *dst_cq) {
static handler_t connection_handle_read_body_unknown(connection *con, chunkqueue *cq, chunkqueue *dst_cq) {
/* con->conf.max_request_size is in kBytes */
const off_t max_request_size = (off_t)con->conf.max_request_size << 10;
chunkqueue_append_chunkqueue(dst_cq, cq);
if (0 != max_request_size && dst_cq->bytes_in > max_request_size) {
log_error_write(srv, __FILE__, __LINE__, "sos",
"request-size too long:", dst_cq->bytes_in, "-> 413");
log_error(con->conf.errh, __FILE__, __LINE__,
"request-size too long: %lld -> 413", (long long)dst_cq->bytes_in);
/* 413 Payload Too Large */
return connection_handle_read_post_error(srv, con, 413);
return connection_handle_read_post_error(con, 413);
}
return HANDLER_GO_ON;
}
static off_t connection_write_throttle(server *srv, connection *con, off_t max_bytes) {
UNUSED(srv);
static off_t connection_write_throttle(connection *con, off_t max_bytes) {
if (con->conf.global_bytes_per_second) {
off_t limit = (off_t)con->conf.global_bytes_per_second - *(con->conf.global_bytes_per_second_cnt_ptr);
if (limit <= 0) {
@ -317,14 +314,14 @@ static off_t connection_write_throttle(server *srv, connection *con, off_t max_b
return max_bytes;
}
int connection_write_chunkqueue(server *srv, connection *con, chunkqueue *cq, off_t max_bytes) {
int connection_write_chunkqueue(connection *con, chunkqueue *cq, off_t max_bytes) {
int ret = -1;
off_t written = 0;
#ifdef TCP_CORK
int corked = 0;
#endif
max_bytes = connection_write_throttle(srv, con, max_bytes);
max_bytes = connection_write_throttle(con, max_bytes);
if (0 == max_bytes) return 1;
written = cq->bytes_out;
@ -347,7 +344,7 @@ int connection_write_chunkqueue(server *srv, connection *con, chunkqueue *cq, of
}
#endif
ret = con->network_write(srv, con, cq, max_bytes);
ret = con->network_write(con, cq, max_bytes);
if (ret >= 0) {
ret = chunkqueue_is_empty(cq) ? 0 : 1;
}
@ -368,7 +365,7 @@ int connection_write_chunkqueue(server *srv, connection *con, chunkqueue *cq, of
return ret;
}
static int connection_write_100_continue(server *srv, connection *con) {
static int connection_write_100_continue(connection *con) {
/* Make best effort to send all or none of "HTTP/1.1 100 Continue" */
/* (Note: also choosing not to update con->write_request_ts
* which differs from connections.c:connection_handle_write()) */
@ -378,7 +375,7 @@ static int connection_write_100_continue(server *srv, connection *con) {
int rc;
off_t max_bytes =
connection_write_throttle(srv, con, sizeof(http_100_continue)-1);
connection_write_throttle(con, sizeof(http_100_continue)-1);
if (max_bytes < (off_t)sizeof(http_100_continue)-1) {
return 1; /* success; skip sending if throttled to partial */
}
@ -387,7 +384,7 @@ static int connection_write_100_continue(server *srv, connection *con) {
written = cq->bytes_out;
chunkqueue_append_mem(cq,http_100_continue,sizeof(http_100_continue)-1);
rc = con->network_write(srv, con, cq, sizeof(http_100_continue)-1);
rc = con->network_write(con, cq, sizeof(http_100_continue)-1);
written = cq->bytes_out - written;
con->bytes_written += written;
@ -423,7 +420,7 @@ handler_t connection_handle_read_post_state(server *srv, connection *con) {
if (con->is_readable) {
con->read_idle_ts = srv->cur_ts;
switch(con->network_read(srv, con, con->read_queue, MAX_READ_LIMIT)) {
switch(con->network_read(con, con->read_queue, MAX_READ_LIMIT)) {
case -1:
con->state = CON_STATE_ERROR;
return HANDLER_ERROR;
@ -445,7 +442,7 @@ handler_t connection_handle_read_post_state(server *srv, connection *con) {
const buffer *vb = http_header_request_get(con, HTTP_HEADER_EXPECT, CONST_STR_LEN("Expect"));
if (NULL != vb && buffer_eq_icase_slen(vb, CONST_STR_LEN("100-continue"))) {
http_header_request_unset(con, HTTP_HEADER_EXPECT, CONST_STR_LEN("Expect"));
if (!connection_write_100_continue(srv, con)) {
if (!connection_write_100_continue(con)) {
return HANDLER_ERROR;
}
}
@ -454,17 +451,17 @@ handler_t connection_handle_read_post_state(server *srv, connection *con) {
if (con->request.content_length < 0) {
/*(-1: Transfer-Encoding: chunked, -2: unspecified length)*/
handler_t rc = (-1 == con->request.content_length)
? connection_handle_read_post_chunked(srv, con, cq, dst_cq)
: connection_handle_read_body_unknown(srv, con, cq, dst_cq);
? connection_handle_read_post_chunked(con, cq, dst_cq)
: connection_handle_read_body_unknown(con, cq, dst_cq);
if (HANDLER_GO_ON != rc) return rc;
}
else if (con->request.content_length <= 64*1024) {
/* don't buffer request bodies <= 64k on disk */
chunkqueue_steal(dst_cq, cq, (off_t)con->request.content_length - dst_cq->bytes_in);
}
else if (0 != chunkqueue_steal_with_tempfiles(srv, dst_cq, cq, (off_t)con->request.content_length - dst_cq->bytes_in)) {
else if (0 != chunkqueue_steal_with_tempfiles(dst_cq, cq, (off_t)con->request.content_length - dst_cq->bytes_in, con->conf.errh)) {
/* writing to temp file failed */
return connection_handle_read_post_error(srv, con, 500); /* Internal Server Error */
return connection_handle_read_post_error(con, 500); /* Internal Server Error */
}
chunkqueue_remove_finished_chunks(cq);
@ -478,7 +475,7 @@ handler_t connection_handle_read_post_state(server *srv, connection *con) {
return HANDLER_GO_ON;
} else if (is_closed) {
#if 0
return connection_handle_read_post_error(srv, con, 400); /* Bad Request */
return connection_handle_read_post_error(con, 400); /* Bad Request */
#endif
return HANDLER_ERROR;
} else {

View File

@ -108,8 +108,8 @@ static void connection_plugin_ctx_check(server *srv, connection *con) {
plugin *p = ((plugin **)(srv->plugins.ptr))[i];
plugin_data_base *pd = p->data;
if (!pd || NULL == con->plugin_ctx[pd->id]) continue;
log_error_write(srv, __FILE__, __LINE__, "ss",
"missing cleanup in", p->name);
log_error(con->conf.errh, __FILE__, __LINE__,
"missing cleanup in %s", p->name);
con->plugin_ctx[pd->id] = NULL;
}
}
@ -126,23 +126,18 @@ static int connection_close(server *srv, connection *con) {
fdevent_unregister(srv->ev, con->fd);
con->fdn = NULL;
#ifdef __WIN32
if (closesocket(con->fd)) {
log_error_write(srv, __FILE__, __LINE__, "sds",
"(warning) close:", con->fd, strerror(errno));
}
if (0 == closesocket(con->fd))
#else
if (close(con->fd)) {
log_error_write(srv, __FILE__, __LINE__, "sds",
"(warning) close:", con->fd, strerror(errno));
}
if (0 == close(con->fd))
#endif
else {
srv->cur_fds--;
}
--srv->cur_fds;
else
log_perror(con->conf.errh, __FILE__, __LINE__,
"(warning) close: %d", con->fd);
if (srv->srvconf.log_state_handling) {
log_error_write(srv, __FILE__, __LINE__, "sd",
"connection closed for fd", con->fd);
log_error(con->conf.errh, __FILE__, __LINE__,
"connection closed for fd %d", con->fd);
}
con->fd = -1;
con->is_ssl_sock = 0;
@ -185,7 +180,7 @@ static void connection_read_for_eos_plain(server *srv, connection *con) {
}
static void connection_read_for_eos_ssl(server *srv, connection *con) {
if (con->network_read(srv, con, con->read_queue, MAX_READ_LIMIT) < 0)
if (con->network_read(con, con->read_queue, MAX_READ_LIMIT) < 0)
con->close_timeout_ts = srv->cur_ts - (HTTP_LINGER_TIMEOUT+1);
chunkqueue_reset(con->read_queue);
}
@ -217,8 +212,8 @@ static void connection_handle_shutdown(server *srv, connection *con) {
connection_set_state(con, CON_STATE_CLOSE);
if (srv->srvconf.log_state_handling) {
log_error_write(srv, __FILE__, __LINE__, "sd",
"shutdown for fd", con->fd);
log_error(con->conf.errh, __FILE__, __LINE__,
"shutdown for fd %d", con->fd);
}
} else {
connection_close(srv, con);
@ -226,8 +221,8 @@ static void connection_handle_shutdown(server *srv, connection *con) {
}
__attribute_cold__
static void connection_fdwaitqueue_append(server *srv, connection *con) {
connection_list_append(&srv->fdwaitqueue, con);
static void connection_fdwaitqueue_append(connection *con) {
connection_list_append(&con->srv->fdwaitqueue, con);
}
static void connection_handle_response_end_state(server *srv, connection *con) {
@ -296,7 +291,7 @@ static void connection_handle_errdoc(connection *con) {
buffer_copy_buffer(con->physical.path, con->conf.errorfile_prefix);
buffer_append_int(con->physical.path, con->http_status);
buffer_append_string_len(con->physical.path, CONST_STR_LEN(".html"));
if (0 == http_chunk_append_file(srv, con, con->physical.path)) {
if (0 == http_chunk_append_file(con, con->physical.path)) {
stat_cache_entry *sce = NULL;
if (stat_cache_get_entry(srv, con, con->physical.path, &sce)
!= HANDLER_ERROR) {
@ -330,7 +325,7 @@ static void connection_handle_errdoc(connection *con) {
"</h1>\n"
" </body>\n"
"</html>\n"));
(void)http_chunk_append_mem(srv, con, CONST_BUF_LEN(b));
(void)http_chunk_append_mem(con, CONST_BUF_LEN(b));
http_header_response_set(con, HTTP_HEADER_CONTENT_TYPE,
CONST_STR_LEN("Content-Type"),
@ -393,7 +388,7 @@ static int connection_handle_write_prepare(server *srv, connection *con) {
case HANDLER_FINISHED:
break;
default:
log_error_write(srv, __FILE__, __LINE__, "s", "response_start plugin failed");
log_error(con->conf.errh,__FILE__,__LINE__,"response_start plugin failed");
return -1;
}
@ -420,8 +415,11 @@ static int connection_handle_write_prepare(server *srv, connection *con) {
/* qlen = 0 is important for Redirects (301, ...) as they MAY have
* a content. Browsers are waiting for a Content otherwise
*/
buffer_copy_int(srv->tmp_buf, qlen);
http_header_response_set(con, HTTP_HEADER_CONTENT_LENGTH, CONST_STR_LEN("Content-Length"), CONST_BUF_LEN(srv->tmp_buf));
buffer * const tb = con->srv->tmp_buf;
buffer_copy_int(tb, qlen);
http_header_response_set(con, HTTP_HEADER_CONTENT_LENGTH,
CONST_STR_LEN("Content-Length"),
CONST_BUF_LEN(tb));
}
}
} else {
@ -465,34 +463,33 @@ static int connection_handle_write_prepare(server *srv, connection *con) {
con->file_finished = 1;
}
http_response_write_header(srv, con);
http_response_write_header(con);
return 0;
}
static void connection_handle_write(server *srv, connection *con) {
switch(connection_write_chunkqueue(srv, con, con->write_queue, MAX_WRITE_LIMIT)) {
switch(connection_write_chunkqueue(con, con->write_queue, MAX_WRITE_LIMIT)) {
case 0:
con->write_request_ts = srv->cur_ts;
if (con->file_finished) {
connection_set_state(con, CON_STATE_RESPONSE_END);
}
break;
case -1: /* error on our side */
log_error_write(srv, __FILE__, __LINE__, "sd",
"connection closed: write failed on fd", con->fd);
log_error(con->conf.errh, __FILE__, __LINE__,
"connection closed: write failed on fd %d", con->fd);
connection_set_state(con, CON_STATE_ERROR);
break;
case -2: /* remote close */
connection_set_state(con, CON_STATE_ERROR);
break;
case 1:
con->write_request_ts = srv->cur_ts;
con->is_writable = 0;
/* not finished yet -> WRITE */
break;
}
con->write_request_ts = srv->cur_ts;
}
static void connection_handle_write_state(server *srv, connection *con) {
@ -516,13 +513,13 @@ static void connection_handle_write_state(server *srv, connection *con) {
case HANDLER_GO_ON:
break;
case HANDLER_WAIT_FOR_FD:
connection_fdwaitqueue_append(srv, con);
connection_fdwaitqueue_append(con);
break;
case HANDLER_COMEBACK:
default:
log_error_write(srv, __FILE__, __LINE__, "sdd",
"unexpected subrequest handler ret-value:",
con->fd, r);
log_error(con->conf.errh, __FILE__, __LINE__,
"unexpected subrequest handler ret-value: %d %d",
con->fd, r);
/* fall through */
case HANDLER_ERROR:
connection_set_state(con, CON_STATE_ERROR);
@ -700,7 +697,7 @@ static int connection_reset(server *srv, connection *con) {
chunkqueue_reset(con->request_content_queue);
/* The cond_cache gets reset in response.c */
/* config_cond_cache_reset(srv, con); */
/* config_cond_cache_reset(con); */
con->async_callback = 0;
con->error_handler_saved_status = 0;
@ -726,7 +723,7 @@ static chunk * connection_read_header_more(connection *con, chunkqueue *cq, chun
if ((NULL == c || NULL == c->next) && con->is_readable) {
server * const srv = con->srv;
con->read_idle_ts = srv->cur_ts;
if (0 != con->network_read(srv, con, cq, MAX_READ_LIMIT))
if (0 != con->network_read(con, cq, MAX_READ_LIMIT))
connection_set_state(con, CON_STATE_ERROR);
}
@ -808,7 +805,7 @@ static int connection_handle_read_state(server * const srv, connection * const c
srv->srvconf.max_request_field_size;
if ((con->header_len ? con->header_len : clen) > max_request_field_size
|| hoff[0] >= sizeof(hoff)/sizeof(hoff[0])-1) {
log_error(con->errh, __FILE__, __LINE__, "%s",
log_error(con->conf.errh, __FILE__, __LINE__, "%s",
"oversized request-header -> sending Status 431");
con->http_status = 431; /* Request Header Fields Too Large */
con->keep_alive = 0;
@ -853,7 +850,7 @@ static int connection_handle_read_state(server * const srv, connection * const c
}
if (con->conf.log_request_header) {
log_error(con->errh, __FILE__, __LINE__,
log_error(con->conf.errh, __FILE__, __LINE__,
"fd: %d request-len: %d\n%.*s", con->fd, (int)con->header_len,
(int)con->header_len, hdrs);
}
@ -866,7 +863,7 @@ static int connection_handle_read_state(server * const srv, connection * const c
if (srv->srvconf.log_request_header_on_error) {
/*(http_request_parse() modifies hdrs only to
* undo line-wrapping in-place using spaces)*/
log_error(con->errh, __FILE__, __LINE__, "request-header:\n%.*s",
log_error(con->conf.errh, __FILE__, __LINE__, "request-header:\n%.*s",
(int)con->header_len, hdrs);
}
}
@ -954,8 +951,8 @@ static handler_t connection_handle_fdevent(server *srv, void *context, int reven
} else if (revents & FDEVENT_ERR) { /* error, connection reset */
connection_set_state(con, CON_STATE_ERROR);
} else {
log_error_write(srv, __FILE__, __LINE__, "sd",
"connection closed: poll() -> ???", revents);
log_error(con->conf.errh, __FILE__, __LINE__,
"connection closed: poll() -> ??? %d", revents);
}
}
@ -994,7 +991,7 @@ connection *connection_accept(server *srv, server_socket *srv_socket) {
/* out of fds */
break;
default:
log_error_write(srv, __FILE__, __LINE__, "ssd", "accept failed:", strerror(errno), errno);
log_perror(srv->errh, __FILE__, __LINE__, "accept failed");
}
return NULL;
} else {
@ -1007,7 +1004,7 @@ connection *connection_accept(server *srv, server_socket *srv_socket) {
/* 0: everything ok, -1: error, -2: con closed */
static int connection_read_cq(server *srv, connection *con, chunkqueue *cq, off_t max_bytes) {
static int connection_read_cq(connection *con, chunkqueue *cq, off_t max_bytes) {
ssize_t len;
char *mem = NULL;
size_t mem_len = 0;
@ -1051,7 +1048,7 @@ static int connection_read_cq(server *srv, connection *con, chunkqueue *cq, off_
/* suppress logging for this error, expected for keep-alive */
break;
default:
log_error_write(srv, __FILE__, __LINE__, "sd", "connection closed - recv failed: ", lastError);
log_error(con->conf.errh, __FILE__, __LINE__, "connection closed - recv failed: %d", lastError);
break;
}
}
@ -1067,7 +1064,7 @@ static int connection_read_cq(server *srv, connection *con, chunkqueue *cq, off_
/* suppress logging for this error, expected for keep-alive */
break;
default:
log_error_write(srv, __FILE__, __LINE__, "ssd", "connection closed - read failed: ", strerror(errno), errno);
log_perror(con->conf.errh, __FILE__, __LINE__, "connection closed - read failed");
break;
}
#endif /* __WIN32 */
@ -1093,8 +1090,9 @@ static int connection_read_cq(server *srv, connection *con, chunkqueue *cq, off_
}
static int connection_write_cq(server *srv, connection *con, chunkqueue *cq, off_t max_bytes) {
return srv->network_backend_write(srv, con->fd, cq, max_bytes);
static int connection_write_cq(connection *con, chunkqueue *cq, off_t max_bytes) {
server * const srv = con->srv;
return srv->network_backend_write(con->fd, cq, max_bytes, con->conf.errh);
}
@ -1105,13 +1103,12 @@ connection *connection_accepted(server *srv, server_socket *srv_socket, sock_add
/* ok, we have the connection, register it */
#if 0
log_error_write(srv, __FILE__, __LINE__, "sd",
"appected()", cnt);
log_error(srv->errh, __FILE__, __LINE__, "accepted() %d", cnt);
#endif
srv->con_opened++;
con = connections_get_new_connection(srv);
con->errh = srv->errh;
con->conf.errh = srv->errh;
con->srv = srv;
con->fd = cnt;
@ -1127,7 +1124,7 @@ connection *connection_accepted(server *srv, server_socket *srv_socket, sock_add
con->srv_socket = srv_socket;
con->is_ssl_sock = srv_socket->is_ssl;
config_cond_cache_reset(srv, con);
config_cond_cache_reset(con);
con->conditional_is_valid |= (1 << COMP_SERVER_SOCKET)
| (1 << COMP_HTTP_REMOTE_IP);
@ -1229,7 +1226,7 @@ static int connection_handle_request(server *srv, connection *con) {
connection_set_state(con, CON_STATE_RESPONSE_START);
break;
case HANDLER_WAIT_FOR_FD:
connection_fdwaitqueue_append(srv, con);
connection_fdwaitqueue_append(con);
break;
case HANDLER_COMEBACK:
if (con->mode == DIRECT && buffer_is_empty(con->physical.path)) {