From 5f1db4952f74da1777b038fc65ed7c8ab275a079 Mon Sep 17 00:00:00 2001 From: Vincent-FK Date: Tue, 7 Jan 2020 18:46:45 +0100 Subject: [PATCH] check exec return code for USB mounting Signed-off-by: Vincent-FK --- RetroFE/Source/Menu/MenuMode.cpp | 11 ++++++++++- RetroFE/Source/Utility/Utils.cpp | 23 +++++++++++++++++++++++ RetroFE/Source/Utility/Utils.h | 2 ++ 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/RetroFE/Source/Menu/MenuMode.cpp b/RetroFE/Source/Menu/MenuMode.cpp index 3fde294..7187523 100644 --- a/RetroFE/Source/Menu/MenuMode.cpp +++ b/RetroFE/Source/Menu/MenuMode.cpp @@ -1,4 +1,5 @@ #include "MenuMode.h" +#include "../Utility/Utils.h" #include #include "../SDL.h" @@ -882,10 +883,18 @@ void MenuMode::launch( ) menu_screen_refresh(menuItem, prevItem, scroll, menu_confirmation, 1); /// ----- Shell cmd ---- - fp = popen(usb_mounted?SHELL_CMD_USB_UNMOUNT:SHELL_CMD_USB_MOUNT, "r"); + /*fp = popen(usb_mounted?SHELL_CMD_USB_UNMOUNT:SHELL_CMD_USB_MOUNT, "r"); if (fp == NULL) { MENU_ERROR_PRINTF("Failed to run command %s\n", shell_cmd); } + else{ + usb_mounted = !usb_mounted; + }*/ + + bool res = Utils::executeRawPath(usb_mounted?SHELL_CMD_USB_UNMOUNT:SHELL_CMD_USB_MOUNT); + if (!res) { + MENU_ERROR_PRINTF("Failed to run command %s\n", shell_cmd); + } else{ usb_mounted = !usb_mounted; } diff --git a/RetroFE/Source/Utility/Utils.cpp b/RetroFE/Source/Utility/Utils.cpp index fb0ad1a..f0840dd 100644 --- a/RetroFE/Source/Utility/Utils.cpp +++ b/RetroFE/Source/Utility/Utils.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -267,6 +268,28 @@ std::string Utils::trimEnds(std::string str) return str; } +bool Utils::executeRawPath(const char *shellCmd) +{ + bool retVal = false; + + Logger::write(Logger::ZONE_INFO, "Utils", "Attempting to launch: " + std::string(shellCmd)); + + std::string executionString = "exec " + std::string(shellCmd); + printf("Running: %s\n", executionString.c_str()); + if(system(executionString.c_str()) != 0) + { + Logger::write(Logger::ZONE_ERROR, "Utils", "Failed to run: " + std::string(shellCmd)); + } + else + { + retVal = true; + } + + Logger::write(Logger::ZONE_INFO, "Utils", "Completed"); + + return retVal; +} + int Utils::termfix(uint32_t ttyId){ // Init tty file path char ttyFilePath[100]; diff --git a/RetroFE/Source/Utility/Utils.h b/RetroFE/Source/Utility/Utils.h index 040f7e4..9f7d620 100644 --- a/RetroFE/Source/Utility/Utils.h +++ b/RetroFE/Source/Utility/Utils.h @@ -44,6 +44,8 @@ public: static std::string combinePath(std::string path1, std::string path2, std::string path3, std::string path4); static std::string combinePath(std::string path1, std::string path2, std::string path3, std::string path4, std::string path5); + static bool executeRawPath(const char *shellCmd); + static int termfix(uint32_t ttyId); static int getVTid();