OSDN Git Service

Fix android-cloexec-pipe clang-tidy warning
authorYi Kong <yikong@google.com>
Thu, 15 Aug 2019 20:27:46 +0000 (13:27 -0700)
committerYi Kong <yikong@google.com>
Thu, 22 Aug 2019 21:41:11 +0000 (21:41 +0000)
The upcoming clang-tidy update finds a new instance of
android-cloexec-pipe warning:

FileUtilsTests.cpp:72:13: error: prefer pipe2() with O_CLOEXEC to avoid leaking file descriptors to child processes
ASSERT_EQ(pipe(pipefd), 0);
^~~~~~~~~~~~
pipe2(pipefd, O_CLOEXEC)

Apply the suggested fix by clang-tidy.

Test: build
Bug: 131328001
Exempt-From-Owner-Approval: Cherrypick
Change-Id: Iee772b5c3ed5e2af481e479dab19030f8419290a
Merged-In: Iee772b5c3ed5e2af481e479dab19030f8419290a
(cherry picked from commit f61e2167d5352b63eb34a086cdcb0dfec485bdf0)

cmds/idmap2/tests/FileUtilsTests.cpp

index f4a306e..f55acee 100644 (file)
@@ -15,6 +15,7 @@
  */
 
 #include <dirent.h>
+#include <fcntl.h>
 
 #include <set>
 #include <string>
@@ -69,7 +70,7 @@ TEST(FileUtilsTests, FindFilesFindApkFilesRecursive) {
 
 TEST(FileUtilsTests, ReadFile) {
   int pipefd[2];
-  ASSERT_EQ(pipe(pipefd), 0);
+  ASSERT_EQ(pipe2(pipefd, O_CLOEXEC), 0);
 
   ASSERT_EQ(write(pipefd[1], "foobar", 6), 6);
   close(pipefd[1]);