Received: from eggs.gnu.org ([2001:4830:134:3::10]:50480) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XIKzX-0007WU-Be for qemu-devel@nongnu.org; Fri, 15 Aug 2014 13:08:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XIKzS-0000T4-Dl for qemu-devel@nongnu.org; Fri, 15 Aug 2014 13:08:39 -0400 Received: from mx1.redhat.com ([209.132.183.28]:25336) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XIKzS-0000SH-4k for qemu-devel@nongnu.org; Fri, 15 Aug 2014 13:08:34 -0400 From: Stefan Hajnoczi Date: Fri, 15 Aug 2014 18:06:37 +0100 Message-Id: <1408122422-13935-31-git-send-email-stefanha@redhat.com> In-Reply-To: <1408122422-13935-1-git-send-email-stefanha@redhat.com> References: <1408122422-13935-1-git-send-email-stefanha@redhat.com> Subject: [Qemu-devel] [PULL 30/55] qemu-char: using qemu_set_nonblock() instead of fcntl(O_NONBLOCK) List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Peter Maydell , Wangxin , Gonglei , Stefan Hajnoczi From: Gonglei Technically, fcntl(soc, F_SETFL, O_NONBLOCK) is incorrect since it clobbers all other file flags. We can use F_GETFL to get the current flags, set or clear the O_NONBLOCK flag, then use F_SETFL to set the flags. Using the qemu_set_nonblock() wrapper. Signed-off-by: Wangxin Signed-off-by: Gonglei Reviewed-by: Eric Blake Signed-off-by: Stefan Hajnoczi --- qemu-char.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/qemu-char.c b/qemu-char.c index 6964a2d..b1e6a0a 100644 --- a/qemu-char.c +++ b/qemu-char.c @@ -975,7 +975,7 @@ static CharDriverState *qemu_chr_open_fd(int fd_in, int fd_out) s = g_malloc0(sizeof(FDCharDriver)); s->fd_in = io_channel_from_fd(fd_in); s->fd_out = io_channel_from_fd(fd_out); - fcntl(fd_out, F_SETFL, O_NONBLOCK); + qemu_set_nonblock(fd_out); s->chr = chr; chr->opaque = s; chr->chr_add_watch = fd_chr_add_watch; @@ -1062,7 +1062,7 @@ static CharDriverState *qemu_chr_open_stdio(ChardevStdio *opts) } old_fd0_flags = fcntl(0, F_GETFL); tcgetattr (0, &oldtty); - fcntl(0, F_SETFL, O_NONBLOCK); + qemu_set_nonblock(0); atexit(term_exit); chr = qemu_chr_open_fd(0, 1); -- 1.9.3