diff options
author | Christopher Ferris <cferris@google.com> | 2014-09-24 16:01:18 -0700 |
---|---|---|
committer | Christopher Ferris <cferris@google.com> | 2014-09-24 16:50:30 -0700 |
commit | 528ad742c671f17a9f8731ad8de4bcc931631bc9 (patch) | |
tree | 5b0cdb0b310ba6c7bf3ccf11dcc7bfa5058fbf50 /tests/sys_stat_test.cpp | |
parent | 567d3fcb7ece287a84912183e91eff851fa48fc2 (diff) |
Fix sys_stat.mkfifo when not run as root.
It's not allowed for a shell user to create a fifo in /data/local/tmp.
Make the test do nothing if not run as root.
Bug: 17646702
(cherry picked from commit 6c69afdb6ddd56e011b59e3060f12a5bdffb5f5c)
Change-Id: Ia3a862ed4586413b7bb393557ab57e0a7141d888
Diffstat (limited to 'tests/sys_stat_test.cpp')
-rw-r--r-- | tests/sys_stat_test.cpp | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/tests/sys_stat_test.cpp b/tests/sys_stat_test.cpp index a57a706e5..64049ab61 100644 --- a/tests/sys_stat_test.cpp +++ b/tests/sys_stat_test.cpp @@ -56,18 +56,22 @@ TEST(sys_stat, futimens_EBADF) { } TEST(sys_stat, mkfifo) { - // Racy but probably sufficient way to get a suitable filename. - std::string path; - { - TemporaryFile tf; - path = tf.filename; - } + if (getuid() == 0) { + // Racy but probably sufficient way to get a suitable filename. + std::string path; + { + TemporaryFile tf; + path = tf.filename; + } - ASSERT_EQ(0, mkfifo(path.c_str(), 0666)); - struct stat sb; - ASSERT_EQ(0, stat(path.c_str(), &sb)); - ASSERT_TRUE(S_ISFIFO(sb.st_mode)); - unlink(path.c_str()); + ASSERT_EQ(0, mkfifo(path.c_str(), 0666)); + struct stat sb; + ASSERT_EQ(0, stat(path.c_str(), &sb)); + ASSERT_TRUE(S_ISFIFO(sb.st_mode)); + unlink(path.c_str()); + } else { + GTEST_LOG_(INFO) << "This test only performs a test when run as root."; + } } TEST(sys_stat, stat64_lstat64_fstat64) { |