diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/switchctl.c | 40 |
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"); |