From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.fibranet.cat (www.fibranet.cat [88.99.13.26]) by sourceware.org (Postfix) with ESMTPS id E6DD43857735 for ; Thu, 13 Jul 2023 08:07:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E6DD43857735 Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=fibranet.cat Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=fibranet.cat Received: from [192.168.1.11] (133.red-176-83-117.dynamicip.rima-tde.net [176.83.117.133]) (authenticated bits=0) by mail.fibranet.cat (8.15.2/8.15.2) with ESMTPSA id 36D86xBJ1717428 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Thu, 13 Jul 2023 10:07:01 +0200 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.fibranet.cat 36D86xBJ1717428 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fibranet.cat; s=default; t=1689235622; bh=WRkX0vm07/s2EDlRdfbhL68xzT7fXjNU8lBKIBIH7jI=; h=Date:Subject:To:References:From:In-Reply-To:From; b=jO3bWPCYpGg4KKnB7iUhPyIzawQUs/j3RPfTcAnmE3mKPcEONR1e6XoP8nQ+fKjUe CkFc3cFfbqsCJK1YajR8QXwwYJ/PCdUaRfSETkbiSnOAV9fVqVlkWekjQjVrGa3bE7 0F+GZeN2ssc4f/mbFngSLRav+ZbxnMlgzV8h+zp0= Message-ID: Date: Thu, 13 Jul 2023 10:06:58 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.12.0 Subject: Re: [PATCH] Fix getlogin() to check only stdin to get a valid tty Content-Language: en-US To: newlib@sourceware.org References: <1de3b3ee-7dd8-db16-6e17-365dbd9fde84@fibranet.cat> <74633613-8420-5ad6-2882-6ad14066f781@foss.st.com> From: Jordi Sanfeliu Organization: Fibranet NSP, SL In-Reply-To: <74633613-8420-5ad6-2882-6ad14066f781@foss.st.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.6.2 (mail.fibranet.cat [88.99.13.26]); Thu, 13 Jul 2023 10:07:02 +0200 (CEST) X-FibraNet-MailScanner-Information: FibraNet E-Mail Virus Protection Service X-FibraNet-MailScanner-ID: 36D86xBJ1717428 X-FibraNet-MailScanner: Found to be clean X-FibraNet-MailScanner-SpamCheck: X-FibraNet-MailScanner-From: jordi@fibranet.cat X-FibraNet-MailScanner-Watermark: 1689840423.96415@E0dNwOst9mEfBY7MDyl1ag X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,BODY_8BITS,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Hello Torbjörn, Thanks for you reply. It seems to me that this code returns 0 as soon as one of the 3 fds is 0, regardless if the rest are valid tty names. I think that what you meant is this: if ((tty = ttyname (0)) == 0) if ((tty = ttyname (1)) == 0) if ((tty = ttyname (2)) == 0) return 0; which IMO would be even a better patch. What do you think? Best regards. On 7/12/23 20:50, Torbjorn SVENSSON wrote: >> -  if (((tty = ttyname (0)) == 0) >> -      || ((tty = ttyname (1)) == 0) >> -      || ((tty = ttyname (2)) == 0)) > > These 3 lines of code checks if one of stdin, stdout or stderr is > connected to a terminal device. If the return value of ttyname is 0, it > means that there is no terminal device connected to that fd. > As I read the code, it first tries with stdin. If stdin is closed or > redirected, it tries with stdout instead and then lastly, falls back to > trying with stderr. If none of the 3 fd's provides a terminal device, > then the getlogin will return 0. -- Jordi Sanfeliu FIBRANET Network Services Provider https://www.fibranet.cat