Skip to content

Commit

Permalink
MDEV-10383 Named pipes : multiple servers can listen on the same pipe…
Browse files Browse the repository at this point in the history
…name

Use FILE_FLAG_FIRST_PIPE_INSTANCE with the first CreateNamedPipe()
call to make sure the pipe does not already exist.
  • Loading branch information
vaintroub committed Aug 2, 2016
1 parent 5fdb3cf commit 6b71a6d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
9 changes: 9 additions & 0 deletions mysql-test/t/named_pipe.test
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,12 @@ connect(pipe_con,localhost,root,,,,,PIPE);

connection default;
disconnect pipe_con;

# MDEV-10383 : check that other server cannot 'bind' on the same pipe
let $MYSQLD_DATADIR= `select @@datadir`;
--error 1
--exec $MYSQLD_CMD --enable-named-pipe --skip-networking --log-error=second-mysqld.err
let SEARCH_FILE=$MYSQLD_DATADIR/second-mysqld.err;
let SEARCH_RANGE= -50;
let SEARCH_PATTERN=\[ERROR\] Create named pipe failed;
source include/search_pattern_in_file.inc;
31 changes: 11 additions & 20 deletions sql/mysqld.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2316,26 +2316,17 @@ static void network_init(void)
saPipeSecurity.lpSecurityDescriptor = &sdPipeDescriptor;
saPipeSecurity.bInheritHandle = FALSE;
if ((hPipe= CreateNamedPipe(pipe_name,
PIPE_ACCESS_DUPLEX|FILE_FLAG_OVERLAPPED,
PIPE_TYPE_BYTE |
PIPE_READMODE_BYTE |
PIPE_WAIT,
PIPE_UNLIMITED_INSTANCES,
(int) global_system_variables.net_buffer_length,
(int) global_system_variables.net_buffer_length,
NMPWAIT_USE_DEFAULT_WAIT,
&saPipeSecurity)) == INVALID_HANDLE_VALUE)
{
LPVOID lpMsgBuf;
int error=GetLastError();
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM,
NULL, error, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR) &lpMsgBuf, 0, NULL );
sql_perror((char *)lpMsgBuf);
LocalFree(lpMsgBuf);
unireg_abort(1);
}
PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED | FILE_FLAG_FIRST_PIPE_INSTANCE,
PIPE_TYPE_BYTE | PIPE_READMODE_BYTE | PIPE_WAIT,
PIPE_UNLIMITED_INSTANCES,
(int) global_system_variables.net_buffer_length,
(int) global_system_variables.net_buffer_length,
NMPWAIT_USE_DEFAULT_WAIT,
&saPipeSecurity)) == INVALID_HANDLE_VALUE)
{
sql_perror("Create named pipe failed");
unireg_abort(1);
}
}
#endif

Expand Down

0 comments on commit 6b71a6d

Please sign in to comment.