summaryrefslogtreecommitdiff
path: root/switchctl.c
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2010-01-10 16:17:47 (GMT)
committerChristian Pointner <equinox@helsinki.at>2010-01-10 16:17:47 (GMT)
commit5b5a0e9950fa7e191a67cacabe55f1780fed5b5e (patch)
treeae4bd9ee0fc2635741fe6bed54824d01bb9a5030 /switchctl.c
parent475ead22df9433e3a7f41fa88190984a10f86144 (diff)
new listener type: mode
switched to version 1.0 RC1 cleanups
Diffstat (limited to 'switchctl.c')
-rw-r--r--switchctl.c27
1 files changed, 23 insertions, 4 deletions
diff --git a/switchctl.c b/switchctl.c
index 6d5c42c..9b704bb 100644
--- a/switchctl.c
+++ b/switchctl.c
@@ -340,7 +340,7 @@ void process_cmd_type(const char* param, int fd, client_t* client_lst)
}
}
-int process_cmd_mode(const char* param, int fd, cmd_t **cmd_q, options_t* opt)
+int process_cmd_mode(const char* param, int fd, cmd_t **cmd_q, options_t* opt, client_t* client_lst)
{
mode_t old_mode = opt->mode_;
@@ -402,8 +402,23 @@ int process_cmd_mode(const char* param, int fd, cmd_t **cmd_q, options_t* opt)
send_response(fd, "EEE: mode: missing parameter");
}
- if(old_mode != opt->mode_)
- log_printf(NOTICE, "new mode: %s", opt->mode_ == MODE_MASTER ? "master" : "standby");
+ if(old_mode != opt->mode_) {
+ char* mode_str;
+ asprintf(&mode_str, "new Mode: %s", opt->mode_ == MODE_MASTER ? "master" : "standby");
+ if(mode_str) {
+ log_printf(NOTICE, "%s", mode_str);
+ client_t* client;
+ int listener_cnt = 0;
+ for(client = client_lst; client; client = client->next)
+ if(client->mode_listener && client->fd != fd) {
+ send_response(client->fd, mode_str);
+ listener_cnt++;
+ }
+ free(mode_str);
+ log_printf(DEBUG, "sent new mode to %d additional listeners", listener_cnt);
+ }
+
+ }
return 0;
}
@@ -414,6 +429,7 @@ void process_cmd_listen(const char* param, int fd, client_t* client_lst)
if(listener) {
if(!param) {
listener->request_listener = 1;
+ listener->mode_listener = 1;
listener->status_listener = 1;
listener->gpi_listener = 1;
listener->oc_listener = 1;
@@ -423,6 +439,8 @@ void process_cmd_listen(const char* param, int fd, client_t* client_lst)
else {
if(!strncmp(param, "request", 7))
listener->request_listener = 1;
+ else if(!strncmp(param, "mode", 6))
+ listener->mode_listener = 1;
else if(!strncmp(param, "status", 6))
listener->status_listener = 1;
else if(!strncmp(param, "gpi", 3))
@@ -435,6 +453,7 @@ void process_cmd_listen(const char* param, int fd, client_t* client_lst)
listener->silence_listener = 1;
else if(!strncmp(param, "none", 4)) {
listener->request_listener = 0;
+ listener->mode_listener = 0;
listener->status_listener = 0;
listener->gpi_listener = 0;
listener->oc_listener = 0;
@@ -522,7 +541,7 @@ int process_cmd(const char* cmd, int fd, cmd_t **cmd_q, client_t* client_lst, op
}
case TYPE: process_cmd_type(param, fd, client_lst); break;
case MODE: {
- int ret = process_cmd_mode(param, fd, cmd_q, opt);
+ int ret = process_cmd_mode(param, fd, cmd_q, opt, client_lst);
if(ret)
return ret;
break;