Handle server repurposing under a lock

By moving the repurposing of the servers under the global server lock, the
repurposing of a server and allocation of a new server behave in the same
way.

Also fixed the wrong error message on server creation failure referring to
invalid server relationships.
This commit is contained in:
Markus Mäkelä
2017-08-04 11:24:54 +03:00
parent e133e758a6
commit 1743f4c1b7
3 changed files with 36 additions and 34 deletions

View File

@ -139,7 +139,6 @@ SERVER* server_alloc(const char *name, const char *address, unsigned short port,
server->monuser[0] = '\0';
server->monpw[0] = '\0';
server->is_active = true;
server->created_online = false;
server->charset = SERVER_DEFAULT_CHARSET;
server->proxy_protocol = false;
@ -1281,8 +1280,9 @@ bool server_serialize(const SERVER *server)
return rval;
}
SERVER* server_find_destroyed(const char *name, const char *protocol,
const char *authenticator, const char *auth_options)
SERVER* server_repurpose_destroyed(const char *name, const char *protocol,
const char *authenticator, const char *auth_options,
const char *address, const char *port)
{
spinlock_acquire(&server_spin);
SERVER *server = allServers;
@ -1297,6 +1297,9 @@ SERVER* server_find_destroyed(const char *name, const char *protocol,
(auth_options && server->auth_options &&
strcmp(server->auth_options, auth_options) == 0))
{
snprintf(server->name, sizeof(server->name), "%s", address);
server->port = atoi(port);
server->is_active = true;
break;
}
}