From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 87840 invoked by alias); 8 Apr 2015 08:06:36 -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 87829 invoked by uid 89); 8 Apr 2015 08:06:36 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.6 required=5.0 tests=AWL,BAYES_00,KAM_LAZY_DOMAIN_SECURITY,SPF_HELO_PASS,T_RP_MATCHES_RCVD autolearn=no 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; Wed, 08 Apr 2015 08:06:26 +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 (8.14.4/8.14.4) with ESMTP id t3886Nn6016290 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 8 Apr 2015 04:06:23 -0400 Received: from blade.nx (ovpn-116-118.ams2.redhat.com [10.36.116.118]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t3886MZ8001941; Wed, 8 Apr 2015 04:06:23 -0400 Received: by blade.nx (Postfix, from userid 1000) id E34F526410C; Wed, 8 Apr 2015 09:06:21 +0100 (BST) Date: Wed, 08 Apr 2015 08:06:00 -0000 From: Gary Benson To: Doug Evans Cc: "gdb-patches@sourceware.org" Subject: Re: [PATCH 4/7] Introduce linux_pid_to_exec_file Message-ID: <20150408080621.GA17016@blade.nx> References: <1427887341-31819-1-git-send-email-gbenson@redhat.com> <1427887341-31819-5-git-send-email-gbenson@redhat.com> <20150407090705.GA22271@blade.nx> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-IsSubscribed: yes X-SW-Source: 2015-04/txt/msg00253.txt.bz2 Doug Evans wrote: > On Tue, Apr 7, 2015 at 2:07 AM, Gary Benson wrote: > > Doug Evans wrote: > > > Gary Benson writes: > > > > +/* See nat/linux-nat.h. */ > > > > + > > > > +char * > > > > +linux_pid_to_exec_file (int pid) > > > > +{ > > > > + static char buf[PATH_MAX]; > > > > + char name[PATH_MAX]; > > > > + > > > > + xsnprintf (name, PATH_MAX, "/proc/%d/exe", pid); > > > > + memset (buf, 0, PATH_MAX); > > > > + if (readlink (name, buf, PATH_MAX - 1) <= 0) > > > > + strcpy (buf, name); > > > > + > > > > + return buf; > > > > +} > > Hi. Another nit. > > Since readlink does not nul-terminate the string, I think it would > be clearer to explicitly nul-terminate the result instead of doing > the initial memset. I realize the current linux-nat.c version > doesn't do this, but we can still improve things here. Ok, I'll do that. > [One might also want the code to protect itself in the case where > the buf is not large enough, but one can leave that for now since > we assume PATH_MAX is big enough throughout.] I don't know how you'd tell, readlink doesn't seem to indicate whether it truncated or not. Cheers, Gary -- http://gbenson.net/