From 2cef5b3ce4bc988ac93ff128218f4b0dddb0f074 Mon Sep 17 00:00:00 2001 From: Lucian Petrut Date: Mon, 6 Nov 2023 14:58:08 +0000 Subject: [PATCH] test: fix Windows ::_creat The Windows Universal C Runtime (ucrt) "_creat" function is no longer POSIX compatible and requires Windows specific mode flags. We got admin socket test failures after switching from msvcrt to uscrt. We'll address the issue with some platform checks. Signed-off-by: Lucian Petrut --- src/global/signal_handler.cc | 4 ++++ src/test/admin_socket.cc | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/src/global/signal_handler.cc b/src/global/signal_handler.cc index 055763eee46..d3387267871 100644 --- a/src/global/signal_handler.cc +++ b/src/global/signal_handler.cc @@ -276,7 +276,11 @@ void generate_crash_dump(char *base, ::close(fd); } snprintf(fn, sizeof(fn)-1, "%s/done", base); + #ifdef _WIN32 + ::creat(fn, _S_IREAD); + #else ::creat(fn, 0444); + #endif } } } diff --git a/src/test/admin_socket.cc b/src/test/admin_socket.cc index a8236271652..03bbb72b2a9 100644 --- a/src/test/admin_socket.cc +++ b/src/test/admin_socket.cc @@ -239,7 +239,11 @@ TEST(AdminSocketClient, Ping) { ASSERT_FALSE(ok); } // file exists but does not allow connections (no process, wrong type...) + #ifdef _WIN32 + int fd = ::creat(path.c_str(), _S_IREAD | _S_IWRITE); + #else int fd = ::creat(path.c_str(), 0777); + #endif ASSERT_TRUE(fd); // On Windows, we won't be able to remove the file unless we close it // first. @@ -307,7 +311,11 @@ TEST(AdminSocket, bind_and_listen) { { int fd = 0; string message; + #ifdef _WIN32 + int fd2 = ::creat(path.c_str(), _S_IREAD | _S_IWRITE); + #else int fd2 = ::creat(path.c_str(), 0777); + #endif ASSERT_TRUE(fd2); // On Windows, we won't be able to remove the file unless we close it // first. -- 2.39.5