From 081afb84df011547579f3a10a24b2c51db9d6591 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Mon, 27 Jul 2015 02:52:54 +0200 Subject: make connected client type exclusive 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"); -- cgit v0.10.2