summaryrefslogtreecommitdiffstats
path: root/twrp-functions.cpp
diff options
context:
space:
mode:
authorEthan Yonker <dees_troy@teamw.in>2017-01-19 21:01:57 +0100
committerEthan Yonker <dees_troy@teamw.in>2017-03-01 22:56:47 +0100
commitddb63e27f2cdba7ab3757abdc12a34cc02095345 (patch)
treebec2a6f8f18ee1f77ad568c8da76cc419b5ff7ca /twrp-functions.cpp
parentgui: preserve order of gui_print vs gui_msg (diff)
downloadandroid_bootable_recovery-ddb63e27f2cdba7ab3757abdc12a34cc02095345.tar
android_bootable_recovery-ddb63e27f2cdba7ab3757abdc12a34cc02095345.tar.gz
android_bootable_recovery-ddb63e27f2cdba7ab3757abdc12a34cc02095345.tar.bz2
android_bootable_recovery-ddb63e27f2cdba7ab3757abdc12a34cc02095345.tar.lz
android_bootable_recovery-ddb63e27f2cdba7ab3757abdc12a34cc02095345.tar.xz
android_bootable_recovery-ddb63e27f2cdba7ab3757abdc12a34cc02095345.tar.zst
android_bootable_recovery-ddb63e27f2cdba7ab3757abdc12a34cc02095345.zip
Diffstat (limited to 'twrp-functions.cpp')
-rw-r--r--twrp-functions.cpp35
1 files changed, 35 insertions, 0 deletions
diff --git a/twrp-functions.cpp b/twrp-functions.cpp
index 3c6c55bce..c9643570f 100644
--- a/twrp-functions.cpp
+++ b/twrp-functions.cpp
@@ -142,6 +142,41 @@ int TWFunc::Wait_For_Child(pid_t pid, int *status, string Child_Name) {
return 0;
}
+int TWFunc::Wait_For_Child_Timeout(pid_t pid, int *status, const string& Child_Name, int timeout) {
+ pid_t retpid = waitpid(pid, status, WNOHANG);
+ for (; retpid == 0 && timeout; --timeout) {
+ sleep(1);
+ retpid = waitpid(pid, status, WNOHANG);
+ }
+ if (retpid == 0 && timeout == 0) {
+ LOGERR("%s took too long, killing process\n", Child_Name.c_str());
+ kill(pid, SIGKILL);
+ int died = 0;
+ for (timeout = 5; retpid == 0 && timeout; --timeout) {
+ sleep(1);
+ retpid = waitpid(pid, status, WNOHANG);
+ }
+ if (retpid)
+ LOGINFO("Child process killed successfully\n");
+ else
+ LOGINFO("Child process took too long to kill, may be a zombie process\n");
+ return -1;
+ } else if (retpid > 0) {
+ if (WIFSIGNALED(*status)) {
+ gui_msg(Msg(msg::kError, "pid_signal={1} process ended with signal: {2}")(Child_Name)(WTERMSIG(*status))); // Seg fault or some other non-graceful termination
+ return -1;
+ }
+ } else if (retpid < 0) { // no PID returned
+ if (errno == ECHILD)
+ LOGERR("%s no child process exist\n", Child_Name.c_str());
+ else {
+ LOGERR("%s Unexpected error %d\n", Child_Name.c_str(), errno);
+ return -1;
+ }
+ }
+ return 0;
+}
+
bool TWFunc::Path_Exists(string Path) {
// Check to see if the Path exists
struct stat st;