From d4e5ea7c0a9ee20fb7551a6e49c3da32da6c4123 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20Gallou=C3=ABt?= Date: Mon, 24 Jun 2019 11:36:01 +0000 Subject: [PATCH] Abort if fd_set_nonblock() fails MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Adrien Gallouët --- src/bind.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/bind.c b/src/bind.c index 2da5646..e96fbba 100644 --- a/src/bind.c +++ b/src/bind.c @@ -18,13 +18,13 @@ #define O_CLOEXEC 0 #endif -static void +static int fd_set_nonblock(int fd) { - int ret; - if (fd == -1) - return; + return 0; + + int ret; do { ret = fcntl(fd, F_GETFL, 0); @@ -36,8 +36,7 @@ fd_set_nonblock(int fd) ret = fcntl(fd, F_SETFL, flags | O_NONBLOCK); } while (ret == -1 && errno == EINTR); - if (ret == -1) - perror("fcntl O_NONBLOCK"); + return ret; } static int @@ -191,9 +190,12 @@ gt_bind(int argc, char **argv) return 1; } - fd_set_nonblock(tun_fd); - fd_set_nonblock(mud_fd); - fd_set_nonblock(ctl_fd); + if (fd_set_nonblock(tun_fd) || + fd_set_nonblock(mud_fd) || + fd_set_nonblock(ctl_fd)) { + gt_log("couldn't setup non-blocking fds\n"); + return 1; + } const long pid = (long)getpid();