Remove comment wrt sigaction() usage, it's deprecated
[fio.git] / fio.c
diff --git a/fio.c b/fio.c
index 7a420daf909afb84009792d63d2b146d85ce520d..f0566ed77f75f71b33634c3ba2cac7dbe4aa23eb 100644 (file)
--- a/fio.c
+++ b/fio.c
@@ -107,36 +107,39 @@ static void status_timer_arm(void)
        setitimer(ITIMER_REAL, &itimer, NULL);
 }
 
-/*
- * We need to rearm on BSD/solaris. Switch this to sigaction in the future...
- */
-static void set_sig_handlers(void (*sighandler)(int))
-{
-       signal(SIGINT, sighandler);
-       signal(SIGALRM, sighandler);
-}
-
-static void sig_handler(int sig)
+static void sig_alrm(int sig)
 {
-       set_sig_handlers(sig_handler);
-
-       if (!threads)
-               return;
-
-       switch (sig) {
-       case SIGALRM:
+       if (threads) {
                update_io_ticks();
                print_thread_status();
                status_timer_arm();
-               break;
-       default:
+       }
+}
+
+static void sig_int(int sig)
+{
+       if (threads) {
                printf("\nfio: terminating on signal %d\n", sig);
                fflush(stdout);
                terminate_threads(TERMINATE_ALL);
-               break;
        }
 }
 
+static void set_sig_handlers(void)
+{
+       struct sigaction act;
+
+       memset(&act, 0, sizeof(act));
+       act.sa_handler = sig_alrm;
+       act.sa_flags = SA_RESTART;
+       sigaction(SIGALRM, &act, NULL);
+
+       memset(&act, 0, sizeof(act));
+       act.sa_handler = sig_int;
+       act.sa_flags = SA_RESTART;
+       sigaction(SIGINT, &act, NULL);
+}
+
 /*
  * Check if we are above the minimum rate given.
  */
@@ -237,7 +240,7 @@ static inline int runtime_exceeded(struct thread_data *td, struct timeval *t)
  */
 static void cleanup_pending_aio(struct thread_data *td)
 {
-       struct list_head *entry, *n;
+       struct flist_head *entry, *n;
        struct io_u *io_u;
        int r;
 
@@ -252,8 +255,8 @@ static void cleanup_pending_aio(struct thread_data *td)
         * now cancel remaining active events
         */
        if (td->io_ops->cancel) {
-               list_for_each_safe(entry, n, &td->io_u_busylist) {
-                       io_u = list_entry(entry, struct io_u, list);
+               flist_for_each_safe(entry, n, &td->io_u_busylist) {
+                       io_u = flist_entry(entry, struct io_u, list);
 
                        /*
                         * if the io_u isn't in flight, then that generally
@@ -389,7 +392,7 @@ static void do_verify(struct thread_data *td)
                                 * zero read, fail
                                 */
                                if (!bytes) {
-                                       td_verror(td, ENODATA, "full resid");
+                                       td_verror(td, EIO, "full resid");
                                        put_io_u(td, io_u);
                                        break;
                                }
@@ -517,7 +520,7 @@ static void do_io(struct thread_data *td)
                                 * zero read, fail
                                 */
                                if (!bytes) {
-                                       td_verror(td, ENODATA, "full resid");
+                                       td_verror(td, EIO, "full resid");
                                        put_io_u(td, io_u);
                                        break;
                                }
@@ -594,7 +597,7 @@ sync_done:
                if (check_min_rate(td, &comp_time)) {
                        if (exitall_on_terminate)
                                terminate_threads(td->groupid);
-                       td_verror(td, ENODATA, "check_min_rate");
+                       td_verror(td, EIO, "check_min_rate");
                        break;
                }
 
@@ -647,13 +650,13 @@ sync_done:
 
 static void cleanup_io_u(struct thread_data *td)
 {
-       struct list_head *entry, *n;
+       struct flist_head *entry, *n;
        struct io_u *io_u;
 
-       list_for_each_safe(entry, n, &td->io_u_freelist) {
-               io_u = list_entry(entry, struct io_u, list);
+       flist_for_each_safe(entry, n, &td->io_u_freelist) {
+               io_u = flist_entry(entry, struct io_u, list);
 
-               list_del(&io_u->list);
+               flist_del(&io_u->list);
                free(io_u);
        }
 
@@ -697,7 +700,7 @@ static int init_io_u(struct thread_data *td)
                        return 1;
                io_u = malloc(sizeof(*io_u));
                memset(io_u, 0, sizeof(*io_u));
-               INIT_LIST_HEAD(&io_u->list);
+               INIT_FLIST_HEAD(&io_u->list);
 
                if (!(td->io_ops->flags & FIO_NOIO)) {
                        io_u->buf = p + max_bs * i;
@@ -708,7 +711,7 @@ static int init_io_u(struct thread_data *td)
 
                io_u->index = i;
                io_u->flags = IO_U_F_FREE;
-               list_add(&io_u->list, &td->io_u_freelist);
+               flist_add(&io_u->list, &td->io_u_freelist);
        }
 
        io_u_init_timeout();
@@ -844,11 +847,11 @@ static void *thread_main(void *data)
 
        dprint(FD_PROCESS, "jobs pid=%d started\n", (int) td->pid);
 
-       INIT_LIST_HEAD(&td->io_u_freelist);
-       INIT_LIST_HEAD(&td->io_u_busylist);
-       INIT_LIST_HEAD(&td->io_u_requeues);
-       INIT_LIST_HEAD(&td->io_log_list);
-       INIT_LIST_HEAD(&td->io_hist_list);
+       INIT_FLIST_HEAD(&td->io_u_freelist);
+       INIT_FLIST_HEAD(&td->io_u_busylist);
+       INIT_FLIST_HEAD(&td->io_u_requeues);
+       INIT_FLIST_HEAD(&td->io_log_list);
+       INIT_FLIST_HEAD(&td->io_hist_list);
        td->io_hist_tree = RB_ROOT;
 
        td_set_runstate(td, TD_INITIALIZED);
@@ -1156,7 +1159,7 @@ static void run_threads(void)
                fflush(stdout);
        }
 
-       set_sig_handlers(sig_handler);
+       set_sig_handlers();
 
        todo = thread_number;
        nr_running = 0;