aboutsummaryrefslogtreecommitdiffstats
path: root/erts
diff options
context:
space:
mode:
authorSverker Eriksson <[email protected]>2016-07-05 15:51:23 +0200
committerSverker Eriksson <[email protected]>2016-07-05 15:51:23 +0200
commitacf0330b0f5b1f4b8fc411cac45f57348b459525 (patch)
treeaa70293e76996fad8f2c74a194dac731f61b1e4f /erts
parente77c49f0e80740531405a49494fe5431326a0ba7 (diff)
downloadotp-acf0330b0f5b1f4b8fc411cac45f57348b459525.tar.gz
otp-acf0330b0f5b1f4b8fc411cac45f57348b459525.tar.bz2
otp-acf0330b0f5b1f4b8fc411cac45f57348b459525.zip
run_erl: Fix failing run_erl invokation on OpenBSD
Symptom: run_erl does exit(0) and child program (erl) does not seem to start. Running run_erl again however brings the previous child program to life. Problem: A race causing run_erl to read 0 from master pty and exit because the child has not yet opened its corresponding slave pty. Solution: Use the non standard openpty() function instead that does not expose this race as the slave fd is opened in the parent. Question: Is there a race free way to do this with posix_openpt on OpenBSD?
Diffstat (limited to 'erts')
-rw-r--r--erts/etc/unix/run_erl.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/erts/etc/unix/run_erl.c b/erts/etc/unix/run_erl.c
index d7cfbe675e..f8b5da47ab 100644
--- a/erts/etc/unix/run_erl.c
+++ b/erts/etc/unix/run_erl.c
@@ -904,14 +904,26 @@ static int create_fifo(char *name, int perm)
* Find a master device, open and return fd and slave device name.
*/
+#ifdef HAVE_WORKING_POSIX_OPENPT
+ /*
+ * Use openpty() on OpenBSD even if we have posix_openpt()
+ * as there is a race when read from master pty returns 0
+ * if child has not yet opened slave pty.
+ * (maybe other BSD's have the same problem?)
+ */
+# if !(defined(__OpenBSD__) && defined(HAVE_OPENPTY))
+# define TRY_POSIX_OPENPT
+# endif
+#endif
+
static int open_pty_master(char **ptyslave, int *sfdp)
{
int mfd;
/* Use the posix_openpt if working, as this guarantees creation of the
slave device properly. */
-#if defined(HAVE_WORKING_POSIX_OPENPT) || (defined(__sun) && defined(__SVR4))
-# ifdef HAVE_WORKING_POSIX_OPENPT
+#if defined(TRY_POSIX_OPENPT) || (defined(__sun) && defined(__SVR4))
+# ifdef TRY_POSIX_OPENPT
mfd = posix_openpt(O_RDWR);
# elif defined(__sun) && defined(__SVR4)
mfd = sf_open("/dev/ptmx", O_RDWR, 0);