From: Maxim Georgiev Date: Tue, 21 Mar 2017 02:31:48 +0000 (-0700) Subject: In AsyncSocketTest.SendMessageFlags test use folly::test::TemporaryFile object instea... X-Git-Tag: v2017.03.27.00~22 X-Git-Url: http://plrg.eecs.uci.edu/git/?p=folly.git;a=commitdiff_plain;h=3ffa8cf0d790a265ad7cfc172276eb09de26b30f In AsyncSocketTest.SendMessageFlags test use folly::test::TemporaryFile object instead of directly creating a file with O_TMPFILE flag Summary: O_TMPFILE flag is not available on older Linux systems (supported starting Linux 3.11). Got complains about it on GitHub (https://fburl.com/9d848m7i) Will use folly::test::TemporaryFile instead. Reviewed By: yfeldblum Differential Revision: D4729733 fbshipit-source-id: 903563825c5b939e35c61725da559e33d21212c4 --- diff --git a/folly/io/async/test/AsyncSocketTest2.cpp b/folly/io/async/test/AsyncSocketTest2.cpp index a1988722..cbca3d34 100644 --- a/folly/io/async/test/AsyncSocketTest2.cpp +++ b/folly/io/async/test/AsyncSocketTest2.cpp @@ -3094,6 +3094,7 @@ TEST(AsyncSocketTest, SendMessageAncillaryData) { // Set up listening socket int lfd = fsp::socket(AF_UNIX, SOCK_STREAM, 0); ASSERT_NE(lfd, -1); + SCOPE_EXIT { close(lfd); }; ASSERT_NE(bind(lfd, (struct sockaddr*)&addr, sizeof(addr)), -1) << "Bind failed: " << errno; @@ -3111,6 +3112,7 @@ TEST(AsyncSocketTest, SendMessageAncillaryData) { // Accept the connection int sfd = accept(lfd, nullptr, nullptr); ASSERT_NE(sfd, -1); + SCOPE_EXIT { close(sfd); }; // Instantiate AsyncSocket object for the connected socket EventBase evb; @@ -3119,7 +3121,10 @@ TEST(AsyncSocketTest, SendMessageAncillaryData) { // Open a temporary file and write a magic string to it // We'll transfer the file handle to test the message parameters // callback logic. - int tmpfd = open("/var/tmp", O_RDWR | O_TMPFILE); + TemporaryFile file(StringPiece(), + fs::path(), + TemporaryFile::Scope::UNLINK_IMMEDIATELY); + int tmpfd = file.fd(); ASSERT_NE(tmpfd, -1) << "Failed to open a temporary file"; std::string magicString("Magic string"); ASSERT_EQ(write(tmpfd, magicString.c_str(), magicString.length()), @@ -3178,6 +3183,7 @@ TEST(AsyncSocketTest, SendMessageAncillaryData) { int fd = 0; memcpy(&fd, CMSG_DATA(&r_u.cmh), sizeof(int)); ASSERT_NE(fd, 0); + SCOPE_EXIT { close(fd); }; std::vector transferredMagicString(magicString.length() + 1, 0);