Exit with error on signal
[fio.git] / fio.c
diff --git a/fio.c b/fio.c
index 77451db2c37deb4e1c80db8dfa5b8d020e746ae0..284e9f2e867583f963a1388917ec030d63157fce 100644 (file)
--- a/fio.c
+++ b/fio.c
@@ -45,6 +45,7 @@
 #include "cgroup.h"
 #include "profile.h"
 #include "lib/rand.h"
+#include "memalign.h"
 
 unsigned long page_mask;
 unsigned long page_size;
@@ -125,6 +126,7 @@ static void sig_int(int sig)
        if (threads) {
                log_info("\nfio: terminating on signal %d\n", sig);
                fflush(stdout);
+               exit_value = 128;
                terminate_threads(TERMINATE_ALL);
        }
 }
@@ -135,6 +137,8 @@ static void *disk_thread_main(void *data)
 
        while (threads) {
                usleep(DISK_UTIL_MSEC * 1000);
+               if (!threads)
+                       break;
                update_io_ticks();
                print_thread_status();
        }
@@ -144,13 +148,9 @@ static void *disk_thread_main(void *data)
 
 static int create_disk_util_thread(void)
 {
-       pthread_attr_t attr;
        int ret;
 
-       pthread_attr_init(&attr);
-       pthread_attr_setstacksize(&attr, PTHREAD_STACK_MIN);
-       ret = pthread_create(&disk_util_thread, &attr, disk_thread_main, NULL);
-       pthread_attr_destroy(&attr);
+       ret = pthread_create(&disk_util_thread, NULL, disk_thread_main, NULL);
        if (ret) {
                log_err("Can't create disk util thread: %s\n", strerror(ret));
                return 1;
@@ -499,7 +499,6 @@ static void do_verify(struct thread_data *td)
                                clear_io_u(td, io_u);
                        } else if (io_u->resid) {
                                int bytes = io_u->xfer_buflen - io_u->resid;
-                               struct fio_file *f = io_u->file;
 
                                /*
                                 * zero read, fail
@@ -517,6 +516,7 @@ static void do_verify(struct thread_data *td)
                                if (ddir_rw(io_u->ddir))
                                        td->ts.short_io_u[io_u->ddir]++;
 
+                               f = io_u->file;
                                if (io_u->offset == f->real_file_size)
                                        goto sync_done;
 
@@ -798,7 +798,7 @@ static void cleanup_io_u(struct thread_data *td)
                io_u = flist_entry(entry, struct io_u, list);
 
                flist_del(&io_u->list);
-               free(io_u);
+               fio_memfree(io_u, sizeof(*io_u));
        }
 
        free_io_mem(td);
@@ -845,8 +845,9 @@ static int init_io_u(struct thread_data *td)
                if (td->terminate)
                        return 1;
 
-               if (posix_memalign(&ptr, cl_align, sizeof(*io_u))) {
-                       log_err("fio: posix_memalign=%s\n", strerror(errno));
+               ptr = fio_memalign(cl_align, sizeof(*io_u));
+               if (!ptr) {
+                       log_err("fio: unable to allocate aligned memory\n");
                        break;
                }
 
@@ -1499,14 +1500,14 @@ static void run_threads(void)
                        todo--;
                } else {
                        struct fio_file *f;
-                       unsigned int i;
+                       unsigned int j;
 
                        /*
                         * for sharing to work, each job must always open
                         * its own files. so close them, if we opened them
                         * for creation
                         */
-                       for_each_file(td, f, i) {
+                       for_each_file(td, f, j) {
                                if (fio_file_open(f))
                                        td_io_close_file(td, f);
                        }