aboutsummaryrefslogtreecommitdiffstats
path: root/erts/emulator/sys/unix/sys.c
diff options
context:
space:
mode:
authorLukas Larsson <[email protected]>2013-12-19 14:10:28 +0100
committerLukas Larsson <[email protected]>2014-01-10 18:36:52 +0100
commitb9eb22b7cdb7c52b87848c486214012aabf8cf96 (patch)
treebd863b42d5e38d1c0ece685018aef3cfb8b6628a /erts/emulator/sys/unix/sys.c
parent20641fe0f2ea745873fc7557448d3a7deb1bd639 (diff)
downloadotp-b9eb22b7cdb7c52b87848c486214012aabf8cf96.tar.gz
otp-b9eb22b7cdb7c52b87848c486214012aabf8cf96.tar.bz2
otp-b9eb22b7cdb7c52b87848c486214012aabf8cf96.zip
erts: Make sure fds 0,1 and 2 are open
If they are not open a really nasty race where the io pipe in erl_poll got fd 0 and the fd_driver setting fd 0 to blocking could occur. This caused the emulator to hang during shutdown.
Diffstat (limited to 'erts/emulator/sys/unix/sys.c')
-rw-r--r--erts/emulator/sys/unix/sys.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/erts/emulator/sys/unix/sys.c b/erts/emulator/sys/unix/sys.c
index a7ea4b2490..77d7154313 100644
--- a/erts/emulator/sys/unix/sys.c
+++ b/erts/emulator/sys/unix/sys.c
@@ -547,6 +547,25 @@ erts_sys_pre_init(void)
#endif
#endif /* USE_THREADS */
erts_smp_atomic_init_nob(&sys_misc_mem_sz, 0);
+
+ {
+ /*
+ * Unfortunately we depend on fd 0,1,2 in the old shell code.
+ * So if for some reason we do not have those open when we start
+ * we have to open them here. Not doing this can cause the emulator
+ * to deadlock when reaping the fd_driver ports :(
+ */
+ int fd;
+ /* Make sure fd 0 is open */
+ if ((fd = open("/dev/null", O_RDONLY)) != 0)
+ close(fd);
+ /* Make sure fds 1 and 2 are open */
+ while (fd < 3) {
+ fd = open("/dev/null", O_WRONLY);
+ }
+ close(fd);
+ }
+
}
void