You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by yl...@apache.org on 2021/09/19 16:53:44 UTC
svn commit: r1893445 - in /apr/apr/trunk: buckets/apr_buckets_file.c
file_io/os2/filedup.c file_io/unix/filedup.c file_io/win32/filedup.c
Author: ylavic
Date: Sun Sep 19 16:53:44 2021
New Revision: 1893445
URL: http://svn.apache.org/viewvc?rev=1893445&view=rev
Log:
Follow up to r1893204: restore apr_file_setaside() semantics, fix file_bucket_setaside().
apr_file_setasidea() needs to invalidate the old file descriptor per semantics:
* @remark After calling this function, old_file may not be used
So to avoid the setaside issue with splitted file buckets, file_bucket_setaside()
will now apr_file_dup() instead of apr_file_setaside() when the bucket is shared
(i.e. refcount > 1).
Modified:
apr/apr/trunk/buckets/apr_buckets_file.c
apr/apr/trunk/file_io/os2/filedup.c
apr/apr/trunk/file_io/unix/filedup.c
apr/apr/trunk/file_io/win32/filedup.c
Modified: apr/apr/trunk/buckets/apr_buckets_file.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/buckets/apr_buckets_file.c?rev=1893445&r1=1893444&r2=1893445&view=diff
==============================================================================
--- apr/apr/trunk/buckets/apr_buckets_file.c (original)
+++ apr/apr/trunk/buckets/apr_buckets_file.c Sun Sep 19 16:53:44 2021
@@ -212,9 +212,9 @@ APR_DECLARE(apr_status_t) apr_bucket_fil
return APR_SUCCESS;
}
-static apr_status_t file_bucket_setaside(apr_bucket *data, apr_pool_t *reqpool)
+static apr_status_t file_bucket_setaside(apr_bucket *b, apr_pool_t *reqpool)
{
- apr_bucket_file *a = data->data;
+ apr_bucket_file *a = b->data;
apr_file_t *fd = NULL;
apr_file_t *f = a->fd;
apr_pool_t *curpool = apr_file_pool_get(f);
@@ -223,11 +223,33 @@ static apr_status_t file_bucket_setaside
return APR_SUCCESS;
}
- if (!apr_pool_is_ancestor(a->readpool, reqpool)) {
- a->readpool = reqpool;
- }
+ /* If the file is shared/split accross multiple buckets, this bucket can't
+ * take exclusive ownership with apr_file_setaside() (thus invalidating the
+ * f->filedes), let's apr_file_dup() in this case instead.
+ */
+ if (a->refcount.refcount > 1) {
+ apr_bucket_file *new;
+ apr_status_t rv;
+
+ rv = apr_file_dup(&fd, f, reqpool);
+ if (rv != APR_SUCCESS) {
+ return rv;
+ }
+
+ new = apr_bucket_alloc(sizeof(*new), b->list);
+ memcpy(new, a, sizeof(*new));
+ new->refcount.refcount = 1;
+ new->readpool = reqpool;
- apr_file_setaside(&fd, f, reqpool);
+ a->refcount.refcount--;
+ a = b->data = new;
+ }
+ else {
+ apr_file_setaside(&fd, f, reqpool);
+ if (!apr_pool_is_ancestor(a->readpool, reqpool)) {
+ a->readpool = reqpool;
+ }
+ }
a->fd = fd;
return APR_SUCCESS;
}
Modified: apr/apr/trunk/file_io/os2/filedup.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/file_io/os2/filedup.c?rev=1893445&r1=1893444&r2=1893445&view=diff
==============================================================================
--- apr/apr/trunk/file_io/os2/filedup.c (original)
+++ apr/apr/trunk/file_io/os2/filedup.c Sun Sep 19 16:53:44 2021
@@ -120,5 +120,6 @@ APR_DECLARE(apr_status_t) apr_file_setas
apr_file_cleanup);
}
+ old_file->filedes = -1;
return APR_SUCCESS;
}
Modified: apr/apr/trunk/file_io/unix/filedup.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/file_io/unix/filedup.c?rev=1893445&r1=1893444&r2=1893445&view=diff
==============================================================================
--- apr/apr/trunk/file_io/unix/filedup.c (original)
+++ apr/apr/trunk/file_io/unix/filedup.c Sun Sep 19 16:53:44 2021
@@ -188,6 +188,7 @@ APR_DECLARE(apr_status_t) apr_file_setas
: apr_unix_child_file_cleanup);
}
+ old_file->filedes = -1;
#ifndef WAITIO_USES_POLL
(*new_file)->pollset = NULL;
#endif
Modified: apr/apr/trunk/file_io/win32/filedup.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/file_io/win32/filedup.c?rev=1893445&r1=1893444&r2=1893445&view=diff
==============================================================================
--- apr/apr/trunk/file_io/win32/filedup.c (original)
+++ apr/apr/trunk/file_io/win32/filedup.c Sun Sep 19 16:53:44 2021
@@ -218,6 +218,7 @@ APR_DECLARE(apr_status_t) apr_file_setas
file_cleanup);
}
+ old_file->filehand = INVALID_HANDLE_VALUE;
#if APR_FILES_AS_SOCKETS
/* Create a pollset with room for one descriptor. */
/* ### check return codes */