server: error handling fixes
Signed-off-by: Jens Axboe <axboe@kernel.dk>
diff --git a/fio.c b/fio.c
index ece897e..b242f94 100644
--- a/fio.c
+++ b/fio.c
@@ -165,10 +165,14 @@
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);
}
}
diff --git a/server.c b/server.c
index e6c49cc..db9d859 100644
--- a/server.c
+++ b/server.c
@@ -77,6 +77,8 @@
break;
else if (errno == EAGAIN || errno == EINTR)
continue;
+ else
+ break;
} while (!exit_backend);
if (!len)
@@ -100,6 +102,8 @@
break;
else if (errno == EAGAIN || errno == EINTR)
continue;
+ else
+ break;
} while (!exit_backend);
if (!len)
@@ -965,25 +969,14 @@
return ret;
}
-static void sig_int(int sig)
+void fio_server_got_signal(int signal)
{
- fio_terminate_threads(TERMINATE_ALL);
- exit_backend = 1;
-}
-
-static void server_signal_handler(void)
-{
- 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 @@
pid_t pid;
int ret;
- server_signal_handler();
-
if (!pidfile)
return fio_server();
diff --git a/server.h b/server.h
index cd07a85..49f02a6 100644
--- a/server.h
+++ b/server.h
@@ -94,6 +94,7 @@
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;