From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 102071 invoked by alias); 28 Jul 2015 23:12:05 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 102062 invoked by uid 89); 28 Jul 2015 23:12:04 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.1 required=5.0 tests=AWL,BAYES_00,KAM_LAZY_DOMAIN_SECURITY,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Tue, 28 Jul 2015 23:12:03 +0000 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (Postfix) with ESMTPS id AE0008E36A; Tue, 28 Jul 2015 23:12:02 +0000 (UTC) Received: from [127.0.0.1] (ovpn01.gateway.prod.ext.ams2.redhat.com [10.39.146.11]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t6SNC0KX025562; Tue, 28 Jul 2015 19:12:01 -0400 Message-ID: <55B80C40.2060901@redhat.com> Date: Tue, 28 Jul 2015 23:12:00 -0000 From: Pedro Alves User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.5.0 MIME-Version: 1.0 To: Sergio Durigan Junior , GDB Patches CC: Eli Zaretskii , Doug Evans Subject: Re: [PATCH] Warn the user when $SHELL is invalid References: <1437761993-18758-1-git-send-email-sergiodj@redhat.com> <1438113495-10985-1-git-send-email-sergiodj@redhat.com> In-Reply-To: <1438113495-10985-1-git-send-email-sergiodj@redhat.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-SW-Source: 2015-07/txt/msg00847.txt.bz2 On 07/28/2015 08:58 PM, Sergio Durigan Junior wrote: > After a lot of discussion (really, I did not know this patch would > draw so much attention), this patch has now been simplified (mostly > because of Doug's suggestions). > > It is known that GDB needs a valid shell to start the inferior and to > offer the "shell" command to the user. This has recently been the > cause of a problem on the MIPS buildslave, because $SHELL was set to > /sbin/nologin and several tests were failing. The thread is here: > > > > In order to improve the error/warning messages emitted in this > scenario, this patch proposes a new check to be performed before > executing the inferior (or before executing a program using the > "shell" command on GDB). This new check tries to determine if the > specified $SHELL is valid or not. The default behavior has not been > changed: if $SHELL is invalid, GDB will still try to execute a program > using it, which will lead to an error eventually. However, now GDB > will also display a message to the user saying that $SHELL is invalid. > This should help when determining what went wrong. > > The check for a valid shell is simple and has been proposed by Doug. > We just fork and then exec a simple command: > > $SHELL -c 'exit 42' > > If the return value is 42, then $SHELL is valid. Otherwise we issue > the warning. It is obviously trivial to create a program that returns > 42 and ignores its arguments, and it it obvious that this program > would be considered a valid shell by GDB, but this should not cause > any problem; the only "drawback" for the user is that she wouldn't get > the warning message before the error. > > OK to apply? As mentioned in the other thread, myself, I'm not convinced of the value of the extra fork/exit complexity for this. IMO, a wider potential bug surface for a not-so-clear benefit. We currently get: $ SHELL=/nonexisting gdb /home/pedro/a.out (gdb) r Starting program: /home/pedro/a.out Cannot exec /nonexisting -c exec /home/pedro/a.out . Error: No such file or directory During startup program exited with code 127. (gdb) If we're starting with a shell, then if the exec fails, it was obviously because execing the shell failed. I'd suggest simply trying to make the error message clearer. E.g.,: $ SHELL=/nonexisting gdb /home/pedro/a.out (gdb) r Starting program: /home/pedro/a.out "set startup-with-shell" is on, but failed to exec: /nonexisting -c exec /home/pedro/a.out Error: No such file or directory If set, the SHELL environment variable must point at a valid shell. SHELL is currently set to "/nonexisting". During startup program exited with code 127. (gdb) Thanks, Pedro Alves