server: error handling fixes
authorJens Axboe <axboe@kernel.dk>
Tue, 11 Oct 2011 10:16:32 +0000 (12:16 +0200)
committerJens Axboe <axboe@kernel.dk>
Tue, 11 Oct 2011 10:16:32 +0000 (12:16 +0200)
Signed-off-by: Jens Axboe <axboe@kernel.dk>
fio.c
server.c
server.h

diff --git a/fio.c b/fio.c
index ece897e5fa3bdab4cec8f411f429ded502418312..b242f9445cb872c14c0ec008cba1f257dd4f53f1 100644 (file)
--- a/fio.c
+++ b/fio.c
@@ -165,10 +165,14 @@ void fio_terminate_threads(int group_id)
 static void sig_int(int sig)
 {
        if (threads) {
-               log_info("\nfio: terminating on signal %d\n", sig);
-               exit_backend = 1;
-               fflush(stdout);
-               exit_value = 128;
+               if (is_backend)
+                       fio_server_got_signal(sig);
+               else {
+                       log_info("\nfio: terminating on signal %d\n", sig);
+                       fflush(stdout);
+                       exit_value = 128;
+               }
+
                fio_terminate_threads(TERMINATE_ALL);
        }
 }
index e6c49cc88abfeee02a5aa9163fc89166d43a10fe..db9d8594c8b84c59003cf0d58270bbca197c8fb5 100644 (file)
--- a/server.c
+++ b/server.c
@@ -77,6 +77,8 @@ int fio_send_data(int sk, const void *p, unsigned int len)
                        break;
                else if (errno == EAGAIN || errno == EINTR)
                        continue;
+               else
+                       break;
        } while (!exit_backend);
 
        if (!len)
@@ -100,6 +102,8 @@ int fio_recv_data(int sk, void *p, unsigned int len)
                        break;
                else if (errno == EAGAIN || errno == EINTR)
                        continue;
+               else
+                       break;
        } while (!exit_backend);
 
        if (!len)
@@ -965,25 +969,14 @@ static int fio_server(void)
        return ret;
 }
 
-static void sig_int(int sig)
-{
-       fio_terminate_threads(TERMINATE_ALL);
-       exit_backend = 1;
-}
-
-static void server_signal_handler(void)
+void fio_server_got_signal(int signal)
 {
-       struct sigaction act;
-
-       memset(&act, 0, sizeof(act));
-       act.sa_handler = sig_int;
-       act.sa_flags = SA_RESTART;
-       sigaction(SIGINT, &act, NULL);
-
-       memset(&act, 0, sizeof(act));
-       act.sa_handler = sig_int;
-       act.sa_flags = SA_RESTART;
-       sigaction(SIGTERM, &act, NULL);
+       if (signal == SIGPIPE)
+               server_fd = -1;
+       else {
+               log_info("\nfio: terminating on signal %d\n", signal);
+               exit_backend = 1;
+       }
 }
 
 static int check_existing_pidfile(const char *pidfile)
@@ -1036,8 +1029,6 @@ int fio_start_server(char *pidfile)
        pid_t pid;
        int ret;
 
-       server_signal_handler();
-
        if (!pidfile)
                return fio_server();
 
index cd07a85d627881fd7c379439f98103e20e676e30..49f02a6cd55ddd23c817cf9e382fd8d7e9e8c127 100644 (file)
--- a/server.h
+++ b/server.h
@@ -94,6 +94,7 @@ extern int fio_net_send_simple_cmd(int, uint16_t, uint64_t, struct flist_head *)
 extern void fio_server_set_arg(const char *);
 extern int fio_server_parse_string(const char *, char **, int *, int *, struct in_addr *);
 extern const char *fio_server_op(unsigned int);
+extern void fio_server_got_signal(int);
 
 struct thread_stat;
 struct group_run_stats;