From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9612 invoked by alias); 17 Sep 2005 22:27:10 -0000 Mailing-List: contact gdb-patches-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sources.redhat.com Received: (qmail 9553 invoked by uid 22791); 17 Sep 2005 22:27:00 -0000 Received: from nevyn.them.org (HELO nevyn.them.org) (66.93.172.17) by sourceware.org (qpsmtpd/0.30-dev) with ESMTP; Sat, 17 Sep 2005 22:27:00 +0000 Received: from drow by nevyn.them.org with local (Exim 4.52) id 1EGl8z-0002tb-E0; Sat, 17 Sep 2005 18:26:49 -0400 Date: Sat, 17 Sep 2005 22:27:00 -0000 From: Daniel Jacobowitz To: Mark Kettenis Cc: qpan@mvista.com, gdb-patches@sources.redhat.com, qunyingpan@gmail.com Subject: Re: Patch: fix gdb_gcore.sh failure in ash/dash Message-ID: <20050917222649.GK8777@nevyn.them.org> Mail-Followup-To: Mark Kettenis , qpan@mvista.com, gdb-patches@sources.redhat.com, qunyingpan@gmail.com References: <432240C1.9000308@mvista.com> <20050917215830.GG8777@nevyn.them.org> <200509172217.j8HMHh3R005674@elgar.sibelius.xs4all.nl> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <200509172217.j8HMHh3R005674@elgar.sibelius.xs4all.nl> User-Agent: Mutt/1.5.8i X-SW-Source: 2005-09/txt/msg00133.txt.bz2 On Sun, Sep 18, 2005 at 12:17:43AM +0200, Mark Kettenis wrote: > > Date: Sat, 17 Sep 2005 17:58:30 -0400 > > From: Daniel Jacobowitz > > > > On Fri, Sep 09, 2005 at 07:11:13PM -0700, Qunying Pan wrote: > > > Hi, > > > > > > Running gdb_gcore.sh in ash/dash fails with message "Hangup detected on > > > fd 0". The following patch fixes the problem. Acceptable? > > > > Let's just use a tempfile. This patch also makes one other change in > > behavior: it uses gdb from $PATH instead of hardcoding /usr/bin, since > > I needed that to test it and it seems more reasonable. > > > > Anyone have comments on this patch? > > I think using a temporary file is a good idea, but if I read your > patch correctly, it seems the temporary file is created in the current > directory, which might not be writable. That's where we default to creating the core file, too. I can easily enough honor -o and create it in that directory instead. > Another problem is that the name is predictable, which is a potential > security risk. Assuming mktemp(1) is available is probably not a good > idea, but it'd be nice to use it if it's avaiable. Seemed excessively complicated when I was first doing this, but might as well. This better? -- Daniel Jacobowitz CodeSourcery, LLC 2005-09-17 Daniel Jacobowitz * gdb_gcore.sh: Use a temporary file. Use gdb from $PATH. Index: gdb_gcore.sh =================================================================== RCS file: /big/fsf/rsync/src/src/gdb/gdb_gcore.sh,v retrieving revision 1.1 diff -u -p -r1.1 gdb_gcore.sh --- gdb_gcore.sh 17 Apr 2003 20:33:09 -0000 1.1 +++ gdb_gcore.sh 17 Sep 2005 22:26:10 -0000 @@ -1,6 +1,6 @@ #!/bin/sh -# Copyright 2003 Free Software Foundation, Inc. +# Copyright 2003, 2005 Free Software Foundation, Inc. # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -16,9 +16,6 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -# Please email any bugs, comments, and/or additions to this file to: -# bug-gdb@prep.ai.mit.edu - # # gcore.sh # Script to generate a core file of a running program. @@ -48,6 +45,17 @@ then shift; shift fi +# Create a temporary file. Use mktemp if available, but cope if it is not. +tmpfile=`mktemp ${name}.XXXXXX 2>/dev/null` || { + tmpfile=${name}.$$ + if test -e $tmpfile; then + echo "Could not create temporary file $tmpfile" + exit 1 + fi + touch $tmpfile +} +trap "rm -f $tmpfile" EXIT + # Initialise return code. rc=0 @@ -55,17 +63,15 @@ rc=0 for pid in $* do # Write gdb script for pid $pid. - - # Avoid need for temporary files by using funky "here - # document" feature of sh. - - /usr/bin/gdb > /dev/null << EOF - attach $pid - gcore $name.$pid - detach - quit + cat >>$tmpfile <