[multiple] fdevent_mkostemp()

fdevent_mkostemp() with flags arg so that caller can pass O_APPEND

renamed from fdevent_mkstemp_append(), previously always O_APPEND
master
Glenn Strauss 2 years ago
parent 2e60c4e0b2
commit 9f62f1b196

@ -436,6 +436,7 @@ if 1:
'mempcpy',
'memset_s',
'memset',
'mkostemp',
'mmap',
'munmap',
'pathconf',

@ -1506,6 +1506,7 @@ AC_CHECK_FUNCS([\
mempcpy \
memset \
memset_s \
mkostemp \
mmap \
pathconf \
pipe2 \

@ -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)

@ -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) {

@ -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

@ -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);

@ -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;

@ -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))

@ -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))

@ -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);
}

Loading…
Cancel
Save