summaryrefslogtreecommitdiffstats
path: root/recovery.cpp
diff options
context:
space:
mode:
authorTao Bao <tbao@google.com>2016-01-14 21:19:31 +0100
committerandroid-build-merger <android-build-merger@google.com>2016-01-14 21:19:31 +0100
commitb595e1722c666a6c30820a22f793abf90b905e31 (patch)
tree3fe032bd4983fec105cbd131cbd30f785782bb80 /recovery.cpp
parentMerge "uncrypt: avoid use-after-free" am: 0305fcecc5 (diff)
parentMerge "recovery: Fork a process for fuse when sideloading from SD card." (diff)
downloadandroid_bootable_recovery-b595e1722c666a6c30820a22f793abf90b905e31.tar
android_bootable_recovery-b595e1722c666a6c30820a22f793abf90b905e31.tar.gz
android_bootable_recovery-b595e1722c666a6c30820a22f793abf90b905e31.tar.bz2
android_bootable_recovery-b595e1722c666a6c30820a22f793abf90b905e31.tar.lz
android_bootable_recovery-b595e1722c666a6c30820a22f793abf90b905e31.tar.xz
android_bootable_recovery-b595e1722c666a6c30820a22f793abf90b905e31.tar.zst
android_bootable_recovery-b595e1722c666a6c30820a22f793abf90b905e31.zip
Diffstat (limited to 'recovery.cpp')
-rw-r--r--recovery.cpp61
1 files changed, 57 insertions, 4 deletions
diff --git a/recovery.cpp b/recovery.cpp
index 3b388bc1d..ee2fb43fc 100644
--- a/recovery.cpp
+++ b/recovery.cpp
@@ -28,6 +28,7 @@
#include <sys/klog.h>
#include <sys/stat.h>
#include <sys/types.h>
+#include <sys/wait.h>
#include <time.h>
#include <unistd.h>
@@ -855,6 +856,10 @@ static void choose_recovery_file(Device* device) {
}
}
+// How long (in seconds) we wait for the fuse-provided package file to
+// appear, before timing out.
+#define SDCARD_INSTALL_TIMEOUT 10
+
static int apply_from_sdcard(Device* device, bool* wipe_cache) {
modified_flash = true;
@@ -872,14 +877,62 @@ static int apply_from_sdcard(Device* device, bool* wipe_cache) {
ui->Print("\n-- Install %s ...\n", path);
set_sdcard_update_bootloader_message();
- void* token = start_sdcard_fuse(path);
- int status = install_package(FUSE_SIDELOAD_HOST_PATHNAME, wipe_cache,
+ // We used to use fuse in a thread as opposed to a process. Since accessing
+ // through fuse involves going from kernel to userspace to kernel, it leads
+ // to deadlock when a page fault occurs. (Bug: 26313124)
+ pid_t child;
+ if ((child = fork()) == 0) {
+ bool status = start_sdcard_fuse(path);
+
+ _exit(status ? EXIT_SUCCESS : EXIT_FAILURE);
+ }
+
+ // FUSE_SIDELOAD_HOST_PATHNAME will start to exist once the fuse in child
+ // process is ready.
+ int result = INSTALL_ERROR;
+ int status;
+ bool waited = false;
+ for (int i = 0; i < SDCARD_INSTALL_TIMEOUT; ++i) {
+ if (waitpid(child, &status, WNOHANG) == -1) {
+ result = INSTALL_ERROR;
+ waited = true;
+ break;
+ }
+
+ struct stat sb;
+ if (stat(FUSE_SIDELOAD_HOST_PATHNAME, &sb) == -1) {
+ if (errno == ENOENT && i < SDCARD_INSTALL_TIMEOUT-1) {
+ sleep(1);
+ continue;
+ } else {
+ LOGE("Timed out waiting for the fuse-provided package.\n");
+ result = INSTALL_ERROR;
+ kill(child, SIGKILL);
+ break;
+ }
+ }
+
+ result = install_package(FUSE_SIDELOAD_HOST_PATHNAME, wipe_cache,
TEMPORARY_INSTALL_FILE, false);
+ break;
+ }
+
+ if (!waited) {
+ // Calling stat() on this magic filename signals the fuse
+ // filesystem to shut down.
+ struct stat sb;
+ stat(FUSE_SIDELOAD_HOST_EXIT_PATHNAME, &sb);
+
+ waitpid(child, &status, 0);
+ }
+
+ if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) {
+ LOGE("Error exit from the fuse process: %d\n", WEXITSTATUS(status));
+ }
- finish_sdcard_fuse(token);
ensure_path_unmounted(SDCARD_ROOT);
- return status;
+ return result;
}
// Return REBOOT, SHUTDOWN, or REBOOT_BOOTLOADER. Returning NO_ACTION