Improve adb sideload - use storage vs tmp
diff --git a/adb_install.cpp b/adb_install.cpp
index f5ba89c..3b64606 100644
--- a/adb_install.cpp
+++ b/adb_install.cpp
@@ -84,7 +84,7 @@
 
     pid_t child;
     if ((child = fork()) == 0) {
-        execl("/sbin/recovery", "recovery", "--adbd", NULL);
+        execl("/sbin/recovery", "recovery", "--adbd", install_file, NULL);
         _exit(-1);
     }
 	DataManager_SetIntValue("tw_child_pid", child);
@@ -102,7 +102,7 @@
     maybe_restart_adbd();
 
     struct stat st;
-    if (stat(ADB_SIDELOAD_FILENAME, &st) != 0) {
+    if (stat(install_file, &st) != 0) {
         if (errno == ENOENT) {
             ui->Print("No package received.\n");
         } else {
@@ -110,17 +110,5 @@
         }
         return INSTALL_ERROR;
     }
-	char zip_file[255];
-	if (strncmp(ADB_SIDELOAD_FILENAME, "/tmp", 4) == 0) {
-		char command[255];
-		sprintf(zip_file, "%s/%s", DataManager_GetCurrentStoragePath(), "sideload.zip");
-		ui->Print("Copying zip to '%s'\n", zip_file);
-		sprintf(command, "cp %s %s", ADB_SIDELOAD_FILENAME, zip_file);
-		system(command);
-		sprintf(command, "rm %s", ADB_SIDELOAD_FILENAME);
-		system(command);
-	} else {
-		strcpy(zip_file, ADB_SIDELOAD_FILENAME);
-	}
-	return TWinstall_zip(zip_file, wipe_cache);
+	return TWinstall_zip(install_file, wipe_cache);
 }
diff --git a/gui/action.cpp b/gui/action.cpp
index 4114bf0..15180ca 100644
--- a/gui/action.cpp
+++ b/gui/action.cpp
@@ -1057,22 +1057,19 @@
 				simulate_progress_bar();
 			} else {
 				int wipe_cache = 0;
-				string Command;
+				string Command, Sideload_File;
 
 				if (!PartitionManager.Mount_Current_Storage(true)) {
 					operation_end(1, simulate);
 					return 0;
 				}
-				if (TWFunc::Path_Exists(ADB_SIDELOAD_FILENAME)) {
-					Command = "rm ";
-					Command += ADB_SIDELOAD_FILENAME;
+				Sideload_File = DataManager::GetCurrentStoragePath() + "/sideload.zip";
+				if (TWFunc::Path_Exists(Sideload_File)) {
+					Command = "rm " + Sideload_File;
 					system(Command.c_str());
 				}
-				Command = "touch ";
-				Command += ADB_SIDELOAD_FILENAME;
-				system(Command.c_str());
 				ui_print("Starting ADB sideload feature...\n");
-				ret = apply_from_adb(ui, &wipe_cache, "/tmp/install_log");
+				ret = apply_from_adb(ui, &wipe_cache, Sideload_File.c_str());
 				if (ret != 0)
 					ret = 1; // failure
 				else if (wipe_cache)
@@ -1084,9 +1081,9 @@
 		if (function == "adbsideloadcancel")
 		{
 			int child_pid;
-			string Command;
-			Command = "rm ";
-			Command += ADB_SIDELOAD_FILENAME;
+			string Command, Sideload_File;
+			Sideload_File = DataManager::GetCurrentStoragePath() + "/sideload.zip";
+			Command = "rm " + Sideload_File;
 			system(Command.c_str());
 			DataManager::GetValue("tw_child_pid", child_pid);
 			ui_print("Cancelling ADB sideload...\n");
diff --git a/minadbd/adb.c b/minadbd/adb.c
index 0e8fd2a..54adba0 100644
--- a/minadbd/adb.c
+++ b/minadbd/adb.c
@@ -40,6 +40,8 @@
 
 static const char *adb_device_banner = "sideload";
 
+char ADB_SIDELOAD_FILENAME[255];
+
 void fatal(const char *fmt, ...)
 {
     va_list ap;
@@ -378,8 +380,9 @@
     usb_cleanup();
 }
 
-int adb_main()
+int adb_main(const char* path)
 {
+	strcpy(ADB_SIDELOAD_FILENAME, path);
     atexit(adb_cleanup);
 #if defined(HAVE_FORKEXEC)
     // No SIGCHLD. Let the service subproc handle its children.
@@ -394,6 +397,7 @@
         usb_init();
     }
 
+/* Remove this so that perms work properly
     if (setgid(AID_SHELL) != 0) {
         fprintf(stderr, "failed to setgid to shell\n");
         exit(1);
@@ -402,8 +406,9 @@
         fprintf(stderr, "failed to setuid to shell\n");
         exit(1);
     }
-    fprintf(stderr, "userid is %d\n", getuid());
 
+    fprintf(stderr, "userid is %d\n", getuid());
+*/
     D("Event loop starting\n");
 
     fdevent_loop();
diff --git a/minadbd/adb.h b/minadbd/adb.h
index 98fa597..19c22e8 100644
--- a/minadbd/adb.h
+++ b/minadbd/adb.h
@@ -217,7 +217,7 @@
 
 void get_my_path(char *s, size_t maxLen);
 int launch_server(int server_port);
-int adb_main();
+int adb_main(const char* path);
 
 
 /* transports are ref-counted
@@ -413,6 +413,7 @@
 int sendfailmsg(int fd, const char *reason);
 int handle_host_request(char *service, transport_type ttype, char* serial, int reply_fd, asocket *s);
 
-#define ADB_SIDELOAD_FILENAME "/tmp/update.zip"
+//#define ADB_SIDELOAD_FILENAME "/tmp/update.zip"
+extern char ADB_SIDELOAD_FILENAME[255];
 
 #endif
diff --git a/recovery.cpp b/recovery.cpp
index b8bb099..2d89014 100644
--- a/recovery.cpp
+++ b/recovery.cpp
@@ -790,8 +790,8 @@
     // anything in the command file or bootloader control block; the
     // only way recovery should be run with this argument is when it
     // starts a copy of itself from the apply_from_adb() function.
-    if (argc == 2 && strcmp(argv[1], "--adbd") == 0) {
-        adb_main();
+    if (argc == 3 && strcmp(argv[1], "--adbd") == 0) {
+        adb_main(argv[2]);
         return 0;
     }