From c485cdb0249415b8aee5968b2b8854921e152854 Mon Sep 17 00:00:00 2001 From: Ryan Prichard Date: Tue, 30 Apr 2019 14:47:34 -0700 Subject: Revert fwalk/sfp locking to fix concurrent reads The locking can fail in a couple of ways: - A concurrent fread from an unbuffered or line-buffered file flushes the output of other line-buffered files, and if _fwalk locks every file, then the fread blocks until other file reads have completed. - __sfp can initialize a file lock while _fwalk is locking/unlocking it. For now, revert to the behavior Bionic had in previous releases. This commit reverts the file locking parts of commit 468efc80da2504f4ae7de8b5e137426d44dda9d7. Bug: http://b/131251441 Bug: http://b/130189834 Test: bionic unit tests Change-Id: I9e20b9cd8ccd14e7962f7308e174f08af72b56c6 --- tests/stdio_test.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'tests/stdio_test.cpp') diff --git a/tests/stdio_test.cpp b/tests/stdio_test.cpp index 65a942c37..c237d6d32 100644 --- a/tests/stdio_test.cpp +++ b/tests/stdio_test.cpp @@ -29,6 +29,7 @@ #include #include +#include #include #include @@ -2577,3 +2578,24 @@ TEST(STDIO_TEST, dev_std_files) { ASSERT_LT(0, length); ASSERT_EQ("/proc/self/fd/2", std::string(path, length)); } + +TEST(STDIO_TEST, fread_with_locked_file) { + // Reading an unbuffered/line-buffered file from one thread shouldn't block on + // files locked on other threads, even if it flushes some line-buffered files. + FILE* fp1 = fopen("/dev/zero", "r"); + ASSERT_TRUE(fp1 != nullptr); + flockfile(fp1); + + std::thread([] { + for (int mode : { _IONBF, _IOLBF }) { + FILE* fp2 = fopen("/dev/zero", "r"); + ASSERT_TRUE(fp2 != nullptr); + setvbuf(fp2, nullptr, mode, 0); + ASSERT_EQ('\0', fgetc(fp2)); + fclose(fp2); + } + }).join(); + + funlockfile(fp1); + fclose(fp1); +} -- cgit v1.2.3 From 31c7309dc6d4385f120ec30dae3c0adcb5a7db1d Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Tue, 7 May 2019 10:03:02 -0700 Subject: Add SEEK_DATA and SEEK_HOLE constants. Without pulling in , the UAPI source of these constants, because it's full of pollution, in particular a macro called BLOCK_SIZE that breaks a lot of stuff. Test: treehugger Change-Id: I7258ec57e91c67645c2b4d0ce44850d757c4bb12 --- tests/stdio_test.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'tests/stdio_test.cpp') diff --git a/tests/stdio_test.cpp b/tests/stdio_test.cpp index c237d6d32..01b4dbab7 100644 --- a/tests/stdio_test.cpp +++ b/tests/stdio_test.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -2599,3 +2600,13 @@ TEST(STDIO_TEST, fread_with_locked_file) { funlockfile(fp1); fclose(fp1); } + +TEST(STDIO_TEST, SEEK_macros) { + ASSERT_EQ(0, SEEK_SET); + ASSERT_EQ(1, SEEK_CUR); + ASSERT_EQ(2, SEEK_END); + ASSERT_EQ(3, SEEK_DATA); + ASSERT_EQ(4, SEEK_HOLE); + // So we'll notice if Linux grows another constant in ... + ASSERT_EQ(SEEK_MAX, SEEK_HOLE); +} -- cgit v1.2.3