From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from esa2.mentor.iphmx.com (esa2.mentor.iphmx.com [68.232.141.98]) by sourceware.org (Postfix) with ESMTPS id 68ED13857C42 for ; Wed, 19 Aug 2020 16:28:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 68ED13857C42 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=joseph_myers@mentor.com IronPort-SDR: uhFSu5ssYqzKLG9wt3bg7y+aynSU8PkORFjAeoZ4W7tfa5jrQjZSCvasawJFpxqHAqd1ynhJNH GoGEp/aidYU4lFXfhBXezRHD71GE5tbmNM3LMzN8qo9fbxWMY5QqJmL87AMi3ETmxLxih9rdxB 6Oj9Cu9Kz2P3sLeUXk5wADSjqeP2aNfS9vtb7GXHaaIlXMII7YasTUudnbi7uMr66MFcV261TP adzTU52loonULso2cYXib7a60Aj1dOR2E96mJgNVFpb5q7XJKCxBleRjf1zUCK+d1ybqh7qXvI Bvc= X-IronPort-AV: E=Sophos;i="5.76,332,1592899200"; d="scan'208";a="52090126" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa2.mentor.iphmx.com with ESMTP; 19 Aug 2020 08:28:31 -0800 IronPort-SDR: PBj6OcgFyo5/einMZGRfDq83whJdxzvnlrXadbNJW+Jk0QyKfeVnOyRdq8sBag4BZptRP/5XXd nZ9ueHH+k4SepjyuJtJqAw2QKgcaYzjHUS2RZXx3mHU6OhKgbwuPXd9LufVpe4YW4Qd/yBcCJ0 SYw9ikdNQGcufL+UtFRH5vK+2UXPxVb6YFW3gHwyNoaAXn8yviM0Lja5kbIErRp/U06aR/Hm/4 UDCncLvRoF5cmZdZxIrCe4CYtelvLV70ZdgGe6IaTRpfewBrUG8NjNdkuWl9HEm8EEeb59DWhm cQk= Date: Wed, 19 Aug 2020 16:28:25 +0000 From: Joseph Myers X-X-Sender: jsm28@digraph.polyomino.org.uk To: =?ISO-8859-2?Q?Arsen_Arsenovi=E6?= CC: Subject: Re: [PATCH v2] Ensure standard file descriptors are open on start In-Reply-To: <20200819124124.17481-1-arsen@aarsen.me> Message-ID: References: <20200819124124.17481-1-arsen@aarsen.me> User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: SVR-IES-MBX-03.mgc.mentorg.com (139.181.222.3) To SVR-IES-MBX-03.mgc.mentorg.com (139.181.222.3) X-Spam-Status: No, score=-3127.9 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=no autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org Content-Type: text/plain; charset="ISO-8859-2" Content-Transfer-Encoding: 8BIT X-Content-Filtered-By: Mailman/MimeDel 2.1.29 X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 19 Aug 2020 16:28:33 -0000 On Wed, 19 Aug 2020, Arsen Arsenoviæ via Libc-alpha wrote: > ISO C requires that standard input, output and error are always open on > program startup. ISO C doesn't talk about file descriptors at all. The objects stdin, stdout and stderr need to be initialized, but it's fine for all I/O on them to fail. > + /* Ensure the standard streams are opened, as required by POSIX and C. For > + dynamic programs this is already handled in the dynamic loader. */ Please give specific references, not just "as required by POSIX and C". What exactly do you think requires these descriptors to be open? The POSIX specification for execve explicitly says "If file descriptor 0, 1, or 2 would otherwise be closed after a successful call to one of the exec family of functions, implementations may open an unspecified file for the file descriptor in the new process image. If a standard utility or a conforming application is executed with file descriptor 0 not open for reading or with file descriptor 1 or 2 not open for writing, the environment in which the utility or application is executed shall be deemed non-conforming, and consequently the utility or application might not behave as described in this standard.". So at least that description of the process of creating a new process image only permits opening those file descriptors but does not require it and indeed explicitly does not impose requirements on how code behaves if started with those file descriptors not open. https://pubs.opengroup.org/onlinepubs/9699919799/functions/execve.html -- Joseph S. Myers joseph@codesourcery.com