Error check fcntl() calls
Add a helper to mark an fd as non-blocking, so we can check
and complain in one place.
Signed-off-by: Jens Axboe <axboe@fb.com>
diff --git a/libfio.c b/libfio.c
index 3fde492..5ed8c60 100644
--- 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"
@@ -233,6 +234,21 @@
return 0;
}
+void 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 {
+ flags |= O_NONBLOCK;
+ flags = fcntl(fd, F_SETFL, flags);
+ if (flags < 0)
+ log_err("fio: %s failed to get file flags: %s\n", who, strerror(errno));
+ }
+}
+
static int endian_check(void)
{
union {