aboutsummaryrefslogtreecommitdiffstats
path: root/erts
diff options
context:
space:
mode:
authorPatrik Nyblom <[email protected]>2011-04-05 15:48:15 +0200
committerPatrik Nyblom <[email protected]>2011-04-05 15:48:15 +0200
commit645d19ca2e96ec53b4b4834b312cfa869084d107 (patch)
tree4c7becd336cf8ad8c5b84fb2dc954ad695704a20 /erts
parent091e3b7ac5915aba478e4ef98d0123a1dce05bc3 (diff)
parent663d618e854f88ac032cf802d15d6abcff89dd78 (diff)
downloadotp-645d19ca2e96ec53b4b4834b312cfa869084d107.tar.gz
otp-645d19ca2e96ec53b4b4834b312cfa869084d107.tar.bz2
otp-645d19ca2e96ec53b4b4834b312cfa869084d107.zip
Merge branch 'pan/run_erl_race_creating_fifo/OTP-9164' into dev
* pan/run_erl_race_creating_fifo/OTP-9164: Fix race in pipe creation. Two simultaneous node starts caused failure
Diffstat (limited to 'erts')
-rw-r--r--erts/etc/unix/run_erl.c59
1 files changed, 35 insertions, 24 deletions
diff --git a/erts/etc/unix/run_erl.c b/erts/etc/unix/run_erl.c
index cadff12c6f..e97cc14fab 100644
--- a/erts/etc/unix/run_erl.c
+++ b/erts/etc/unix/run_erl.c
@@ -1,7 +1,7 @@
/*
* %CopyrightBegin%
*
- * Copyright Ericsson AB 1996-2010. All Rights Reserved.
+ * Copyright Ericsson AB 1996-2011. All Rights Reserved.
*
* The contents of this file are subject to the Erlang Public License,
* Version 1.1, (the "License"); you may not use this file except in
@@ -221,6 +221,8 @@ int main(int argc, char **argv)
char *p, *ptyslave=NULL;
int i = 1;
int off_argv;
+ int calculated_pipename = 0;
+ int highest_pipe_num = 0;
program_name = argv[0];
@@ -298,10 +300,10 @@ int main(int argc, char **argv)
if(*pipename && pipename[strlen(pipename)-1] == '/') {
/* The user wishes us to find a unique pipe name in the specified */
/* directory */
- int highest_pipe_num = 0;
DIR *dirp;
struct dirent *direntp;
+ calculated_pipename = 1;
dirp = opendir(pipename);
if(!dirp) {
ERRNO_ERR1(LOG_ERR,"Can't access pipe directory '%s'.", pipename);
@@ -322,28 +324,37 @@ int main(int argc, char **argv)
PIPE_STUBNAME, highest_pipe_num+1);
} /* if */
- /* write FIFO - is read FIFO for `to_erl' program */
- strn_cpy(fifo1, sizeof(fifo1), pipename);
- strn_cat(fifo1, sizeof(fifo1), ".r");
- if (create_fifo(fifo1, PERM) < 0) {
- ERRNO_ERR1(LOG_ERR,"Cannot create FIFO %s for writing.", fifo1);
- exit(1);
- }
-
- /* read FIFO - is write FIFO for `to_erl' program */
- strn_cpy(fifo2, sizeof(fifo2), pipename);
- strn_cat(fifo2, sizeof(fifo2), ".w");
-
- /* Check that nobody is running run_erl already */
- if ((fd = open (fifo2, O_WRONLY|DONT_BLOCK_PLEASE, 0)) >= 0) {
- /* Open as client succeeded -- run_erl is already running! */
- fprintf(stderr, "Erlang already running on pipe %s.\n", pipename);
- close(fd);
- exit(1);
- }
- if (create_fifo(fifo2, PERM) < 0) {
- ERRNO_ERR1(LOG_ERR,"Cannot create FIFO %s for reading.", fifo2);
- exit(1);
+ for(;;) {
+ /* write FIFO - is read FIFO for `to_erl' program */
+ strn_cpy(fifo1, sizeof(fifo1), pipename);
+ strn_cat(fifo1, sizeof(fifo1), ".r");
+ if (create_fifo(fifo1, PERM) < 0) {
+ ERRNO_ERR1(LOG_ERR,"Cannot create FIFO %s for writing.", fifo1);
+ exit(1);
+ }
+
+ /* read FIFO - is write FIFO for `to_erl' program */
+ strn_cpy(fifo2, sizeof(fifo2), pipename);
+ strn_cat(fifo2, sizeof(fifo2), ".w");
+
+ /* Check that nobody is running run_erl already */
+ if ((fd = open (fifo2, O_WRONLY|DONT_BLOCK_PLEASE, 0)) >= 0) {
+ /* Open as client succeeded -- run_erl is already running! */
+ close(fd);
+ if (calculated_pipename) {
+ ++highest_pipe_num;
+ strn_catf(pipename, sizeof(pipename), "%s.%d",
+ PIPE_STUBNAME, highest_pipe_num+1);
+ continue;
+ }
+ fprintf(stderr, "Erlang already running on pipe %s.\n", pipename);
+ exit(1);
+ }
+ if (create_fifo(fifo2, PERM) < 0) {
+ ERRNO_ERR1(LOG_ERR,"Cannot create FIFO %s for reading.", fifo2);
+ exit(1);
+ }
+ break;
}
/*