From 5ca67789bea6461f6fedb0b9a80a372b8012fdc2 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Wed, 27 May 2009 17:31:42 +0000 Subject: [PATCH] reopening door device after errro --- door_daemon/door_daemon.c | 45 ++++++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/door_daemon/door_daemon.c b/door_daemon/door_daemon.c index 779d085..4288baf 100644 --- a/door_daemon/door_daemon.c +++ b/door_daemon/door_daemon.c @@ -490,41 +490,44 @@ int main(int argc, char* argv[]) fclose(pid_file); } - int door_fd = open(opt.door_dev_, O_RDWR | O_NOCTTY); - if(door_fd < 0) { - log_printf(ERROR, "unable to open %s: %s", opt.door_dev_, strerror(errno)); - options_clear(&opt); - log_close(); - exit(-1); - } - ret = setup_tty(door_fd); - if(ret) { - close(door_fd); - options_clear(&opt); - log_close(); - exit(-1); - } - - int cmd_listen_fd = init_command_socket(opt.command_sock_); if(cmd_listen_fd < 0) { - close(door_fd); options_clear(&opt); log_close(); exit(-1); } + + int door_fd = 0; + for(;;) { + door_fd = open(opt.door_dev_, O_RDWR | O_NOCTTY); + if(door_fd < 0) + ret = 2; + else { + ret = setup_tty(door_fd); + if(ret) + ret = 2; + else + ret = main_loop(door_fd, cmd_listen_fd); + } - ret = main_loop(door_fd, cmd_listen_fd); + if(ret == 2) { + log_printf(ERROR, "%s error, trying to reopen in 5 seconds..", opt.door_dev_); + if(door_fd > 0) + close(door_fd); + sleep(5); + } + else + break; + } close(cmd_listen_fd); - close(door_fd); + if(door_fd > 0) + close(door_fd); if(!ret) log_printf(NOTICE, "normal shutdown"); else if(ret < 0) log_printf(NOTICE, "shutdown after error"); - else if(ret == 2) - log_printf(ERROR, "shutdown after %s read error", opt.door_dev_); else log_printf(NOTICE, "shutdown after signal"); -- 1.7.10.4