From 6e8c27a52b67e3474936113f897f309a0091910a Mon Sep 17 00:00:00 2001 From: Ethan Yonker Date: Thu, 22 Dec 2016 17:55:57 -0600 Subject: Support v2 fstab format Auto detect and support both the v1 and v2 fstab formats Support putting TWRP style flags in a separate /etc/twrp.flags file twrp.flags format is the same as twrp.fstab (v1 with TWRP flags) Support using a wildcard in a block device and find all partitions: /usb-otg vfat /dev/block/sda* Support using sysfs entries (voldmanaged) and read uevents and scan for wildcard partitions from uevent data. (twvold?) May not be complete for some of the newer flags found in fstabs in newer build trees and there is a slim chance of a crash if the user removes a removable device while TWRP is performing actions. May need to add some kind of mutex to prevent the 2 threads from causing this crash. We need to start somewhere though and this change is pretty innocuous when not using a v2 fstab. Change-Id: I617d97c7db332cbe671a9d2b8ad98b3d9c4f03cc --- gui/gui.cpp | 46 ++++++++++++++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 16 deletions(-) (limited to 'gui/gui.cpp') diff --git a/gui/gui.cpp b/gui/gui.cpp index a70dadfd2..a270e365f 100644 --- a/gui/gui.cpp +++ b/gui/gui.cpp @@ -33,7 +33,6 @@ #include #include #include -#include extern "C" { @@ -79,6 +78,8 @@ int gGuiRunning = 0; int g_pty_fd = -1; // set by terminal on init void terminal_pty_read(); +int select_fd = 0; + static int gRecorder = -1; extern "C" void gr_write_frame_to_file(int fd); @@ -395,9 +396,18 @@ void InputHandler::handleDrag() } } +void set_select_fd() { + select_fd = ors_read_fd + 1; + if (g_pty_fd >= select_fd) + select_fd = g_pty_fd + 1; + if (PartitionManager.uevent_pfd.fd >= select_fd) + select_fd = PartitionManager.uevent_pfd.fd + 1; +} + static void setup_ors_command() { ors_read_fd = -1; + set_select_fd(); unlink(ORS_INPUT_FILE); if (mkfifo(ORS_INPUT_FILE, 06660) != 0) { @@ -417,6 +427,7 @@ static void setup_ors_command() unlink(ORS_INPUT_FILE); unlink(ORS_OUTPUT_FILE); } + set_select_fd(); } // callback called after a CLI command was executed @@ -448,6 +459,7 @@ static void ors_command_read() if (!orsout) { close(ors_read_fd); ors_read_fd = -1; + set_select_fd(); LOGINFO("Unable to fopen %s\n", ORS_OUTPUT_FILE); unlink(ORS_INPUT_FILE); unlink(ORS_OUTPUT_FILE); @@ -554,29 +566,30 @@ static int runPages(const char *page_name, const int stop_on_page_done) for (;;) { loopTimer(input_timeout_ms); + FD_ZERO(&fdset); + timeout.tv_sec = 0; + timeout.tv_usec = 1; if (g_pty_fd > 0) { - // TODO: this is not nice, we should have one central select for input, pty, and ors - FD_ZERO(&fdset); FD_SET(g_pty_fd, &fdset); - timeout.tv_sec = 0; - timeout.tv_usec = 1; - has_data = select(g_pty_fd+1, &fdset, NULL, NULL, &timeout); - if (has_data > 0) { - terminal_pty_read(); - } + } + if (PartitionManager.uevent_pfd.fd > 0) { + FD_SET(PartitionManager.uevent_pfd.fd, &fdset); } #ifndef TW_OEM_BUILD if (ors_read_fd > 0 && !orsout) { // orsout is non-NULL if a command is still running - FD_ZERO(&fdset); FD_SET(ors_read_fd, &fdset); - timeout.tv_sec = 0; - timeout.tv_usec = 1; - has_data = select(ors_read_fd+1, &fdset, NULL, NULL, &timeout); - if (has_data > 0) { - ors_command_read(); - } } #endif + // TODO: combine this select with the poll done by input handling + has_data = select(select_fd, &fdset, NULL, NULL, &timeout); + if (has_data > 0) { + if (g_pty_fd > 0 && FD_ISSET(g_pty_fd, &fdset)) + terminal_pty_read(); + if (PartitionManager.uevent_pfd.fd > 0 && FD_ISSET(PartitionManager.uevent_pfd.fd, &fdset)) + PartitionManager.read_uevent(); + if (ors_read_fd > 0 && !orsout && FD_ISSET(ors_read_fd, &fdset)) + ors_command_read(); + } if (!gForceRender.get_value()) { @@ -636,6 +649,7 @@ static int runPages(const char *page_name, const int stop_on_page_done) if (ors_read_fd > 0) close(ors_read_fd); ors_read_fd = -1; + set_select_fd(); gGuiRunning = 0; return 0; } -- cgit v1.2.3