AU: shift to use new TMPDIR-enabled temp file

The main change here is that delta generator will now create all
temporary files in TMPDIR, if set. Other than that, we're converting all
other temporary file/directory creation to use the new functions.

- All temps of the form "/tmp/foo" are converted to "foo": this
  preserves the behavior in the default case (where TMPDIR is not set),
  yet will do the right thing if run with a different TMPDIR.

- A few other cases (for example, temp file created relative to the
  current working directory) will now be created in TMPDIR or /tmp.
  These are all in unit tests and the transition makes sense anyway.

Note that two temp file/directory creation calls in actual UE code were
using "/tmp/..." and were not changed. This will ensure that they are
resilient to TMPDIR changes and will always be allocated in the same
(hard-coded) location.

BUG=chromium:253622
TEST=Unit tests.

Change-Id: Ia1208963a0e2fcd43b8d6f92bb3d1b7459e930a2
Reviewed-on: https://chromium-review.googlesource.com/182247
Tested-by: Gilad Arnold <garnold@chromium.org>
Reviewed-by: Don Garrett <dgarrett@chromium.org>
Commit-Queue: Gilad Arnold <garnold@chromium.org>
diff --git a/delta_diff_generator.cc b/delta_diff_generator.cc
index f69a1fe..d42b296 100644
--- a/delta_diff_generator.cc
+++ b/delta_diff_generator.cc
@@ -288,7 +288,7 @@
   ScopedFdCloser image_fd_closer(&image_fd);
 
   string temp_file_path;
-  TEST_AND_RETURN_FALSE(utils::MakeTempFile("/tmp/CrAU_temp_data.XXXXXX",
+  TEST_AND_RETURN_FALSE(utils::MakeTempFile("CrAU_temp_data.XXXXXX",
                                             &temp_file_path,
                                             NULL));
 
@@ -1559,7 +1559,7 @@
   Graph graph;
   CheckGraph(graph);
 
-  const string kTempFileTemplate("/tmp/CrAU_temp_data.XXXXXX");
+  const string kTempFileTemplate("CrAU_temp_data.XXXXXX");
   string temp_file_path;
   scoped_ptr<ScopedPathUnlinker> temp_file_unlinker;
   off_t data_file_size = 0;
@@ -1684,7 +1684,7 @@
   // Reorder the data blobs with the newly ordered manifest
   string ordered_blobs_path;
   TEST_AND_RETURN_FALSE(utils::MakeTempFile(
-      "/tmp/CrAU_temp_data.ordered.XXXXXX",
+      "CrAU_temp_data.ordered.XXXXXX",
       &ordered_blobs_path,
       NULL));
   ScopedPathUnlinker ordered_blobs_unlinker(ordered_blobs_path);
@@ -1801,7 +1801,7 @@
 bool DeltaDiffGenerator::BsdiffFiles(const string& old_file,
                                      const string& new_file,
                                      vector<char>* out) {
-  const string kPatchFile = "/tmp/delta.patchXXXXXX";
+  const string kPatchFile = "delta.patchXXXXXX";
   string patch_file_path;
 
   TEST_AND_RETURN_FALSE(
diff --git a/delta_diff_generator_unittest.cc b/delta_diff_generator_unittest.cc
index 510d1ed..7d9095e 100644
--- a/delta_diff_generator_unittest.cc
+++ b/delta_diff_generator_unittest.cc
@@ -697,7 +697,7 @@
 
   // Prepare the filesystem with the minimum required for this to work
   string temp_dir;
-  EXPECT_TRUE(utils::MakeTempDirectory("/tmp/AssignTempBlocksTest.XXXXXX",
+  EXPECT_TRUE(utils::MakeTempDirectory("AssignTempBlocksTest.XXXXXX",
                                        &temp_dir));
   ScopedDirRemover temp_dir_remover(temp_dir);
 
@@ -708,7 +708,7 @@
   ScopedPathUnlinker filename_unlinker(temp_dir + kFilename);
 
   int fd;
-  EXPECT_TRUE(utils::MakeTempFile("/tmp/AssignTempBlocksTestData.XXXXXX",
+  EXPECT_TRUE(utils::MakeTempFile("AssignTempBlocksTestData.XXXXXX",
                                   NULL,
                                   &fd));
   ScopedFdCloser fd_closer(&fd);
@@ -814,7 +814,7 @@
 
   // Prepare the filesystem with the minimum required for this to work.
   string temp_dir;
-  EXPECT_TRUE(utils::MakeTempDirectory("/tmp/NoSparseAsTempTest.XXXXXX",
+  EXPECT_TRUE(utils::MakeTempDirectory("NoSparseAsTempTest.XXXXXX",
                                        &temp_dir));
   ScopedDirRemover temp_dir_remover(temp_dir);
 
@@ -825,7 +825,7 @@
   ScopedPathUnlinker filename_unlinker(temp_dir + kFilename);
 
   int fd = -1;
-  EXPECT_TRUE(utils::MakeTempFile("/tmp/NoSparseAsTempTestData.XXXXXX",
+  EXPECT_TRUE(utils::MakeTempFile("NoSparseAsTempTestData.XXXXXX",
                                   NULL,
                                   &fd));
   ScopedFdCloser fd_closer(&fd);
@@ -1075,7 +1075,7 @@
 
   // Prepare the filesystem with the minimum required for this to work
   string temp_dir;
-  EXPECT_TRUE(utils::MakeTempDirectory("/tmp/AssignTempBlocksReuseTest.XXXXXX",
+  EXPECT_TRUE(utils::MakeTempDirectory("AssignTempBlocksReuseTest.XXXXXX",
                                        &temp_dir));
   ScopedDirRemover temp_dir_remover(temp_dir);
 
@@ -1086,7 +1086,7 @@
   ScopedPathUnlinker filename_unlinker(temp_dir + kFilename);
 
   int fd;
-  EXPECT_TRUE(utils::MakeTempFile("/tmp/AssignTempBlocksReuseTest.XXXXXX",
+  EXPECT_TRUE(utils::MakeTempFile("AssignTempBlocksReuseTest.XXXXXX",
                                   NULL,
                                   &fd));
   ScopedFdCloser fd_closer(&fd);
diff --git a/delta_performer_unittest.cc b/delta_performer_unittest.cc
index f02d1b7..4ec8dac 100644
--- a/delta_performer_unittest.cc
+++ b/delta_performer_unittest.cc
@@ -177,7 +177,7 @@
                                       const string& payload_path) {
   string private_key_path = kUnittestPrivateKeyPath;
   if (signature_test == kSignatureGeneratedShellBadKey) {
-    ASSERT_TRUE(utils::MakeTempFile("/tmp/key.XXXXXX",
+    ASSERT_TRUE(utils::MakeTempFile("key.XXXXXX",
                                     &private_key_path,
                                     NULL));
   } else {
@@ -198,7 +198,7 @@
   }
   int signature_size = GetSignatureSize(private_key_path);
   string hash_file;
-  ASSERT_TRUE(utils::MakeTempFile("/tmp/hash.XXXXXX", &hash_file, NULL));
+  ASSERT_TRUE(utils::MakeTempFile("hash.XXXXXX", &hash_file, NULL));
   ScopedPathUnlinker hash_unlinker(hash_file);
   string signature_size_string;
   if (signature_test == kSignatureGeneratedShellRotateCl1 ||
@@ -222,7 +222,7 @@
   ASSERT_TRUE(WriteFileVector(hash_file, hash));
 
   string sig_file;
-  ASSERT_TRUE(utils::MakeTempFile("/tmp/signature.XXXXXX", &sig_file, NULL));
+  ASSERT_TRUE(utils::MakeTempFile("signature.XXXXXX", &sig_file, NULL));
   ScopedPathUnlinker sig_unlinker(sig_file);
   ASSERT_EQ(0,
             System(StringPrintf(
@@ -231,7 +231,7 @@
                 hash_file.c_str(),
                 sig_file.c_str())));
   string sig_file2;
-  ASSERT_TRUE(utils::MakeTempFile("/tmp/signature.XXXXXX", &sig_file2, NULL));
+  ASSERT_TRUE(utils::MakeTempFile("signature.XXXXXX", &sig_file2, NULL));
   ScopedPathUnlinker sig2_unlinker(sig_file2);
   if (signature_test == kSignatureGeneratedShellRotateCl1 ||
       signature_test == kSignatureGeneratedShellRotateCl2) {
@@ -272,8 +272,8 @@
                               off_t chunk_size,
                               SignatureTest signature_test,
                               DeltaState *state) {
-  EXPECT_TRUE(utils::MakeTempFile("/tmp/a_img.XXXXXX", &state->a_img, NULL));
-  EXPECT_TRUE(utils::MakeTempFile("/tmp/b_img.XXXXXX", &state->b_img, NULL));
+  EXPECT_TRUE(utils::MakeTempFile("a_img.XXXXXX", &state->a_img, NULL));
+  EXPECT_TRUE(utils::MakeTempFile("b_img.XXXXXX", &state->b_img, NULL));
   CreateExtImageAtPath(state->a_img, NULL);
 
   state->image_size = static_cast<int>(utils::FileSize(state->a_img));
@@ -410,12 +410,12 @@
   }
 
   string old_kernel;
-  EXPECT_TRUE(utils::MakeTempFile("/tmp/old_kernel.XXXXXX",
+  EXPECT_TRUE(utils::MakeTempFile("old_kernel.XXXXXX",
                                   &state->old_kernel,
                                   NULL));
 
   string new_kernel;
-  EXPECT_TRUE(utils::MakeTempFile("/tmp/new_kernel.XXXXXX",
+  EXPECT_TRUE(utils::MakeTempFile("new_kernel.XXXXXX",
                                   &state->new_kernel,
                                   NULL));
 
@@ -439,7 +439,7 @@
                                &state->new_kernel_data[0],
                                state->new_kernel_data.size()));
 
-  EXPECT_TRUE(utils::MakeTempFile("/tmp/delta.XXXXXX",
+  EXPECT_TRUE(utils::MakeTempFile("delta.XXXXXX",
                                   &state->delta_path,
                                   NULL));
   LOG(INFO) << "delta path: " << state->delta_path;
@@ -1265,7 +1265,7 @@
   FakeHardware* fake_hardware = mock_system_state.get_fake_hardware();
 
   string temp_dir;
-  EXPECT_TRUE(utils::MakeTempDirectory("/tmp/PublicKeyFromResponseTests.XXXXXX",
+  EXPECT_TRUE(utils::MakeTempDirectory("PublicKeyFromResponseTests.XXXXXX",
                                        &temp_dir));
   string non_existing_file = temp_dir + "/non-existing";
   string existing_file = temp_dir + "/existing";
diff --git a/file_writer_unittest.cc b/file_writer_unittest.cc
index 35bfb86..52a50a9 100644
--- a/file_writer_unittest.cc
+++ b/file_writer_unittest.cc
@@ -22,7 +22,7 @@
 TEST(FileWriterTest, SimpleTest) {
   // Create a uniquely named file for testing.
   string path;
-  ASSERT_TRUE(utils::MakeTempFile("/tmp/FileWriterTest-XXXXXX", &path, NULL));
+  ASSERT_TRUE(utils::MakeTempFile("FileWriterTest-XXXXXX", &path, NULL));
   ScopedPathUnlinker path_unlinker(path);
 
   DirectFileWriter file_writer;
@@ -47,7 +47,7 @@
 TEST(FileWriterTest, WriteErrorTest) {
   // Create a uniquely named file for testing.
   string path;
-  ASSERT_TRUE(utils::MakeTempFile("/tmp/FileWriterTest-XXXXXX", &path, NULL));
+  ASSERT_TRUE(utils::MakeTempFile("FileWriterTest-XXXXXX", &path, NULL));
   ScopedPathUnlinker path_unlinker(path);
 
   DirectFileWriter file_writer;
diff --git a/filesystem_copier_action_unittest.cc b/filesystem_copier_action_unittest.cc
index 3e88b42..d6f9742 100644
--- a/filesystem_copier_action_unittest.cc
+++ b/filesystem_copier_action_unittest.cc
@@ -132,8 +132,8 @@
   string a_loop_file;
   string b_loop_file;
 
-  if (!(utils::MakeTempFile("/tmp/a_loop_file.XXXXXX", &a_loop_file, NULL) &&
-        utils::MakeTempFile("/tmp/b_loop_file.XXXXXX", &b_loop_file, NULL))) {
+  if (!(utils::MakeTempFile("a_loop_file.XXXXXX", &a_loop_file, NULL) &&
+        utils::MakeTempFile("b_loop_file.XXXXXX", &b_loop_file, NULL))) {
     ADD_FAILURE();
     return false;
   }
@@ -406,7 +406,7 @@
 
 TEST_F(FilesystemCopierActionTest, RunAsRootDetermineFilesystemSizeTest) {
   string img;
-  EXPECT_TRUE(utils::MakeTempFile("/tmp/img.XXXXXX", &img, NULL));
+  EXPECT_TRUE(utils::MakeTempFile("img.XXXXXX", &img, NULL));
   ScopedPathUnlinker img_unlinker(img);
   CreateExtImageAtPath(img, NULL);
   // Extend the "partition" holding the file system from 10MiB to 20MiB.
diff --git a/filesystem_iterator_unittest.cc b/filesystem_iterator_unittest.cc
index 2ea3728..0a92ec1 100644
--- a/filesystem_iterator_unittest.cc
+++ b/filesystem_iterator_unittest.cc
@@ -59,7 +59,7 @@
   // Create uniqely named main/sub mount points.
   string main_image_mount_point;
   ASSERT_TRUE(utils::MakeTempDirectory(
-          "/tmp/FilesystemIteratorTest.mount-XXXXXX",
+          "FilesystemIteratorTest.mount-XXXXXX",
           &main_image_mount_point));
   ScopedPathUnlinker main_image_mount_point_unlinker(main_image_mount_point);
   const string sub_image_mount_point = main_image_mount_point + "/some_dir/mnt";
diff --git a/full_update_generator_unittest.cc b/full_update_generator_unittest.cc
index 16aa568..c04773e 100644
--- a/full_update_generator_unittest.cc
+++ b/full_update_generator_unittest.cc
@@ -33,14 +33,14 @@
   off_t new_rootfs_size = new_root.size() - 2 * 1024 * 1024;
 
   string new_root_path;
-  EXPECT_TRUE(utils::MakeTempFile("/tmp/NewFullUpdateTest_R.XXXXXX",
+  EXPECT_TRUE(utils::MakeTempFile("NewFullUpdateTest_R.XXXXXX",
                                   &new_root_path,
                                   NULL));
   ScopedPathUnlinker new_root_path_unlinker(new_root_path);
   EXPECT_TRUE(WriteFileVector(new_root_path, new_root));
 
   string new_kern_path;
-  EXPECT_TRUE(utils::MakeTempFile("/tmp/NewFullUpdateTest_K.XXXXXX",
+  EXPECT_TRUE(utils::MakeTempFile("NewFullUpdateTest_K.XXXXXX",
                                   &new_kern_path,
                                   NULL));
   ScopedPathUnlinker new_kern_path_unlinker(new_kern_path);
@@ -48,7 +48,7 @@
 
   string out_blobs_path;
   int out_blobs_fd;
-  EXPECT_TRUE(utils::MakeTempFile("/tmp/NewFullUpdateTest_D.XXXXXX",
+  EXPECT_TRUE(utils::MakeTempFile("NewFullUpdateTest_D.XXXXXX",
                                   &out_blobs_path,
                                   &out_blobs_fd));
   ScopedPathUnlinker out_blobs_path_unlinker(out_blobs_path);
diff --git a/metadata.cc b/metadata.cc
index 1eec1cf..3f96d0f 100644
--- a/metadata.cc
+++ b/metadata.cc
@@ -71,7 +71,7 @@
 bool ComputeMetadataBsdiff(const vector<char>& old_metadata,
                            const vector<char>& new_metadata,
                            vector<char>* bsdiff_delta) {
-  const string kTempFileTemplate("/tmp/CrAU_temp_data.XXXXXX");
+  const string kTempFileTemplate("CrAU_temp_data.XXXXXX");
 
   // Write the metadata buffers to temporary files
   int old_fd;
diff --git a/metadata_unittest.cc b/metadata_unittest.cc
index dc10a6e..096ea9f 100644
--- a/metadata_unittest.cc
+++ b/metadata_unittest.cc
@@ -31,9 +31,9 @@
 
 TEST_F(MetadataTest, RunAsRootReadMetadataDissimilarFileSystems) {
   string a_img, b_img;
-  EXPECT_TRUE(utils::MakeTempFile("/tmp/a_img.XXXXXX", &a_img, NULL));
+  EXPECT_TRUE(utils::MakeTempFile("a_img.XXXXXX", &a_img, NULL));
   ScopedPathUnlinker a_img_unlinker(a_img);
-  EXPECT_TRUE(utils::MakeTempFile("/tmp/b_img.XXXXXX", &b_img, NULL));
+  EXPECT_TRUE(utils::MakeTempFile("b_img.XXXXXX", &b_img, NULL));
   ScopedPathUnlinker b_img_unlinker(b_img);
 
   CreateEmptyExtImageAtPath(a_img, 10485759, 4096);
@@ -65,11 +65,11 @@
 
 TEST_F(MetadataTest, RunAsRootReadMetadata) {
   string a_img, b_img, data_file;
-  EXPECT_TRUE(utils::MakeTempFile("/tmp/a_img.XXXXXX", &a_img, NULL));
+  EXPECT_TRUE(utils::MakeTempFile("a_img.XXXXXX", &a_img, NULL));
   ScopedPathUnlinker a_img_unlinker(a_img);
-  EXPECT_TRUE(utils::MakeTempFile("/tmp/b_img.XXXXXX", &b_img, NULL));
+  EXPECT_TRUE(utils::MakeTempFile("b_img.XXXXXX", &b_img, NULL));
   ScopedPathUnlinker b_img_unlinker(b_img);
-  EXPECT_TRUE(utils::MakeTempFile("/tmp/data_file.XXXXXX", &data_file, NULL));
+  EXPECT_TRUE(utils::MakeTempFile("data_file.XXXXXX", &data_file, NULL));
   ScopedPathUnlinker data_file_unlinker(data_file);
 
   const size_t image_size = (256 * 1024 * 1024);  // Enough for 2 block groups
diff --git a/omaha_hash_calculator_unittest.cc b/omaha_hash_calculator_unittest.cc
index 5147806..1bd1747 100644
--- a/omaha_hash_calculator_unittest.cc
+++ b/omaha_hash_calculator_unittest.cc
@@ -103,7 +103,7 @@
 TEST_F(OmahaHashCalculatorTest, UpdateFileSimpleTest) {
   string data_path;
   ASSERT_TRUE(
-      utils::MakeTempFile("/tmp/data.XXXXXX", &data_path, NULL));
+      utils::MakeTempFile("data.XXXXXX", &data_path, NULL));
   ScopedPathUnlinker data_path_unlinker(data_path);
   ASSERT_TRUE(utils::WriteFile(data_path.c_str(), "hi", 2));
 
@@ -128,7 +128,7 @@
 TEST_F(OmahaHashCalculatorTest, RawHashOfFileSimpleTest) {
   string data_path;
   ASSERT_TRUE(
-      utils::MakeTempFile("/tmp/data.XXXXXX", &data_path, NULL));
+      utils::MakeTempFile("data.XXXXXX", &data_path, NULL));
   ScopedPathUnlinker data_path_unlinker(data_path);
   ASSERT_TRUE(utils::WriteFile(data_path.c_str(), "hi", 2));
 
diff --git a/omaha_request_action_unittest.cc b/omaha_request_action_unittest.cc
index 015f396..97acded 100644
--- a/omaha_request_action_unittest.cc
+++ b/omaha_request_action_unittest.cc
@@ -391,7 +391,7 @@
   params.set_waiting_period(TimeDelta::FromDays(2));
 
   string prefs_dir;
-  EXPECT_TRUE(utils::MakeTempDirectory("/tmp/ue_ut_prefs.XXXXXX",
+  EXPECT_TRUE(utils::MakeTempDirectory("ue_ut_prefs.XXXXXX",
                                        &prefs_dir));
   ScopedDirRemover temp_dir_remover(prefs_dir);
 
@@ -463,7 +463,7 @@
   params.set_max_update_checks_allowed(8);
 
   string prefs_dir;
-  EXPECT_TRUE(utils::MakeTempDirectory("/tmp/ue_ut_prefs.XXXXXX",
+  EXPECT_TRUE(utils::MakeTempDirectory("ue_ut_prefs.XXXXXX",
                                        &prefs_dir));
   ScopedDirRemover temp_dir_remover(prefs_dir);
 
@@ -508,7 +508,7 @@
   params.set_max_update_checks_allowed(8);
 
   string prefs_dir;
-  EXPECT_TRUE(utils::MakeTempDirectory("/tmp/ue_ut_prefs.XXXXXX",
+  EXPECT_TRUE(utils::MakeTempDirectory("ue_ut_prefs.XXXXXX",
                                        &prefs_dir));
   ScopedDirRemover temp_dir_remover(prefs_dir);
 
@@ -554,7 +554,7 @@
   params.set_max_update_checks_allowed(0);
 
   string prefs_dir;
-  EXPECT_TRUE(utils::MakeTempDirectory("/tmp/ue_ut_prefs.XXXXXX",
+  EXPECT_TRUE(utils::MakeTempDirectory("ue_ut_prefs.XXXXXX",
                                        &prefs_dir));
   ScopedDirRemover temp_dir_remover(prefs_dir);
 
@@ -603,7 +603,7 @@
   params.set_max_update_checks_allowed(8);
 
   string prefs_dir;
-  EXPECT_TRUE(utils::MakeTempDirectory("/tmp/ue_ut_prefs.XXXXXX",
+  EXPECT_TRUE(utils::MakeTempDirectory("ue_ut_prefs.XXXXXX",
                                        &prefs_dir));
   ScopedDirRemover temp_dir_remover(prefs_dir);
 
@@ -679,7 +679,7 @@
   params.set_max_update_checks_allowed(8);
 
   string prefs_dir;
-  EXPECT_TRUE(utils::MakeTempDirectory("/tmp/ue_ut_prefs.XXXXXX",
+  EXPECT_TRUE(utils::MakeTempDirectory("ue_ut_prefs.XXXXXX",
                                        &prefs_dir));
   ScopedDirRemover temp_dir_remover(prefs_dir);
 
@@ -1592,7 +1592,7 @@
   params.set_update_check_count_wait_enabled(false);
 
   string prefs_dir;
-  EXPECT_TRUE(utils::MakeTempDirectory("/tmp/ue_ut_prefs.XXXXXX",
+  EXPECT_TRUE(utils::MakeTempDirectory("ue_ut_prefs.XXXXXX",
                                        &prefs_dir));
   ScopedDirRemover temp_dir_remover(prefs_dir);
 
@@ -1665,7 +1665,7 @@
   params.set_update_check_count_wait_enabled(false);
 
   string prefs_dir;
-  EXPECT_TRUE(utils::MakeTempDirectory("/tmp/ue_ut_prefs.XXXXXX",
+  EXPECT_TRUE(utils::MakeTempDirectory("ue_ut_prefs.XXXXXX",
                                        &prefs_dir));
   ScopedDirRemover temp_dir_remover(prefs_dir);
 
diff --git a/omaha_response_handler_action_unittest.cc b/omaha_response_handler_action_unittest.cc
index 41e8c67..9907ce3 100644
--- a/omaha_response_handler_action_unittest.cc
+++ b/omaha_response_handler_action_unittest.cc
@@ -119,7 +119,7 @@
 TEST_F(OmahaResponseHandlerActionTest, SimpleTest) {
   string test_deadline_file;
   CHECK(utils::MakeTempFile(
-          "/tmp/omaha_response_handler_action_unittest-XXXXXX",
+          "omaha_response_handler_action_unittest-XXXXXX",
           &test_deadline_file, NULL));
   ScopedPathUnlinker deadline_unlinker(test_deadline_file);
   {
diff --git a/p2p_manager_unittest.cc b/p2p_manager_unittest.cc
index bee0248..bb34ada 100644
--- a/p2p_manager_unittest.cc
+++ b/p2p_manager_unittest.cc
@@ -55,7 +55,7 @@
 TEST_F(P2PManagerTest, P2PEnabledNeitherCroshFlagNotEnterpriseSetting) {
   string temp_dir;
   Prefs prefs;
-  EXPECT_TRUE(utils::MakeTempDirectory("/tmp/PayloadStateP2PTests.XXXXXX",
+  EXPECT_TRUE(utils::MakeTempDirectory("PayloadStateP2PTests.XXXXXX",
                                        &temp_dir));
   prefs.Init(FilePath(temp_dir));
 
@@ -71,7 +71,7 @@
 TEST_F(P2PManagerTest, P2PEnabledCroshFlag) {
   string temp_dir;
   Prefs prefs;
-  EXPECT_TRUE(utils::MakeTempDirectory("/tmp/PayloadStateP2PTests.XXXXXX",
+  EXPECT_TRUE(utils::MakeTempDirectory("PayloadStateP2PTests.XXXXXX",
                                        &temp_dir));
   prefs.Init(FilePath(temp_dir));
 
@@ -91,7 +91,7 @@
 TEST_F(P2PManagerTest, P2PEnabledEnterpriseSettingTrue) {
   string temp_dir;
   Prefs prefs;
-  EXPECT_TRUE(utils::MakeTempDirectory("/tmp/PayloadStateP2PTests.XXXXXX",
+  EXPECT_TRUE(utils::MakeTempDirectory("PayloadStateP2PTests.XXXXXX",
                                        &temp_dir));
   prefs.Init(FilePath(temp_dir));
 
@@ -117,7 +117,7 @@
 TEST_F(P2PManagerTest, P2PEnabledEnterpriseSettingFalse) {
   string temp_dir;
   Prefs prefs;
-  EXPECT_TRUE(utils::MakeTempDirectory("/tmp/PayloadStateP2PTests.XXXXXX",
+  EXPECT_TRUE(utils::MakeTempDirectory("PayloadStateP2PTests.XXXXXX",
                                        &temp_dir));
   prefs.Init(FilePath(temp_dir));
 
diff --git a/payload_signer.cc b/payload_signer.cc
index 3ed2a49..c962195 100644
--- a/payload_signer.cc
+++ b/payload_signer.cc
@@ -204,12 +204,12 @@
   LOG(INFO) << "Signing hash with private key: " << private_key_path;
   string sig_path;
   TEST_AND_RETURN_FALSE(
-      utils::MakeTempFile("/tmp/signature.XXXXXX", &sig_path, NULL));
+      utils::MakeTempFile("signature.XXXXXX", &sig_path, NULL));
   ScopedPathUnlinker sig_path_unlinker(sig_path);
 
   string hash_path;
   TEST_AND_RETURN_FALSE(
-      utils::MakeTempFile("/tmp/hash.XXXXXX", &hash_path, NULL));
+      utils::MakeTempFile("hash.XXXXXX", &hash_path, NULL));
   ScopedPathUnlinker hash_path_unlinker(hash_path);
   // We expect unpadded SHA256 hash coming in
   TEST_AND_RETURN_FALSE(hash.size() == 32);
@@ -265,7 +265,7 @@
 
   string x_path;
   TEST_AND_RETURN_FALSE(
-      utils::MakeTempFile("/tmp/signed_data.XXXXXX", &x_path, NULL));
+      utils::MakeTempFile("signed_data.XXXXXX", &x_path, NULL));
   ScopedPathUnlinker x_path_unlinker(x_path);
   TEST_AND_RETURN_FALSE(utils::WriteFile(x_path.c_str(), "x", 1));
 
diff --git a/payload_signer_unittest.cc b/payload_signer_unittest.cc
index 972bf2d..086e54a 100644
--- a/payload_signer_unittest.cc
+++ b/payload_signer_unittest.cc
@@ -83,7 +83,7 @@
 void SignSampleData(vector<char>* out_signature_blob) {
   string data_path;
   ASSERT_TRUE(
-      utils::MakeTempFile("/tmp/data.XXXXXX", &data_path, NULL));
+      utils::MakeTempFile("data.XXXXXX", &data_path, NULL));
   ScopedPathUnlinker data_path_unlinker(data_path);
   ASSERT_TRUE(utils::WriteFile(data_path.c_str(),
                                kDataToSign,
diff --git a/payload_state_unittest.cc b/payload_state_unittest.cc
index eb231cb..8029b69 100644
--- a/payload_state_unittest.cc
+++ b/payload_state_unittest.cc
@@ -1069,7 +1069,7 @@
   fake_clock.SetMonotonicTime(Time::FromInternalValue(2000000));
 
   // We need persistent preferences for this test
-  EXPECT_TRUE(utils::MakeTempDirectory("/tmp/PayloadStateDurationTests.XXXXXX",
+  EXPECT_TRUE(utils::MakeTempDirectory("PayloadStateDurationTests.XXXXXX",
                                        &temp_dir));
   prefs.Init(FilePath(temp_dir));
 
@@ -1134,7 +1134,7 @@
 
   // We need persistent preferences for this test
   EXPECT_TRUE(utils::MakeTempDirectory(
-      "/tmp/RebootAfterSuccessfulUpdateTest.XXXXXX", &temp_dir));
+      "RebootAfterSuccessfulUpdateTest.XXXXXX", &temp_dir));
   prefs.Init(FilePath(temp_dir));
 
   mock_system_state.set_clock(&fake_clock);
@@ -1355,7 +1355,7 @@
   string temp_dir;
 
   // Setup an environment with persistent prefs across simulated reboots.
-  EXPECT_TRUE(utils::MakeTempDirectory("/tmp/PayloadStateReboot.XXXXXX",
+  EXPECT_TRUE(utils::MakeTempDirectory("PayloadStateReboot.XXXXXX",
                                        &temp_dir));
   prefs.Init(FilePath(temp_dir));
   mock_system_state.set_prefs(&prefs);
@@ -1405,7 +1405,7 @@
   string temp_dir;
 
   // Setup an environment with persistent prefs across simulated reboots.
-  EXPECT_TRUE(utils::MakeTempDirectory("/tmp/PayloadStateReboot.XXXXXX",
+  EXPECT_TRUE(utils::MakeTempDirectory("PayloadStateReboot.XXXXXX",
                                        &temp_dir));
   prefs.Init(FilePath(temp_dir));
   mock_system_state.set_prefs(&prefs);
@@ -1445,7 +1445,7 @@
   string temp_dir;
 
   // Setup an environment with persistent prefs across simulated reboots.
-  EXPECT_TRUE(utils::MakeTempDirectory("/tmp/PayloadStateReboot.XXXXXX",
+  EXPECT_TRUE(utils::MakeTempDirectory("PayloadStateReboot.XXXXXX",
                                        &temp_dir));
   prefs.Init(FilePath(temp_dir));
   mock_system_state.set_prefs(&prefs);
@@ -1478,7 +1478,7 @@
   string temp_dir;
 
   // Setup an environment with persistent but initially empty prefs.
-  EXPECT_TRUE(utils::MakeTempDirectory("/tmp/PayloadStateReboot.XXXXXX",
+  EXPECT_TRUE(utils::MakeTempDirectory("PayloadStateReboot.XXXXXX",
                                        &temp_dir));
   prefs.Init(FilePath(temp_dir));
   mock_system_state.set_prefs(&prefs);
@@ -1503,7 +1503,7 @@
   string temp_dir;
 
   // We need persistent preferences for this test.
-  EXPECT_TRUE(utils::MakeTempDirectory("/tmp/PayloadStateP2PTests.XXXXXX",
+  EXPECT_TRUE(utils::MakeTempDirectory("PayloadStateP2PTests.XXXXXX",
                                        &temp_dir));
   prefs.Init(FilePath(temp_dir));
 
@@ -1532,7 +1532,7 @@
   string temp_dir;
 
   // We need persistent preferences for this test.
-  EXPECT_TRUE(utils::MakeTempDirectory("/tmp/PayloadStateP2PTests.XXXXXX",
+  EXPECT_TRUE(utils::MakeTempDirectory("PayloadStateP2PTests.XXXXXX",
                                        &temp_dir));
   prefs.Init(FilePath(temp_dir));
 
@@ -1583,7 +1583,7 @@
   Prefs prefs;
   string temp_dir;
 
-  EXPECT_TRUE(utils::MakeTempDirectory("/tmp/PayloadStateP2PTests.XXXXXX",
+  EXPECT_TRUE(utils::MakeTempDirectory("PayloadStateP2PTests.XXXXXX",
                                        &temp_dir));
   prefs.Init(FilePath(temp_dir));
   mock_system_state.set_prefs(&prefs);
@@ -1605,7 +1605,7 @@
   Prefs prefs;
   string temp_dir;
 
-  EXPECT_TRUE(utils::MakeTempDirectory("/tmp/PayloadStateP2PTests.XXXXXX",
+  EXPECT_TRUE(utils::MakeTempDirectory("PayloadStateP2PTests.XXXXXX",
                                        &temp_dir));
   prefs.Init(FilePath(temp_dir));
   mock_system_state.set_clock(&fake_clock);
@@ -1640,7 +1640,7 @@
   Prefs prefs;
   string temp_dir;
 
-  EXPECT_TRUE(utils::MakeTempDirectory("/tmp/PayloadStateP2PTests.XXXXXX",
+  EXPECT_TRUE(utils::MakeTempDirectory("PayloadStateP2PTests.XXXXXX",
                                        &temp_dir));
   prefs.Init(FilePath(temp_dir));
   mock_system_state.set_clock(&fake_clock);
diff --git a/postinstall_runner_action_unittest.cc b/postinstall_runner_action_unittest.cc
index 128610f..e6995e3 100644
--- a/postinstall_runner_action_unittest.cc
+++ b/postinstall_runner_action_unittest.cc
@@ -119,7 +119,7 @@
   // Create a unique named working directory and chdir into it.
   string cwd;
   ASSERT_TRUE(utils::MakeTempDirectory(
-          orig_cwd + "/postinstall_runner_action_unittest-XXXXXX",
+          "postinstall_runner_action_unittest-XXXXXX",
           &cwd));
   ASSERT_EQ(0, Chdir(cwd));
 
diff --git a/test_utils.cc b/test_utils.cc
index d00f432..e73146c 100644
--- a/test_utils.cc
+++ b/test_utils.cc
@@ -28,7 +28,7 @@
 
 namespace chromeos_update_engine {
 
-const char* const kMountPathTemplate = "/tmp/UpdateEngineTests_mnt-XXXXXX";
+const char* const kMountPathTemplate = "UpdateEngineTests_mnt-XXXXXX";
 
 bool WriteFileVector(const std::string& path, const std::vector<char>& data) {
   return utils::WriteFile(path.c_str(), &data[0], data.size());
@@ -300,7 +300,7 @@
 ScopedLoopMounter::ScopedLoopMounter(const string& file_path,
                                      string* mnt_path,
                                      unsigned long flags) {
-  EXPECT_TRUE(utils::MakeTempDirectory("/tmp/mnt.XXXXXX", mnt_path));
+  EXPECT_TRUE(utils::MakeTempDirectory("mnt.XXXXXX", mnt_path));
   dir_remover_.reset(new ScopedDirRemover(*mnt_path));
 
   string loop_dev;
diff --git a/update_attempter_unittest.cc b/update_attempter_unittest.cc
index 0ec41c3..ac01ee3 100644
--- a/update_attempter_unittest.cc
+++ b/update_attempter_unittest.cc
@@ -202,7 +202,7 @@
 TEST_F(UpdateAttempterTest, RunAsRootConstructWithUpdatedMarkerTest) {
   string test_update_completed_marker;
   CHECK(utils::MakeTempFile(
-          "/tmp/update_attempter_unittest-update_completed_marker-XXXXXX",
+          "update_attempter_unittest-update_completed_marker-XXXXXX",
           &test_update_completed_marker, NULL));
   ScopedPathUnlinker completed_marker_unlinker(test_update_completed_marker);
   const FilePath marker(test_update_completed_marker);
@@ -945,7 +945,7 @@
               IsOOBEComplete()).WillRepeatedly(Return(true));
 
   string prefs_dir;
-  EXPECT_TRUE(utils::MakeTempDirectory("/tmp/ue_ut_prefs.XXXXXX",
+  EXPECT_TRUE(utils::MakeTempDirectory("ue_ut_prefs.XXXXXX",
                                        &prefs_dir));
   ScopedDirRemover temp_dir_remover(prefs_dir);
 
@@ -1010,7 +1010,7 @@
               IsOOBEComplete()).WillRepeatedly(Return(true));
 
   string prefs_dir;
-  EXPECT_TRUE(utils::MakeTempDirectory("/tmp/ue_ut_prefs.XXXXXX",
+  EXPECT_TRUE(utils::MakeTempDirectory("ue_ut_prefs.XXXXXX",
                                        &prefs_dir));
   ScopedDirRemover temp_dir_remover(prefs_dir);
 
@@ -1059,7 +1059,7 @@
   string temp_dir;
 
   // We need persistent preferences for this test
-  EXPECT_TRUE(utils::MakeTempDirectory("/tmp/UpdateCheckScheduler.XXXXXX",
+  EXPECT_TRUE(utils::MakeTempDirectory("UpdateCheckScheduler.XXXXXX",
                                        &temp_dir));
   prefs.Init(FilePath(temp_dir));
   mock_system_state_.set_clock(&fake_clock);
diff --git a/utils_unittest.cc b/utils_unittest.cc
index c1f9a2e..c947c0b 100644
--- a/utils_unittest.cc
+++ b/utils_unittest.cc
@@ -182,7 +182,7 @@
 
 TEST(UtilsTest, IsSymlinkTest) {
   string temp_dir;
-  EXPECT_TRUE(utils::MakeTempDirectory("/tmp/symlink-test.XXXXXX", &temp_dir));
+  EXPECT_TRUE(utils::MakeTempDirectory("symlink-test.XXXXXX", &temp_dir));
   string temp_file = temp_dir + "temp-file";
   EXPECT_TRUE(utils::WriteFile(temp_file.c_str(), "", 0));
   string temp_symlink = temp_dir + "temp-symlink";
@@ -275,7 +275,7 @@
 
 TEST(UtilsTest, RunAsRootGetFilesystemSizeTest) {
   string img;
-  EXPECT_TRUE(utils::MakeTempFile("/tmp/img.XXXXXX", &img, NULL));
+  EXPECT_TRUE(utils::MakeTempFile("img.XXXXXX", &img, NULL));
   ScopedPathUnlinker img_unlinker(img);
   CreateExtImageAtPath(img, NULL);
   // Extend the "partition" holding the file system from 10MiB to 20MiB.