From patchwork Mon Aug 11 09:34:20 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gonglei (Arei)" X-Patchwork-Id: 378929 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 2124B14013B for ; Mon, 11 Aug 2014 19:37:52 +1000 (EST) Received: from localhost ([::1]:34700 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XGm34-0003wX-B0 for incoming@patchwork.ozlabs.org; Mon, 11 Aug 2014 05:37:50 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57420) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XGm0b-0000DL-UO for qemu-devel@nongnu.org; Mon, 11 Aug 2014 05:35:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XGm0T-0003wK-Uj for qemu-devel@nongnu.org; Mon, 11 Aug 2014 05:35:17 -0400 Received: from szxga02-in.huawei.com ([119.145.14.65]:39959) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XGm0T-0003uf-5a for qemu-devel@nongnu.org; Mon, 11 Aug 2014 05:35:09 -0400 Received: from 172.24.2.119 (EHLO szxeml423-hub.china.huawei.com) ([172.24.2.119]) by szxrg02-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id BXY75108; Mon, 11 Aug 2014 17:34:54 +0800 (CST) Received: from localhost (10.177.19.102) by szxeml423-hub.china.huawei.com (10.82.67.162) with Microsoft SMTP Server id 14.3.158.1; Mon, 11 Aug 2014 17:34:46 +0800 From: To: Date: Mon, 11 Aug 2014 17:34:20 +0800 Message-ID: <1407749661-11640-2-git-send-email-arei.gonglei@huawei.com> X-Mailer: git-send-email 1.7.3.1.msysgit.0 In-Reply-To: <1407749661-11640-1-git-send-email-arei.gonglei@huawei.com> References: <1407749661-11640-1-git-send-email-arei.gonglei@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.177.19.102] X-CFilter-Loop: Reflected X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 119.145.14.65 Cc: weidong.huang@huawei.com, mst@redhat.com, wangxinxin.wang@huawei.com, peter.huangpeng@huawei.com, Gonglei , kraxel@redhat.com, stefanha@redhat.com, pbonzini@redhat.com Subject: [Qemu-devel] [PATCH 1/2] qemu-char: using qemu_set_nonblock() instead of fcntl(O_NONBLOCK) X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 --- 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);