diff options
author | Christian Pointner <equinox@helsinki.at> | 2010-01-13 11:30:51 (GMT) |
---|---|---|
committer | Christian Pointner <equinox@helsinki.at> | 2010-01-13 11:30:51 (GMT) |
commit | 68194820226407465d2ad10dff69954485eb200c (patch) | |
tree | 59f9d7bca3baba6f7979f67915ef80aa430e3fca | |
parent | 8385776d0e7998168f3f0b23a37aececcd5fd3c5 (diff) |
luaclient reconnects now after lost connection
-rw-r--r-- | luaclient.c | 29 | ||||
-rw-r--r-- | mode-watch.lua | 4 |
2 files changed, 20 insertions, 13 deletions
diff --git a/luaclient.c b/luaclient.c index c721138..75a48e9 100644 --- a/luaclient.c +++ b/luaclient.c @@ -231,17 +231,28 @@ int main(int argc, char* argv[]) fclose(pid_file); } - // extern global variable defined in l_cmd.c - cmd_fd = connect_command_socket(opt.command_sock_); - if(cmd_fd < 0) { - options_clear(&opt); - log_close(); - exit(-1); + for(;;) { + // extern global variable defined in l_cmd.c + cmd_fd = connect_command_socket(opt.command_sock_); + if(cmd_fd < 0) + ret = 2; + else { + ret = main_loop(cmd_fd, &opt); + } + + if(ret == 2) { + log_printf(ERROR, "socket error, trying to reconnect in 5 seconds.."); + + if(cmd_fd > 0) + close(cmd_fd); + sleep(5); + } + else + break; } - ret = main_loop(cmd_fd, &opt); - - close(cmd_fd); + if(cmd_fd > 0) + close(cmd_fd); if(!ret) log_printf(NOTICE, "normal shutdown"); diff --git a/mode-watch.lua b/mode-watch.lua index 26ef870..99cc25e 100644 --- a/mode-watch.lua +++ b/mode-watch.lua @@ -104,10 +104,6 @@ function main_loop(opt) else if(input == cmdfd) then return_value = cmd.recv_data(process_cmd) - if(return_value == 2) then - log.printf(log.ERROR, "connection to server lost, exitting") - return_value = -1 - end if(return_value ~= 0) then break end else log.printf(log.ERROR, "select returned invalid handle??") |