From e77c49f0e80740531405a49494fe5431326a0ba7 Mon Sep 17 00:00:00 2001 From: Sverker Eriksson Date: Tue, 5 Jul 2016 15:34:48 +0200 Subject: run_erl: Beautify #ifdef jungle --- erts/etc/unix/run_erl.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'erts/etc') diff --git a/erts/etc/unix/run_erl.c b/erts/etc/unix/run_erl.c index 30210ac172..d7cfbe675e 100644 --- a/erts/etc/unix/run_erl.c +++ b/erts/etc/unix/run_erl.c @@ -912,12 +912,12 @@ static int open_pty_master(char **ptyslave, int *sfdp) slave device properly. */ #if defined(HAVE_WORKING_POSIX_OPENPT) || (defined(__sun) && defined(__SVR4)) # ifdef HAVE_WORKING_POSIX_OPENPT - if ((mfd = posix_openpt(O_RDWR)) >= 0) { + mfd = posix_openpt(O_RDWR); # elif defined(__sun) && defined(__SVR4) mfd = sf_open("/dev/ptmx", O_RDWR, 0); +# endif if (mfd >= 0) { -# endif if ((*ptyslave = ptsname(mfd)) != NULL && grantpt(mfd) == 0 && unlockpt(mfd) == 0) { -- cgit v1.2.3 From acf0330b0f5b1f4b8fc411cac45f57348b459525 Mon Sep 17 00:00:00 2001 From: Sverker Eriksson Date: Tue, 5 Jul 2016 15:51:23 +0200 Subject: 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? --- erts/etc/unix/run_erl.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'erts/etc') 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); -- cgit v1.2.3 From 7f86a0fedf5a18d82817ceb530aae0f8167c9354 Mon Sep 17 00:00:00 2001 From: Sverker Eriksson Date: Wed, 10 Aug 2016 15:24:30 +0200 Subject: run_erl: Add sleepy_child test case with run_erl option -sleepy-child to provoke race when slave pty is late --- erts/etc/unix/run_erl.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'erts/etc') diff --git a/erts/etc/unix/run_erl.c b/erts/etc/unix/run_erl.c index f8b5da47ab..6a92e18648 100644 --- a/erts/etc/unix/run_erl.c +++ b/erts/etc/unix/run_erl.c @@ -240,6 +240,7 @@ int main(int argc, char **argv) int off_argv; int calculated_pipename = 0; int highest_pipe_num = 0; + int sleepy_child = 0; program_name = argv[0]; @@ -250,6 +251,11 @@ int main(int argc, char **argv) init_outbuf(); + if (!strcmp(argv[1],"-sleepy-child")) { /* For test purpose only */ + sleepy_child = 1; + ++i; + } + if (!strcmp(argv[1],"-daemon")) { daemon_init(); ++i; @@ -392,6 +398,9 @@ int main(int argc, char **argv) exit(1); } if (childpid == 0) { + if (sleepy_child) + sleep(1); + /* Child */ sf_close(mfd); /* disassociate from control terminal */ -- cgit v1.2.3