summaryrefslogtreecommitdiff
path: root/erts/emulator/sys/unix/erl_child_setup.c
diff options
context:
space:
mode:
Diffstat (limited to 'erts/emulator/sys/unix/erl_child_setup.c')
-rw-r--r--erts/emulator/sys/unix/erl_child_setup.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/erts/emulator/sys/unix/erl_child_setup.c b/erts/emulator/sys/unix/erl_child_setup.c
index 0a2ac9abf7..ae269292e5 100644
--- a/erts/emulator/sys/unix/erl_child_setup.c
+++ b/erts/emulator/sys/unix/erl_child_setup.c
@@ -58,6 +58,7 @@
#include <sys/wait.h>
#include <sys/types.h>
#include <sys/socket.h>
+#include <termios.h>
#define WANT_NONBLOCKING
@@ -432,6 +433,17 @@ static int system_properties_fd(void)
}
#endif /* __ANDROID__ */
+/*
+ If beam is terminated using kill -9 or Ctrl-C when +B is set it may not
+ cleanup the terminal properly. So to clean it up we save the initial state in
+ erl_child_setup and then reset the terminal if we detect that beam terminated.
+
+ Not all shells and OSs have this issue, but we do it on all unixes anyway as
+ it is hard for us to know where the bug exists or not and there is no hard in
+ doing it.
+ */
+static struct termios initial_tty_mode;
+
int
main(int argc, char *argv[])
{
@@ -447,6 +459,10 @@ main(int argc, char *argv[])
ABORT("Invalid arguments to child_setup");
}
+ if (isatty(0)) {
+ tcgetattr(0,&initial_tty_mode);
+ }
+
/* We close all fds except the uds from beam.
All other fds from now on will have the
CLOEXEC flags set on them. This means that we
@@ -541,12 +557,18 @@ main(int argc, char *argv[])
pipes, 3, MSG_DONTWAIT)) < 0) {
if (errno == EINTR)
continue;
+ if (isatty(0)) {
+ tcsetattr(0,TCSANOW,&initial_tty_mode);
+ }
DEBUG_PRINT("erl_child_setup failed to read from uds: %d, %d", res, errno);
_exit(0);
}
if (res == 0) {
DEBUG_PRINT("uds was closed!");
+ if (isatty(0)) {
+ tcsetattr(0,TCSANOW,&initial_tty_mode);
+ }
_exit(0);
}
/* Since we use unix domain sockets and send the entire data in