summaryrefslogtreecommitdiff
path: root/file_io
diff options
context:
space:
mode:
Diffstat (limited to 'file_io')
-rw-r--r--file_io/unix/copy.c1
-rw-r--r--file_io/unix/flock.c8
-rw-r--r--file_io/unix/pipe.c64
-rw-r--r--file_io/unix/readwrite.c2
-rw-r--r--file_io/unix/seek.c7
5 files changed, 60 insertions, 22 deletions
diff --git a/file_io/unix/copy.c b/file_io/unix/copy.c
index df3a49c8209ec..7f74d30c16b84 100644
--- a/file_io/unix/copy.c
+++ b/file_io/unix/copy.c
@@ -41,6 +41,7 @@ static apr_status_t apr_file_transfer_contents(const char *from_path,
return status;
}
perms = finfo.protection;
+ apr_file_perms_set(to_path, perms); /* ignore any failure */
}
else
perms = to_perms;
diff --git a/file_io/unix/flock.c b/file_io/unix/flock.c
index f400a96701db8..01e8a639ba918 100644
--- a/file_io/unix/flock.c
+++ b/file_io/unix/flock.c
@@ -32,8 +32,8 @@ APR_DECLARE(apr_status_t) apr_file_lock(apr_file_t *thefile, int type)
struct flock l = { 0 };
int fc;
- l.l_whence = SEEK_SET; /* lock from current point */
- l.l_start = 0; /* begin lock at this offset */
+ l.l_whence = SEEK_SET; /* count l_start from start of file */
+ l.l_start = 0; /* lock from start of file */
l.l_len = 0; /* lock to end of file */
if ((type & APR_FLOCK_TYPEMASK) == APR_FLOCK_SHARED)
l.l_type = F_RDLCK;
@@ -90,8 +90,8 @@ APR_DECLARE(apr_status_t) apr_file_unlock(apr_file_t *thefile)
{
struct flock l = { 0 };
- l.l_whence = SEEK_SET; /* lock from current point */
- l.l_start = 0; /* begin lock at this offset */
+ l.l_whence = SEEK_SET; /* count l_start from start of file */
+ l.l_start = 0; /* lock from start of file */
l.l_len = 0; /* lock to end of file */
l.l_type = F_UNLCK;
diff --git a/file_io/unix/pipe.c b/file_io/unix/pipe.c
index 571d9bcb8e99f..7be16e5d0a1b5 100644
--- a/file_io/unix/pipe.c
+++ b/file_io/unix/pipe.c
@@ -176,7 +176,8 @@ APR_DECLARE(apr_status_t) apr_os_pipe_put(apr_file_t **file,
return apr_os_pipe_put_ex(file, thefile, 0, pool);
}
-APR_DECLARE(apr_status_t) apr_file_pipe_create(apr_file_t **in, apr_file_t **out, apr_pool_t *pool)
+static apr_status_t file_pipe_create(apr_file_t **in, apr_file_t **out,
+ apr_pool_t *pool_in, apr_pool_t *pool_out)
{
int filedes[2];
@@ -184,8 +185,8 @@ APR_DECLARE(apr_status_t) apr_file_pipe_create(apr_file_t **in, apr_file_t **out
return errno;
}
- (*in) = (apr_file_t *)apr_pcalloc(pool, sizeof(apr_file_t));
- (*in)->pool = pool;
+ (*in) = (apr_file_t *)apr_pcalloc(pool_in, sizeof(apr_file_t));
+ (*in)->pool = pool_in;
(*in)->filedes = filedes[0];
(*in)->is_pipe = 1;
(*in)->fname = NULL;
@@ -200,8 +201,8 @@ APR_DECLARE(apr_status_t) apr_file_pipe_create(apr_file_t **in, apr_file_t **out
#ifndef WAITIO_USES_POLL
(*in)->pollset = NULL;
#endif
- (*out) = (apr_file_t *)apr_pcalloc(pool, sizeof(apr_file_t));
- (*out)->pool = pool;
+ (*out) = (apr_file_t *)apr_pcalloc(pool_out, sizeof(apr_file_t));
+ (*out)->pool = pool_out;
(*out)->filedes = filedes[1];
(*out)->is_pipe = 1;
(*out)->fname = NULL;
@@ -222,6 +223,30 @@ APR_DECLARE(apr_status_t) apr_file_pipe_create(apr_file_t **in, apr_file_t **out
return APR_SUCCESS;
}
+static void file_pipe_block(apr_file_t **in, apr_file_t **out, apr_int32_t blocking)
+{
+ switch (blocking) {
+ case APR_FULL_BLOCK:
+ break;
+ case APR_READ_BLOCK:
+ apr_file_pipe_timeout_set(*out, 0);
+ break;
+ case APR_WRITE_BLOCK:
+ apr_file_pipe_timeout_set(*in, 0);
+ break;
+ default:
+ apr_file_pipe_timeout_set(*out, 0);
+ apr_file_pipe_timeout_set(*in, 0);
+ break;
+ }
+}
+
+APR_DECLARE(apr_status_t) apr_file_pipe_create(apr_file_t **in,
+ apr_file_t **out, apr_pool_t *pool)
+{
+ return file_pipe_create(in, out, pool, pool);
+}
+
APR_DECLARE(apr_status_t) apr_file_pipe_create_ex(apr_file_t **in,
apr_file_t **out,
apr_int32_t blocking,
@@ -229,23 +254,26 @@ APR_DECLARE(apr_status_t) apr_file_pipe_create_ex(apr_file_t **in,
{
apr_status_t status;
- if ((status = apr_file_pipe_create(in, out, pool)) != APR_SUCCESS)
+ if ((status = file_pipe_create(in, out, pool, pool)) != APR_SUCCESS) {
return status;
+ }
- switch (blocking) {
- case APR_FULL_BLOCK:
- break;
- case APR_READ_BLOCK:
- apr_file_pipe_timeout_set(*out, 0);
- break;
- case APR_WRITE_BLOCK:
- apr_file_pipe_timeout_set(*in, 0);
- break;
- default:
- apr_file_pipe_timeout_set(*out, 0);
- apr_file_pipe_timeout_set(*in, 0);
+ file_pipe_block(in, out, blocking);
+
+ return APR_SUCCESS;
+}
+
+APR_DECLARE(apr_status_t) apr_file_pipe_create_pools(apr_file_t **in,
+ apr_file_t **out, apr_int32_t blocking, apr_pool_t *pool_in, apr_pool_t *pool_out)
+{
+ apr_status_t status;
+
+ if ((status = file_pipe_create(in, out, pool_in, pool_out)) != APR_SUCCESS) {
+ return status;
}
+ file_pipe_block(in, out, blocking);
+
return APR_SUCCESS;
}
diff --git a/file_io/unix/readwrite.c b/file_io/unix/readwrite.c
index 7044300c17c12..0759495affb9f 100644
--- a/file_io/unix/readwrite.c
+++ b/file_io/unix/readwrite.c
@@ -387,6 +387,8 @@ APR_DECLARE(apr_status_t) apr_file_datasync(apr_file_t *thefile)
#ifdef HAVE_FDATASYNC
if (fdatasync(thefile->filedes)) {
+#elif defined(F_FULLFSYNC)
+ if (fcntl(thefile->filedes, F_FULLFSYNC)) {
#else
if (fsync(thefile->filedes)) {
#endif
diff --git a/file_io/unix/seek.c b/file_io/unix/seek.c
index 3f5aa00e95677..2e973377bf84d 100644
--- a/file_io/unix/seek.c
+++ b/file_io/unix/seek.c
@@ -117,6 +117,13 @@ apr_status_t apr_file_trunc(apr_file_t *fp, apr_off_t offset)
/* Reset buffer positions for write mode */
fp->bufpos = fp->direction = fp->dataRead = 0;
}
+ else if (fp->direction == 0) {
+ /* Discard the read buffer, as we are about to reposition
+ * ourselves to the end of file.
+ */
+ fp->bufpos = 0;
+ fp->dataRead = 0;
+ }
file_unlock(fp);
if (rc) {
return rc;