diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/chunk.c | 2 | ||||
-rw-r--r-- | src/config.h.cmake | 1 | ||||
-rw-r--r-- | src/fdevent.c | 7 | ||||
-rw-r--r-- | src/fdevent.h | 2 | ||||
-rw-r--r-- | src/meson.build | 1 | ||||
-rw-r--r-- | src/mod_dirlisting.c | 2 | ||||
-rw-r--r-- | src/mod_webdav.c | 2 |
8 files changed, 12 insertions, 6 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d34d8f4c..14e49a29 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -178,6 +178,7 @@ check_function_exists(mallopt HAVE_MALLOPT) check_function_exists(memcpy HAVE_MEMCPY) check_function_exists(mempcpy HAVE_MEMPCPY) check_function_exists(memset HAVE_MEMSET) +check_function_exists(mkostemp HAVE_MKOSTEMP) check_function_exists(mmap HAVE_MMAP) check_function_exists(pathconf HAVE_PATHCONF) check_function_exists(pipe2 HAVE_PIPE2) diff --git a/src/chunk.c b/src/chunk.c index 1a68d683..84b8076d 100644 --- a/src/chunk.c +++ b/src/chunk.c @@ -641,7 +641,7 @@ void chunkqueue_steal(chunkqueue * const restrict dest, chunkqueue * const restr static int chunkqueue_get_append_mkstemp(buffer * const b, const char *path, const uint32_t len) { buffer_copy_path_len2(b,path,len,CONST_STR_LEN("lighttpd-upload-XXXXXX")); - return fdevent_mkstemp_append(b->ptr); + return fdevent_mkostemp(b->ptr, O_APPEND); } static chunk *chunkqueue_get_append_newtempfile(chunkqueue * const restrict cq, log_error_st * const restrict errh) { diff --git a/src/config.h.cmake b/src/config.h.cmake index cb1773c9..f4459c69 100644 --- a/src/config.h.cmake +++ b/src/config.h.cmake @@ -133,6 +133,7 @@ #cmakedefine HAVE_MEMCPY #cmakedefine HAVE_MEMPCPY #cmakedefine HAVE_MEMSET +#cmakedefine HAVE_MKOSTEMP #cmakedefine HAVE_MMAP #cmakedefine HAVE_PATHCONF #cmakedefine HAVE_POLL diff --git a/src/fdevent.c b/src/fdevent.c index 4aa2d963..4635922c 100644 --- a/src/fdevent.c +++ b/src/fdevent.c @@ -609,7 +609,10 @@ int fdevent_open_dirname(char *path, int symlinks) { } -int fdevent_mkstemp_append(char *path) { +int fdevent_mkostemp(char *path, int flags) { + #if defined(HAVE_MKOSTEMP) + return mkostemp(path, O_CLOEXEC | flags); + #else #ifdef __COVERITY__ /* POSIX-2008 requires mkstemp create file with 0600 perms */ umask(0600); @@ -618,7 +621,7 @@ int fdevent_mkstemp_append(char *path) { const int fd = mkstemp(path); if (fd < 0) return fd; - if (0 != fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) | O_APPEND)) { + if (flags && 0 != fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) | flags)) { /* (should not happen; fd is regular file) */ int errnum = errno; close(fd); diff --git a/src/fdevent.h b/src/fdevent.h index b7e86b97..06de520c 100644 --- a/src/fdevent.h +++ b/src/fdevent.h @@ -87,7 +87,7 @@ int fdevent_socket_cloexec(int domain, int type, int protocol); int fdevent_socket_nb_cloexec(int domain, int type, int protocol); int fdevent_dup_cloexec(int fd); int fdevent_open_cloexec(const char *pathname, int symlinks, int flags, mode_t mode); -int fdevent_mkstemp_append(char *path); +int fdevent_mkostemp(char *path, int flags); int fdevent_rename(const char *oldpath, const char *newpath); struct sockaddr; diff --git a/src/meson.build b/src/meson.build index 8bfb965f..46baf59b 100644 --- a/src/meson.build +++ b/src/meson.build @@ -131,6 +131,7 @@ conf_data.set('HAVE_MALLOPT', compiler.has_function('mallopt', args: defs)) conf_data.set('HAVE_MEMCPY', compiler.has_function('memcpy', args: defs)) conf_data.set('HAVE_MEMPCPY', compiler.has_function('mempcpy', args: defs)) conf_data.set('HAVE_MEMSET', compiler.has_function('memset', args: defs)) +conf_data.set('HAVE_MKOSTEMP', compiler.has_function('mkostemp', args: defs)) conf_data.set('HAVE_MMAP', compiler.has_function('mmap', args: defs)) conf_data.set('HAVE_PATHCONF', compiler.has_function('pathconf', args: defs)) conf_data.set('HAVE_PIPE2', compiler.has_function('pipe2', args: defs)) diff --git a/src/mod_dirlisting.c b/src/mod_dirlisting.c index db752f20..f727db59 100644 --- a/src/mod_dirlisting.c +++ b/src/mod_dirlisting.c @@ -1442,7 +1442,7 @@ static void mod_dirlisting_cache_add (request_st * const r, plugin_data * const memcpy(newpath, tb->ptr, len+1); /*(include '\0')*/ buffer_append_string_len(tb, CONST_STR_LEN(".XXXXXX")); memcpy(oldpath, tb->ptr, len+7+1); /*(include '\0')*/ - const int fd = fdevent_mkstemp_append(oldpath); + const int fd = fdevent_mkostemp(oldpath, 0); if (fd < 0) return; if (mod_dirlisting_write_cq(fd, &r->write_queue, r->conf.errh) && 0 == rename(oldpath, newpath)) diff --git a/src/mod_webdav.c b/src/mod_webdav.c index d62a13f8..74314833 100644 --- a/src/mod_webdav.c +++ b/src/mod_webdav.c @@ -4416,7 +4416,7 @@ mod_webdav_put_prep (request_st * const r, const plugin_config * const pconf) #endif { buffer_append_string_len(&r->physical.path, CONST_STR_LEN("-XXXXXX")); - fd = fdevent_mkstemp_append(r->physical.path.ptr); + fd = fdevent_mkostemp(r->physical.path.ptr, 0); if (fd >= 0) unlink(r->physical.path.ptr); buffer_truncate(&r->physical.path, len); } |