summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorthat <github@that.at>2016-01-11 01:07:28 +0100
committerthat <github@that.at>2016-01-11 21:43:00 +0100
commita17f175bd3adb514b0e9e37d836642dbf0225024 (patch)
tree7e873f5b68e75a8366d6964e13005020f8b9a7be
parentgui: add terminal emulator (diff)
downloadandroid_bootable_recovery-a17f175bd3adb514b0e9e37d836642dbf0225024.tar
android_bootable_recovery-a17f175bd3adb514b0e9e37d836642dbf0225024.tar.gz
android_bootable_recovery-a17f175bd3adb514b0e9e37d836642dbf0225024.tar.bz2
android_bootable_recovery-a17f175bd3adb514b0e9e37d836642dbf0225024.tar.lz
android_bootable_recovery-a17f175bd3adb514b0e9e37d836642dbf0225024.tar.xz
android_bootable_recovery-a17f175bd3adb514b0e9e37d836642dbf0225024.tar.zst
android_bootable_recovery-a17f175bd3adb514b0e9e37d836642dbf0225024.zip
-rw-r--r--gui/terminal.cpp31
1 files changed, 21 insertions, 10 deletions
diff --git a/gui/terminal.cpp b/gui/terminal.cpp
index 00424eb90..00b7820a5 100644
--- a/gui/terminal.cpp
+++ b/gui/terminal.cpp
@@ -28,6 +28,7 @@
#include <string>
#include <cctype>
#include <linux/input.h>
+#include <sys/wait.h>
extern "C" {
#include "../twcommon.h"
@@ -124,11 +125,10 @@ public:
int rc = ::read(fdMaster, buffer, size);
debug_printf("pty read: %d bytes\n", rc);
if (rc < 0) {
- LOGINFO("pty read failed: %d\n", errno);
- // assume child has died
- close(fdMaster);
- g_pty_fd = fdMaster = -1;
- pid = 0;
+ // assume child has died (usual errno when shell exits seems to be EIO == 5)
+ if (errno != EIO)
+ LOGERR("pty read failed: %d\n", errno);
+ stop();
}
return rc;
}
@@ -142,11 +142,9 @@ public:
int rc = ::write(fdMaster, buffer, size);
debug_printf("pty write: %d bytes -> %d\n", size, rc);
if (rc < 0) {
- LOGINFO("pty write failed: %d\n", errno);
+ LOGERR("pty write failed: %d\n", errno);
// assume child has died
- close(fdMaster);
- g_pty_fd = fdMaster = -1;
- pid = 0;
+ stop();
}
return rc;
}
@@ -168,9 +166,22 @@ public:
LOGERR("failed to set window size, error %d\n", errno);
}
+ void stop()
+ {
+ if (!started()) {
+ LOGERR("someone tried to stop pty, but it was not started\n");
+ return;
+ }
+ close(fdMaster);
+ g_pty_fd = fdMaster = -1;
+ int status;
+ waitpid(pid, &status, WNOHANG); // avoid zombies but don't hang if the child is still alive and we got here due to some error
+ pid = 0;
+ }
+
private:
int fdMaster;
- int pid;
+ pid_t pid;
};
// UTF-8 decoder