Allow threads 60 seconds to exit before being forceful
[fio.git] / libfio.c
index 3fde492c91af727f6d96abf39c308d3ca4b657c7..9245688a029b7771c300df0c923ce680f426e04b 100644 (file)
--- a/libfio.c
+++ b/libfio.c
@@ -27,6 +27,7 @@
 #include <signal.h>
 #include <stdint.h>
 #include <locale.h>
+#include <fcntl.h>
 
 #include "fio.h"
 #include "smalloc.h"
@@ -198,8 +199,13 @@ void fio_terminate_threads(int group_id)
                if (group_id == TERMINATE_ALL || groupid == td->groupid) {
                        dprint(FD_PROCESS, "setting terminate on %s/%d\n",
                                                td->o.name, (int) td->pid);
+
+                       if (td->terminate)
+                               continue;
+
                        td->terminate = 1;
                        td->o.start_delay = 0;
+                       fio_gettime(&td->terminate_time, NULL);
 
                        /*
                         * if the thread is running, just let it exit
@@ -233,6 +239,24 @@ int fio_running_or_pending_io_threads(void)
        return 0;
 }
 
+int fio_set_fd_nonblocking(int fd, const char *who)
+{
+       int flags;
+
+       flags = fcntl(fd, F_GETFL);
+       if (flags < 0)
+               log_err("fio: %s failed to get file flags: %s\n", who, strerror(errno));
+       else {
+               int new_flags = flags | O_NONBLOCK;
+
+               new_flags = fcntl(fd, F_SETFL, new_flags);
+               if (new_flags < 0)
+                       log_err("fio: %s failed to get file flags: %s\n", who, strerror(errno));
+       }
+
+       return flags;
+}
+
 static int endian_check(void)
 {
        union {