Browse Source

[core] set chunkqueue tempdirs at startup

If server.upload-dirs is not configured, then attempt to use TMPDIR
from the environment, if set, or else use /tmp.  Warn at startup if
tempdirs are not present.
personal/stbuehler/mod-csrf-old
Glenn Strauss 5 years ago
parent
commit
c8e647ad31
  1. 22
      src/chunk.c
  2. 2
      src/chunk.h
  3. 12
      src/configfile.c
  4. 4
      src/connections.c

22
src/chunk.c

@ -22,6 +22,13 @@
#include <errno.h>
#include <string.h>
/* default 1MB, upper limit 128MB */
#define DEFAULT_TEMPFILE_SIZE (1 * 1024 * 1024)
#define MAX_TEMPFILE_SIZE (128 * 1024 * 1024)
static array *chunkqueue_default_tempdirs = NULL;
static unsigned int chunkqueue_default_tempfile_size = DEFAULT_TEMPFILE_SIZE;
chunkqueue *chunkqueue_init(void) {
chunkqueue *cq;
@ -33,6 +40,9 @@ chunkqueue *chunkqueue_init(void) {
cq->unused = NULL;
cq->tempdirs = chunkqueue_default_tempdirs;
cq->upload_temp_file_size = chunkqueue_default_tempfile_size;
return cq;
}
@ -377,10 +387,15 @@ void chunkqueue_use_memory(chunkqueue *cq, size_t len) {
}
}
/* default 1MB, upper limit 128MB */
#define DEFAULT_TEMPFILE_SIZE (1 * 1024 * 1024)
#define MAX_TEMPFILE_SIZE (128 * 1024 * 1024)
void chunkqueue_set_tempdirs_default (array *tempdirs, unsigned int upload_temp_file_size) {
chunkqueue_default_tempdirs = tempdirs;
chunkqueue_default_tempfile_size
= (0 == upload_temp_file_size) ? DEFAULT_TEMPFILE_SIZE
: (upload_temp_file_size > MAX_TEMPFILE_SIZE) ? MAX_TEMPFILE_SIZE
: upload_temp_file_size;
}
#if 0
void chunkqueue_set_tempdirs(chunkqueue *cq, array *tempdirs, unsigned int upload_temp_file_size) {
force_assert(NULL != cq);
cq->tempdirs = tempdirs;
@ -390,6 +405,7 @@ void chunkqueue_set_tempdirs(chunkqueue *cq, array *tempdirs, unsigned int uploa
: upload_temp_file_size;
cq->tempdir_idx = 0;
}
#endif
void chunkqueue_steal(chunkqueue *dest, chunkqueue *src, off_t len) {
while (len > 0) {

2
src/chunk.h

@ -50,7 +50,7 @@ typedef struct {
} chunkqueue;
chunkqueue *chunkqueue_init(void);
void chunkqueue_set_tempdirs(chunkqueue *cq, array *tempdirs, unsigned int upload_temp_file_size);
void chunkqueue_set_tempdirs_default (array *tempdirs, unsigned int upload_temp_file_size);
void chunkqueue_append_file(chunkqueue *cq, buffer *fn, off_t offset, off_t len); /* copies "fn" */
void chunkqueue_append_file_fd(chunkqueue *cq, buffer *fn, int fd, off_t offset, off_t len); /* copies "fn" */
void chunkqueue_append_mem(chunkqueue *cq, const char *mem, size_t len); /* copies memory */

12
src/configfile.c

@ -1363,6 +1363,14 @@ int config_set_defaults(server *srv) {
}
}
if (!srv->srvconf.upload_tempdirs->used) {
data_string *ds = data_string_init();
const char *tmpdir = getenv("TMPDIR");
if (NULL == tmpdir) tmpdir = "/tmp";
buffer_copy_string(ds->value, tmpdir);
array_insert_unique(srv->srvconf.upload_tempdirs, (data_unset *)ds);
}
if (srv->srvconf.upload_tempdirs->used) {
buffer * const b = srv->tmp_buf;
size_t len;
@ -1388,6 +1396,10 @@ int config_set_defaults(server *srv) {
}
}
chunkqueue_set_tempdirs_default(
srv->srvconf.upload_tempdirs,
srv->srvconf.upload_temp_file_size);
if (buffer_string_is_empty(s->document_root)) {
log_error_write(srv, __FILE__, __LINE__, "s",
"a default document-root has to be set");

4
src/connections.c

@ -612,10 +612,6 @@ connection *connection_init(server *srv) {
con->write_queue = chunkqueue_init();
con->read_queue = chunkqueue_init();
con->request_content_queue = chunkqueue_init();
chunkqueue_set_tempdirs(
con->request_content_queue,
srv->srvconf.upload_tempdirs,
srv->srvconf.upload_temp_file_size);
con->request.headers = array_init();
con->response.headers = array_init();

Loading…
Cancel
Save