From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15560 invoked by alias); 8 Apr 2015 03:15:34 -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 15540 invoked by uid 89); 8 Apr 2015 03:15:33 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.0 required=5.0 tests=AWL,BAYES_00,FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-qk0-f171.google.com Received: from mail-qk0-f171.google.com (HELO mail-qk0-f171.google.com) (209.85.220.171) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Wed, 08 Apr 2015 03:15:32 +0000 Received: by qkhg7 with SMTP id g7so69842673qkh.2 for ; Tue, 07 Apr 2015 20:15:30 -0700 (PDT) MIME-Version: 1.0 X-Received: by 10.140.165.198 with SMTP id l189mr28613782qhl.93.1428462930872; Tue, 07 Apr 2015 20:15:30 -0700 (PDT) Received: by 10.229.119.10 with HTTP; Tue, 7 Apr 2015 20:15:30 -0700 (PDT) In-Reply-To: <20150407090705.GA22271@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> Date: Wed, 08 Apr 2015 03:15:00 -0000 Message-ID: Subject: Re: [PATCH 4/7] Introduce linux_pid_to_exec_file From: Doug Evans To: Gary Benson Cc: "gdb-patches@sourceware.org" Content-Type: text/plain; charset=UTF-8 X-IsSubscribed: yes X-SW-Source: 2015-04/txt/msg00249.txt.bz2 On Tue, Apr 7, 2015 at 2:07 AM, Gary Benson wrote: > Doug Evans wrote: >> Gary Benson writes: >> > diff --git a/gdb/nat/linux-nat.c b/gdb/nat/linux-nat.c >> > new file mode 100644 >> > index 0000000..b9deae3 >> > --- /dev/null >> > +++ b/gdb/nat/linux-nat.c >> > @@ -0,0 +1,37 @@ > ... >> > +/* 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. [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.]