From patchwork Thu Jun 8 16:51:20 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Pfaff X-Patchwork-Id: 773387 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3wkBK347vqz9s7f for ; Fri, 9 Jun 2017 02:51:35 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 3F62AC76; Thu, 8 Jun 2017 16:51:33 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id 380BBC6B for ; Thu, 8 Jun 2017 16:51:32 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [217.70.183.196]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 758A0106 for ; Thu, 8 Jun 2017 16:51:31 +0000 (UTC) Received: from mfilter1-d.gandi.net (mfilter1-d.gandi.net [217.70.178.130]) by relay4-d.mail.gandi.net (Postfix) with ESMTP id 2FA011720A1; Thu, 8 Jun 2017 18:51:30 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at mfilter1-d.gandi.net Received: from relay4-d.mail.gandi.net ([IPv6:::ffff:217.70.183.196]) by mfilter1-d.gandi.net (mfilter1-d.gandi.net [::ffff:10.0.15.180]) (amavisd-new, port 10024) with ESMTP id WueodRmVPKOM; Thu, 8 Jun 2017 18:51:28 +0200 (CEST) X-Originating-IP: 173.228.112.24 Received: from ovn.org (173-228-112-24.dsl.dynamic.fusionbroadband.com [173.228.112.24]) (Authenticated sender: blp@ovn.org) by relay4-d.mail.gandi.net (Postfix) with ESMTPSA id A9FCA1720A3; Thu, 8 Jun 2017 18:51:26 +0200 (CEST) Date: Thu, 8 Jun 2017 09:51:20 -0700 From: Ben Pfaff To: Alin Serdean Message-ID: <20170608165120.GQ2820@ovn.org> References: <20170608082828.12224-1-aserdean@cloudbasesolutions.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20170608082828.12224-1-aserdean@cloudbasesolutions.com> User-Agent: Mutt/1.5.23 (2014-03-12) X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, NORMAL_HTTP_TO_IP, RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Cc: "dev@openvswitch.org" Subject: Re: [ovs-dev] [PATCH RFC] ofctl: Fix nonstandard isatty on Windows X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org On Thu, Jun 08, 2017 at 08:28:45AM +0000, Alin Serdean wrote: > A lot of tests are failing, due to the open flow ports being outputted using > names instead of numbers. > i.e.: http://64.119.130.115/ovs/beb75a40fdc295bfd6521b0068b4cd12f6de507c/testsuite.dir/0464/testsuite.log.gz > > The issues encountered above is because 'monitor' with 'detach' arguments are > specified, that in turn will call 'close_standard_fds' > (https://github.com/openvswitch/ovs/blob/master/lib/daemon-unix.c#L472) > which will create a duplicate fd over '/dev/null' on Linux and 'nul' on Windows. > > 'isatty' will be called on those FDs. > What POSIX standard says: > http://pubs.opengroup.org/onlinepubs/009695399/functions/isatty.html > 'The isatty() function shall test whether fildes, an open file descriptor, > is associated with a terminal device.' > What MSDN says: > https://msdn.microsoft.com/en-us/library/f4s0ddew(VS.80).aspx > 'The _isatty function determines whether fd is associated with a character > device (a terminal, console, printer, or serial port).' > > This patch adds another check using 'GetConsoleMode' > https://msdn.microsoft.com/en-us/library/windows/desktop/ms683167(v=vs.85).aspx > which will fail if the handle pointing to the file descriptor is not associated > to a console. > > Signed-off-by: Alin Gabriel Serdean Thanks for finding and fixing the problem. This approach fixes a problem in one place only. I see that there are other calls to isatty() in the tree, so I would prefer to fix them all in one place. How about the following approach instead? I have not tested it. diff --git a/include/windows/unistd.h b/include/windows/unistd.h index 2e9f0aef1647..00ca69762102 100644 --- a/include/windows/unistd.h +++ b/include/windows/unistd.h @@ -85,4 +85,19 @@ __inline long sysconf(int type) return value; } +/* On Windows, a console is a specialized character device, and isatty() only + * reports whether a file description is a character device and thus reports + * that devices such as /dev/null are ttys. This replacement avoids that + * problem. */ +#define isatty(fd) rpl_isatty(fd) +static __inline int +rpl_isatty(int fd) +{ + HANDLE h = (HANDLE) _get_osfhandle(fd); + DWORD st; + return (_isatty(STDOUT_FILENO) + && h != INVALID_HANDLE_VALUE + && GetConsoleMode(h, &st)); +} + #endif /* unistd.h */