-
Notifications
You must be signed in to change notification settings - Fork 15.1k
Revert "[libc] Return errno from OFD failure paths in fcntl." #166658
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+73
−94
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This reverts commit 81dede8.
Member
|
@llvm/pr-subscribers-libc Author: Jackson Stogel (jtstogel) ChangesReverts llvm/llvm-project#166252 Full diff: https://github.com/llvm/llvm-project/pull/166658.diff 2 Files Affected:
diff --git a/libc/src/__support/OSUtil/linux/fcntl.cpp b/libc/src/__support/OSUtil/linux/fcntl.cpp
index 08db4859c6417..bb76eee90efd2 100644
--- a/libc/src/__support/OSUtil/linux/fcntl.cpp
+++ b/libc/src/__support/OSUtil/linux/fcntl.cpp
@@ -66,7 +66,7 @@ ErrorOr<int> fcntl(int fd, int cmd, void *arg) {
LIBC_NAMESPACE::syscall_impl<int>(FCNTL_SYSCALL_ID, fd, cmd, &flk64);
// On failure, return
if (ret < 0)
- return Error(-ret);
+ return Error(-1);
// Check for overflow, i.e. the offsets are not the same when cast
// to off_t from off64_t.
if (static_cast<off_t>(flk64.l_len) != flk64.l_len ||
diff --git a/libc/test/src/fcntl/fcntl_test.cpp b/libc/test/src/fcntl/fcntl_test.cpp
index d6aaccddd76ee..84feb34e537a0 100644
--- a/libc/test/src/fcntl/fcntl_test.cpp
+++ b/libc/test/src/fcntl/fcntl_test.cpp
@@ -94,99 +94,78 @@ TEST_F(LlvmLibcFcntlTest, FcntlSetFl) {
ASSERT_THAT(LIBC_NAMESPACE::close(fd), Succeeds(0));
}
-/* Tests that are common between OFD and traditional variants of fcntl locks. */
-template <int GETLK_CMD, int SETLK_CMD>
-class LibcFcntlCommonLockTests : public LlvmLibcFcntlTest {
-public:
- void GetLkRead() {
- using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
- constexpr const char *TEST_FILE_NAME = "testdata/fcntl_getlkread.test";
- const auto TEST_FILE = libc_make_test_file_path(TEST_FILE_NAME);
-
- struct flock flk = {};
- struct flock svflk = {};
- int retVal;
- int fd =
- LIBC_NAMESPACE::open(TEST_FILE, O_CREAT | O_TRUNC | O_RDONLY, S_IRWXU);
- ASSERT_ERRNO_SUCCESS();
- ASSERT_GT(fd, 0);
-
- flk.l_type = F_RDLCK;
- flk.l_start = 0;
- flk.l_whence = SEEK_SET;
- flk.l_len = 50;
-
- // copy flk into svflk
- svflk = flk;
-
- retVal = LIBC_NAMESPACE::fcntl(fd, GETLK_CMD, &svflk);
- ASSERT_ERRNO_SUCCESS();
- ASSERT_GT(retVal, -1);
- ASSERT_NE((int)svflk.l_type, F_WRLCK); // File should not be write locked.
-
- retVal = LIBC_NAMESPACE::fcntl(fd, SETLK_CMD, &svflk);
- ASSERT_ERRNO_SUCCESS();
- ASSERT_GT(retVal, -1);
-
- ASSERT_THAT(LIBC_NAMESPACE::close(fd), Succeeds(0));
- }
-
- void GetLkWrite() {
- using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
- constexpr const char *TEST_FILE_NAME = "testdata/fcntl_getlkwrite.test";
- const auto TEST_FILE = libc_make_test_file_path(TEST_FILE_NAME);
-
- struct flock flk = {};
- struct flock svflk = {};
- int retVal;
- int fd =
- LIBC_NAMESPACE::open(TEST_FILE, O_CREAT | O_TRUNC | O_RDWR, S_IRWXU);
- ASSERT_ERRNO_SUCCESS();
- ASSERT_GT(fd, 0);
-
- flk.l_type = F_WRLCK;
- flk.l_start = 0;
- flk.l_whence = SEEK_SET;
- flk.l_len = 0;
-
- // copy flk into svflk
- svflk = flk;
-
- retVal = LIBC_NAMESPACE::fcntl(fd, GETLK_CMD, &svflk);
- ASSERT_ERRNO_SUCCESS();
- ASSERT_GT(retVal, -1);
- ASSERT_NE((int)svflk.l_type, F_RDLCK); // File should not be read locked.
-
- retVal = LIBC_NAMESPACE::fcntl(fd, SETLK_CMD, &svflk);
- ASSERT_ERRNO_SUCCESS();
- ASSERT_GT(retVal, -1);
-
- ASSERT_THAT(LIBC_NAMESPACE::close(fd), Succeeds(0));
- }
-
- void UseAfterClose() {
- using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
- constexpr const char *TEST_FILE_NAME =
- "testdata/fcntl_use_after_close.test";
- const auto TEST_FILE = libc_make_test_file_path(TEST_FILE_NAME);
- int fd =
- LIBC_NAMESPACE::open(TEST_FILE, O_CREAT | O_TRUNC | O_RDWR, S_IRWXU);
- ASSERT_THAT(LIBC_NAMESPACE::close(fd), Succeeds(0));
- ASSERT_EQ(-1, LIBC_NAMESPACE::fcntl(fd, GETLK_CMD));
- ASSERT_ERRNO_EQ(EBADF);
- }
-};
-
-#define COMMON_LOCK_TESTS(NAME, GETLK, SETLK) \
- using NAME = LibcFcntlCommonLockTests<GETLK, SETLK>; \
- TEST_F(NAME, GetLkRead) { GetLkRead(); } \
- TEST_F(NAME, GetLkWrite) { GetLkWrite(); } \
- TEST_F(NAME, UseAfterClose) { UseAfterClose(); } \
- static_assert(true, "Require semicolon.")
-
-COMMON_LOCK_TESTS(LlvmLibcFcntlProcessAssociatedLockTest, F_GETLK, F_SETLK);
-COMMON_LOCK_TESTS(LlvmLibcFcntlOpenFileDescriptionLockTest, F_OFD_GETLK,
- F_OFD_SETLK);
+TEST_F(LlvmLibcFcntlTest, FcntlGetLkRead) {
+ using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
+ constexpr const char *TEST_FILE_NAME = "testdata/fcntl_getlkread.test";
+ auto TEST_FILE = libc_make_test_file_path(TEST_FILE_NAME);
+
+ struct flock flk, svflk;
+ int retVal;
+ int fd =
+ LIBC_NAMESPACE::open(TEST_FILE, O_CREAT | O_TRUNC | O_RDONLY, S_IRWXU);
+ ASSERT_ERRNO_SUCCESS();
+ ASSERT_GT(fd, 0);
+
+ flk.l_type = F_RDLCK;
+ flk.l_start = 0;
+ flk.l_whence = SEEK_SET;
+ flk.l_len = 50;
+
+ // copy flk into svflk
+ svflk = flk;
+
+ retVal = LIBC_NAMESPACE::fcntl(fd, F_GETLK, &svflk);
+ ASSERT_ERRNO_SUCCESS();
+ ASSERT_GT(retVal, -1);
+ ASSERT_NE((int)flk.l_type, F_WRLCK); // File should not be write locked.
+
+ retVal = LIBC_NAMESPACE::fcntl(fd, F_SETLK, &svflk);
+ ASSERT_ERRNO_SUCCESS();
+ ASSERT_GT(retVal, -1);
+
+ ASSERT_THAT(LIBC_NAMESPACE::close(fd), Succeeds(0));
+}
+
+TEST_F(LlvmLibcFcntlTest, FcntlGetLkWrite) {
+ using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
+ constexpr const char *TEST_FILE_NAME = "testdata/fcntl_getlkwrite.test";
+ auto TEST_FILE = libc_make_test_file_path(TEST_FILE_NAME);
+
+ struct flock flk, svflk;
+ int retVal;
+ int fd = LIBC_NAMESPACE::open(TEST_FILE, O_CREAT | O_TRUNC | O_RDWR, S_IRWXU);
+ ASSERT_ERRNO_SUCCESS();
+ ASSERT_GT(fd, 0);
+
+ flk.l_type = F_WRLCK;
+ flk.l_start = 0;
+ flk.l_whence = SEEK_SET;
+ flk.l_len = 0;
+
+ // copy flk into svflk
+ svflk = flk;
+
+ retVal = LIBC_NAMESPACE::fcntl(fd, F_GETLK, &svflk);
+ ASSERT_ERRNO_SUCCESS();
+ ASSERT_GT(retVal, -1);
+ ASSERT_NE((int)flk.l_type, F_RDLCK); // File should not be read locked.
+
+ retVal = LIBC_NAMESPACE::fcntl(fd, F_SETLK, &svflk);
+ ASSERT_ERRNO_SUCCESS();
+ ASSERT_GT(retVal, -1);
+
+ ASSERT_THAT(LIBC_NAMESPACE::close(fd), Succeeds(0));
+}
+
+TEST_F(LlvmLibcFcntlTest, UseAfterClose) {
+ using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
+ constexpr const char *TEST_FILE_NAME = "testdata/fcntl_use_after_close.test";
+ auto TEST_FILE = libc_make_test_file_path(TEST_FILE_NAME);
+ int fd = LIBC_NAMESPACE::open(TEST_FILE, O_CREAT | O_TRUNC | O_RDWR, S_IRWXU);
+ ASSERT_THAT(LIBC_NAMESPACE::close(fd), Succeeds(0));
+ ASSERT_EQ(-1, LIBC_NAMESPACE::fcntl(fd, F_GETFL));
+ ASSERT_ERRNO_EQ(EBADF);
+}
TEST_F(LlvmLibcFcntlTest, SetGetOwnerTest) {
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
|
lntue
approved these changes
Nov 5, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Reverts #166252
Causing buildbot failures on
libc-x86_64-debian-dbg-asan.