summaryrefslogtreecommitdiff
path: root/switchctl.c
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2014-03-20 21:06:14 (GMT)
committerChristian Pointner <equinox@helsinki.at>2014-03-20 21:06:14 (GMT)
commit16842a01fa7785f240677687a2212ed575b384e2 (patch)
treea1cda7284986a0ec54bd39b88bfeb155c9eac043 /switchctl.c
parent25a74bf11ccd8c90d365038e80e57c9a621569df (diff)
allow type setting only once
Diffstat (limited to 'switchctl.c')
-rw-r--r--switchctl.c38
1 files changed, 22 insertions, 16 deletions
diff --git a/switchctl.c b/switchctl.c
index 7390e0a..37fae8b 100644
--- a/switchctl.c
+++ b/switchctl.c
@@ -88,7 +88,7 @@ void send_usage(int fd)
send_response(fd, "Usage: ");
send_response(fd, " help prints this");
- send_response(fd, " type set client type, one of: master, standby, heartbeat");
+ send_response(fd, " type set client type, one of: master, standby, master_hb, standby_hb");
send_response(fd, " channel switch to channel main or music");
send_response(fd, " client type master and standby only");
send_response(fd, " mode switch to mode master or standby");
@@ -348,24 +348,30 @@ void process_cmd_type(const char* param, int fd, client_t* client_lst)
if(param) {
client_t* client = client_find(client_lst, fd);
if(client) {
- if(!strncmp(param, "master", 6)) {
- client->type = MASTER;
- client->gpi_listener = 1;
- }
- else if(!strncmp(param, "standby", 7)) {
- client->type = STANDBY;
- client->gpi_listener = 1;
+ if(client->type == DEFAULT) {
+ if(!strncmp(param, "master", 6)) {
+ client->type = MASTER;
+ client->gpi_listener = 1;
+ }
+ else if(!strncmp(param, "standby", 7)) {
+ client->type = STANDBY;
+ client->gpi_listener = 1;
+ }
+ else if(!strncmp(param, "master_hb", 9))
+ client->type = MASTER_HB;
+ else if(!strncmp(param, "standby_hb", 10))
+ client->type = STANDBY_HB;
+ else {
+ log_printf(DEBUG, "unkown client type '%s'", param);
+ send_response(fd, "EEE: type: unknown client type");
+ return;
+ }
+ log_printf(DEBUG, "client %d type set to %s", fd, param);
}
- else if(!strncmp(param, "master_hb", 9))
- client->type = MASTER_HB;
- else if(!strncmp(param, "standby_hb", 10))
- client->type = STANDBY_HB;
else {
- log_printf(DEBUG, "unkown client type '%s'", param);
- send_response(fd, "EEE: type: unknown client type");
- return;
+ log_printf(ERROR, "unable to set client type for %d: type already set to %s", fd, client_type_tostring(client->type));
+ send_response(fd, "EEE: type: type already set");
}
- log_printf(DEBUG, "client %d type set to %s", fd, param);
}
else {
log_printf(ERROR, "unable to set client type for %d: client not found", fd);