From patchwork Wed Sep 30 17:06:17 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Maximets X-Patchwork-Id: 524489 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from archives.nicira.com (unknown [IPv6:2600:3c00::f03c:91ff:fe6e:bdf7]) by ozlabs.org (Postfix) with ESMTP id 571BC140D19 for ; Thu, 1 Oct 2015 03:06:34 +1000 (AEST) Received: from archives.nicira.com (localhost [127.0.0.1]) by archives.nicira.com (Postfix) with ESMTP id 8634722C39C; Wed, 30 Sep 2015 10:06:33 -0700 (PDT) X-Original-To: dev@openvswitch.org Delivered-To: dev@openvswitch.org Received: from mx1e3.cudamail.com (mx1.cudamail.com [69.90.118.67]) by archives.nicira.com (Postfix) with ESMTPS id BDE4F22C39B for ; Wed, 30 Sep 2015 10:06:32 -0700 (PDT) Received: from bar5.cudamail.com (localhost [127.0.0.1]) by mx1e3.cudamail.com (Postfix) with ESMTPS id 2BDCD420333 for ; Wed, 30 Sep 2015 11:06:32 -0600 (MDT) X-ASG-Debug-ID: 1443632789-09eadd31eb20db0001-byXFYA Received: from mx1-pf2.cudamail.com ([192.168.24.2]) by bar5.cudamail.com with ESMTP id Nk1RmWVHGszNaDTs (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Wed, 30 Sep 2015 11:06:29 -0600 (MDT) X-Barracuda-Envelope-From: i.maximets@samsung.com X-Barracuda-RBL-Trusted-Forwarder: 192.168.24.2 Received: from unknown (HELO mailout3.w1.samsung.com) (210.118.77.13) by mx1-pf2.cudamail.com with ESMTPS (DHE-RSA-AES128-SHA encrypted); 30 Sep 2015 17:06:29 -0000 Received-SPF: none (mx1-pf2.cudamail.com: domain at samsung.com does not designate permitted sender hosts) X-Barracuda-Apparent-Source-IP: 210.118.77.13 X-Barracuda-RBL-IP: 210.118.77.13 Received: from eucpsbgm2.samsung.com (unknown [203.254.199.245]) by mailout3.w1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTP id <0NVI00K2H26QBK10@mailout3.w1.samsung.com> for dev@openvswitch.org; Wed, 30 Sep 2015 18:06:26 +0100 (BST) X-AuditID: cbfec7f5-f794b6d000001495-6d-560c16925833 Received: from eusync3.samsung.com ( [203.254.199.213]) by eucpsbgm2.samsung.com (EUCPMTA) with SMTP id 0B.19.05269.2961C065; Wed, 30 Sep 2015 18:06:26 +0100 (BST) Received: from imaximets.rnd.samsung.ru ([106.109.129.180]) by eusync3.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0NVI006AA26LBV80@eusync3.samsung.com>; Wed, 30 Sep 2015 18:06:26 +0100 (BST) X-CudaMail-Envelope-Sender: i.maximets@samsung.com From: Ilya Maximets To: dev@openvswitch.org, Gurucharan Shetty X-CudaMail-MID: CM-E2-929060881 X-CudaMail-DTE: 093015 X-CudaMail-Originating-IP: 210.118.77.13 Date: Wed, 30 Sep 2015 20:06:17 +0300 X-ASG-Orig-Subj: [##CM-E2-929060881##][PATCH] netdev-linux: change fd number if 0 was opened Message-id: <1443632777-20193-1-git-send-email-i.maximets@samsung.com> X-Mailer: git-send-email 2.1.4 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrPJMWRmVeSWpSXmKPExsVy+t/xq7qTxHjCDH78Z7X4fo3N4u9TWYuj p/cwW1xp/8luMXm2lMXrmQ9YHNg8/n3bw+5x4Oh2Fo9nN/8zevRtWcUYwBLFZZOSmpNZllqk b5fAlTFz6xzmgpu8Fdeu32JvYNzF1cXIySEhYCLRsLCHHcIWk7hwbz1bFyMXh5DAUkaJZXv6 WCCcViaJ9udHmEGq2AR0JE6tPsIIYosI2Et8+9nJDlLELLCAUWLxr39gCWGgxKkD+4EaODhY BFQl1u6rAjF5Bdwkzi2VhVgmJ3H++E/mCYzcCxgZVjGKppYmFxQnpeca6RUn5haX5qXrJefn bmKEBMPXHYxLj1kdYhTgYFTi4X0hwB0mxJpYVlyZe4hRgoNZSYR3ET9PmBBvSmJlVWpRfnxR aU5q8SFGaQ4WJXHembvehwgJpCeWpGanphakFsFkmTg4pRoYrUN2av2ZvHXrIk0F7p0PdN0P SbQmRTy11Vh/fkaFsfZ/s4dXzD+mRfTaV96POvV+lg57BKt6+zfhj7Zq6aXSoibPFk+KXnM1 bUeQy2Lh7ZFLhHPZ0gt3PdgTXnbGZmKt9vGTApnPl95o9y54Ok/0iNbif+pztezmsaQoLDd2 ytgVlZMXlbFMiaU4I9FQi7moOBEA5+LxCgICAAA= X-GBUdb-Analysis: 0, 210.118.77.13, Ugly c=0 p=0 Source New X-MessageSniffer-Rules: 0-0-0-5281-c X-Barracuda-Connect: UNKNOWN[192.168.24.2] X-Barracuda-Start-Time: 1443632789 X-Barracuda-Encrypted: DHE-RSA-AES256-SHA X-Barracuda-URL: https://web.cudamail.com:443/cgi-mod/mark.cgi X-Virus-Scanned: by bsmtpd at cudamail.com X-Barracuda-BRTS-Status: 1 X-ASG-Whitelist: EmailCat (corporate) Cc: Ilya Maximets , Dyasly Sergey Subject: [ovs-dev] [PATCH] netdev-linux: change fd number if 0 was opened X-BeenThere: dev@openvswitch.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dev-bounces@openvswitch.org Sender: "dev" Since 18167ffebe54e658579835a2e0acf67ec1d14692 fd = 0 instead of -1 considered as erroneous, because pollfd.fd on Windows does not take negative values. So, we should avoid using it. Reported-by: Nikita Kalyazin Signed-off-by: Ilya Maximets --- lib/netdev-linux.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lib/netdev-linux.c b/lib/netdev-linux.c index 584e804..e1c4e35 100644 --- a/lib/netdev-linux.c +++ b/lib/netdev-linux.c @@ -729,6 +729,20 @@ netdev_linux_alloc(void) } static void +change_fd0(int *fd) +{ + int new_fd; + /* Forbiding to open fd 0 because of windows code restrictions + * inside poll_create_node(), that considers fd 0 erroneous. */ + if (*fd == 0) { + new_fd = dup(*fd); + if (close(*fd) < 0) + VLOG_WARN("closing fd 0 failed: %s", ovs_strerror(error)); + *fd = new_fd; + } +} + +static void netdev_linux_common_construct(struct netdev_linux *netdev) { ovs_mutex_init(&netdev->mutex); @@ -778,6 +792,7 @@ netdev_linux_construct_tap(struct netdev *netdev_) /* Open tap device. */ netdev->tap_fd = open(tap_dev, O_RDWR); + change_fd0(&netdev->tap_fd); if (netdev->tap_fd < 0) { error = errno; VLOG_WARN("opening \"%s\" failed: %s", tap_dev, ovs_strerror(error)); @@ -871,6 +886,7 @@ netdev_linux_rxq_construct(struct netdev_rxq *rxq_) /* Create file descriptor. */ rx->fd = socket(PF_PACKET, SOCK_RAW, 0); + change_fd0(&rx->fd); if (rx->fd < 0) { error = errno; VLOG_ERR("failed to create raw socket (%s)", ovs_strerror(error));