Make update_engine use /data/misc/update_engine/cache as tmpdir

update_engine doesn't have access to android's default tmpdir,
/data/local/tmp . So use /data/misc/update_engine/cache/

Test: th
Bug: 320443894
Change-Id: Ibbbe8019c276fe0fa3f9ea197815ed6daac912fc
diff --git a/main.cc b/main.cc
index 103e1a1..ac2f5bc 100644
--- a/main.cc
+++ b/main.cc
@@ -14,6 +14,7 @@
 // limitations under the License.
 //
 
+#include <stdlib.h>
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <xz.h>
@@ -27,6 +28,7 @@
 #include "update_engine/common/logging.h"
 #include "update_engine/common/subprocess.h"
 #include "update_engine/common/terminator.h"
+#include "update_engine/common/utils.h"
 
 using std::string;
 DEFINE_bool(logtofile, false, "Write logs to a file in log_dir.");
@@ -48,6 +50,14 @@
   bool log_to_system = FLAGS_logtostderr;
   bool log_to_file = FLAGS_logtofile || !FLAGS_logtostderr;
   chromeos_update_engine::SetupLogging(log_to_system, log_to_file);
+  base::FilePath tmpdir;
+  if (chromeos_update_engine::GetTempName("", &tmpdir)) {
+    LOG(INFO) << "Using temp dir " << tmpdir;
+    setenv("TMPDIR", tmpdir.value().c_str(), true);
+  } else {
+    PLOG(ERROR) << "Failed to create temporary directory, puffdiff will run "
+                   "w/o on disk cache, updates might take longer.";
+  }
   if (!FLAGS_foreground)
     PLOG_IF(FATAL, daemon(0, 0) == 1) << "daemon() failed";