summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2015-07-27 00:52:54 (GMT)
committerChristian Pointner <equinox@helsinki.at>2015-07-27 00:52:54 (GMT)
commit081afb84df011547579f3a10a24b2c51db9d6591 (patch)
treed04c8fc7cf205a13807fa104a6a81078f5bcd9c4
parent1482b0d47432a94dba02a76a399abda3dd633969 (diff)
make connected client type exclusive
-rw-r--r--src/switchctl.c40
1 files changed, 38 insertions, 2 deletions
diff --git a/src/switchctl.c b/src/switchctl.c
index a06912a..5366a00 100644
--- a/src/switchctl.c
+++ b/src/switchctl.c
@@ -530,22 +530,58 @@ int update_health_status(int fd, cmd_t **cmd_q, client_t* client_lst, options_t*
void process_cmd_type(const char* param, int fd, cmd_t **cmd_q, client_t* client_lst, options_t* opt)
{
+ bool mc, sc, hmc, hsc;
+ mc = sc = hmc = hsc = 0;
+
+ client_t* client;
+ for(client = client_lst; client; client = client->next) {
+ switch(client->type) {
+ case MASTER: mc=1; break;
+ case STANDBY: sc=1; break;
+ case HB_MASTER: hmc=1; break;
+ case HB_STANDBY: hsc=1; break;
+ default: break;
+ }
+ }
+
if(param) {
client_t* client = client_find(client_lst, fd);
if(client) {
if(client->type == DEFAULT) {
if(!strncmp(param, "master", 6)) {
+ if(mc) {
+ log_printf(DEBUG, "client of type '%s' already connected", param);
+ send_response(fd, "EEE: type: already connected");
+ return;
+ }
client->type = MASTER;
client->gpi_listener = 1;
}
else if(!strncmp(param, "standby", 7)) {
+ if(sc) {
+ log_printf(DEBUG, "client of type '%s' already connected", param);
+ send_response(fd, "EEE: type: already connected");
+ return;
+ }
client->type = STANDBY;
client->gpi_listener = 1;
}
- else if(!strncmp(param, "hb_master", 9))
+ else if(!strncmp(param, "hb_master", 9)) {
+ if(hmc) {
+ log_printf(DEBUG, "client of type '%s' already connected", param);
+ send_response(fd, "EEE: type: already connected");
+ return;
+ }
client->type = HB_MASTER;
- else if(!strncmp(param, "hb_standby", 10))
+ }
+ else if(!strncmp(param, "hb_standby", 10)) {
+ if(hsc) {
+ log_printf(DEBUG, "client of type '%s' already connected", param);
+ send_response(fd, "EEE: type: already connected");
+ return;
+ }
client->type = HB_STANDBY;
+ }
else {
log_printf(DEBUG, "unkown client type '%s'", param);
send_response(fd, "EEE: type: unknown client type");