Bug #2588 » chunk.c.patch
chunk_new.c 2017-08-28 01:47:48.000000000 +0200 | ||
---|---|---|
return 0;
|
||
}
|
||
#ifdef __linux__
|
||
#include <linux/version.h>
|
||
#endif
|
||
#include <stdlib.h> /* to get retrieved the POSIX_SOURCE defines */
|
||
int os_fallocate(int fd, off_t filesize) {
|
||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,23)
|
||
return fallocate(fd, 0, 0, filesize);
|
||
#elif _XOPEN_SOURCE >= 600 || _POSIX_C_SOURCE >= 200112L
|
||
return posix_fallocate(fd, 0, filesize);
|
||
#else
|
||
/* fprintf(stderr, "unsupported platform, old upload bug can still occur\n"); */
|
||
#endif
|
||
}
|
||
chunk *chunkqueue_get_append_tempfile(chunkqueue *cq) {
|
||
chunk *c;
|
||
buffer *template = buffer_init_string("/var/tmp/lighttpd-upload-XXXXXX");
|
||
... | ... | |
if (-1 != (c->file.fd = mkstemp(template->ptr))) {
|
||
/* only trigger the unlink if we created the temp-file successfully */
|
||
c->file.is_temp = 1;
|
||
break;
|
||
/* ensure that there is enough storage for our data */
|
||
const int MAX_CHUNK_SIZE = 1 * 1024 * 1024;
|
||
if (os_fallocate(c->file.fd, MAX_CHUNK_SIZE + 1) ) {
|
||
/* fprintf(stderr, "not enough space on storage: %d\n", i); */
|
||
close(c->file.fd);
|
||
c->file.fd = -1;
|
||
unlink(template->ptr);
|
||
}
|
||
else {
|
||
lseek(c->file.fd, 0, SEEK_SET);
|
||
c->file.is_temp = 1;
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
} else {
|