This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [PATCH 4/7] Introduce linux_pid_to_exec_file
- From: Gary Benson <gbenson at redhat dot com>
- To: Doug Evans <xdje42 at gmail dot com>
- Cc: "gdb-patches at sourceware dot org" <gdb-patches at sourceware dot org>
- Date: Wed, 8 Apr 2015 09:06:21 +0100
- Subject: Re: [PATCH 4/7] Introduce linux_pid_to_exec_file
- Authentication-results: sourceware.org; auth=none
- References: <1427887341-31819-1-git-send-email-gbenson at redhat dot com> <1427887341-31819-5-git-send-email-gbenson at redhat dot com> <m3twwti51n dot fsf at sspiff dot org> <20150407090705 dot GA22271 at blade dot nx> <CAP9bCMS0WhfFumRzgDEGfLfWDsOeJt5jggXGGYcn=Qj8JFmOxw at mail dot gmail dot com>
Doug Evans wrote:
> On Tue, Apr 7, 2015 at 2:07 AM, Gary Benson <gbenson@redhat.com> wrote:
> > Doug Evans wrote:
> > > Gary Benson <gbenson@redhat.com> 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/