Skip to content
/ server Public
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion sql/mysqld.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2779,7 +2779,35 @@ static void network_init(void)
else
#endif
{
(void) unlink(mysqld_unix_port);
struct stat statbuf;
if (stat(mysqld_unix_port, &statbuf) == 0)
{
/* Socket file exists - check if another server is using it */
if (S_ISSOCK(statbuf.st_mode))
{
int test_fd= socket(AF_UNIX, SOCK_STREAM, 0);
if (test_fd >= 0)
{
struct sockaddr_un test_addr;
bzero((char*) &test_addr, sizeof(test_addr));
test_addr.sun_family= AF_UNIX;
strmov(test_addr.sun_path, mysqld_unix_port);
if (connect(test_fd, (struct sockaddr *) &test_addr,
sizeof(test_addr)) == 0)
{
/* Socket is active - another server is listening */
close(test_fd);
sql_print_error("Another server process is already "
"using the socket file '%s'. "
"Aborting.", mysqld_unix_port);
unireg_abort(1);
}
close(test_fd);
}
}
/* Socket file is stale or not a socket - safe to remove */
(void) unlink(mysqld_unix_port);
}
port_len= sizeof(UNIXaddr);
}
arg= 1;
Expand Down
Loading