You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by jo...@apache.org on 2005/08/20 11:11:40 UTC
svn commit: r234013 - in /apr/apr/trunk: CHANGES file_io/unix/readwrite.c
test/testfile.c
Author: jorton
Date: Sat Aug 20 02:11:33 2005
New Revision: 234013
URL: http://svn.apache.org/viewcvs?rev=234013&view=rev
Log:
* file_io/unix/readwrite.c (apr_file_write): Catch apr_file_flush()
failure for buffered files.
* test/testfile.c (test_fail_write_flush): Add test case.
Submitted by: Erik Huelsmann <ehuels gmail.com>
Modified:
apr/apr/trunk/CHANGES
apr/apr/trunk/file_io/unix/readwrite.c
apr/apr/trunk/test/testfile.c
Modified: apr/apr/trunk/CHANGES
URL: http://svn.apache.org/viewcvs/apr/apr/trunk/CHANGES?rev=234013&r1=234012&r2=234013&view=diff
==============================================================================
--- apr/apr/trunk/CHANGES (original)
+++ apr/apr/trunk/CHANGES Sat Aug 20 02:11:33 2005
@@ -1,5 +1,8 @@
Changes for APR 1.3.0
+ *) Fix apr_file_write() infinite loop on write failure for buffered
+ files. [Erik Huelsmann <eh...@gmail.com>]
+
*) Add %pm support to apr_snprintf() for printing the error string
corresponding to an apr_status_t value. [Joe Orton]
Modified: apr/apr/trunk/file_io/unix/readwrite.c
URL: http://svn.apache.org/viewcvs/apr/apr/trunk/file_io/unix/readwrite.c?rev=234013&r1=234012&r2=234013&view=diff
==============================================================================
--- apr/apr/trunk/file_io/unix/readwrite.c (original)
+++ apr/apr/trunk/file_io/unix/readwrite.c Sat Aug 20 02:11:33 2005
@@ -170,7 +170,7 @@
rv = 0;
while (rv == 0 && size > 0) {
if (thefile->bufpos == APR_FILE_BUFSIZE) /* write buffer is full*/
- apr_file_flush(thefile);
+ rv = apr_file_flush(thefile);
blocksize = size > APR_FILE_BUFSIZE - thefile->bufpos ?
APR_FILE_BUFSIZE - thefile->bufpos : size;
Modified: apr/apr/trunk/test/testfile.c
URL: http://svn.apache.org/viewcvs/apr/apr/trunk/test/testfile.c?rev=234013&r1=234012&r2=234013&view=diff
==============================================================================
--- apr/apr/trunk/test/testfile.c (original)
+++ apr/apr/trunk/test/testfile.c Sat Aug 20 02:11:33 2005
@@ -703,6 +703,37 @@
free(to_write);
}
+static void test_fail_write_flush(abts_case *tc, void *data)
+{
+ apr_file_t *f;
+ const char *fname = "data/testflush.dat";
+ apr_status_t rv;
+ char buf[APR_BUFFERSIZE];
+ int n;
+
+ apr_file_remove(fname, p);
+
+ APR_ASSERT_SUCCESS(tc, "open test file",
+ apr_file_open(&f, fname,
+ APR_CREATE|APR_READ|APR_BUFFERED,
+ APR_UREAD|APR_UWRITE, p));
+
+ memset(buf, 'A', sizeof buf);
+
+ /* Try three writes. One of these should fail when it exceeds the
+ * internal buffer and actually tries to write to the file, which
+ * was opened read-only and hence should be unwritable. */
+ for (n = 0, rv = APR_SUCCESS; n < 4 && rv == APR_SUCCESS; n++) {
+ apr_size_t bytes = sizeof buf;
+ rv = apr_file_write(f, buf, &bytes);
+ }
+
+ ABTS_ASSERT(tc, "failed to write to read-only buffered fd",
+ rv != APR_SUCCESS);
+
+ apr_file_close(f);
+}
+
abts_suite *testfile(abts_suite *suite)
{
suite = ADD_SUITE(suite)
@@ -733,6 +764,7 @@
abts_run_test(suite, test_mod_neg, NULL);
abts_run_test(suite, test_truncate, NULL);
abts_run_test(suite, test_bigfprintf, NULL);
+ abts_run_test(suite, test_fail_write_flush, NULL);
return suite;
}