This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [PATCH] PPC sim: Don't close file descriptors 0, 1, or 2
- From: Kevin Buettner <kevinb at redhat dot com>
- To: gdb-patches at sourceware dot org
- Date: Mon, 16 Nov 2015 21:05:33 -0700
- Subject: Re: [PATCH] PPC sim: Don't close file descriptors 0, 1, or 2
- Authentication-results: sourceware.org; auth=none
- References: <20151116145807 dot 4aedd84f at pinnacle dot lan> <20151116235317 dot GF31395 at vapier dot lan>
On Mon, 16 Nov 2015 18:53:17 -0500
Mike Frysinger <vapier@gentoo.org> wrote:
> On 16 Nov 2015 14:58, Kevin Buettner wrote:
> > This occurs because the powerpc simulator closes, on behalf of the
> > testcase, the file descriptors associated with stdin, stdout, and
> > stderr. GDB still needs these descriptors to communicate with the
> > user or, in this case, with the testing framework.
>
> special casing this logic in the sim looks wrong to me. why
> is the testcase itself trying to close stdin/stdout/stderr ?
It's not just one test case, but a bunch of them, 229 to be exact.
I haven't investigated all of them, but in many (if not all) of them,
close() is being called during exit(). This problem arises when
GDB runs the testcase to completion.
sim/common achieves the same result by placing file descriptors 0, 1,
2, and MAX_CALLBACK_FDS together in a circular fd_buddy list. (See
os_init() in sim/common/callback.c.) close() is never called on any of
these descriptors due to the fact that they're in a (circular) list of
greater than one element. When one of these descriptors (0, 1, or 2)
is closed (in os_close()), it is simply removed from the fd_buddy
list, with no close() operation actually being performed. Note that
when the final one is "closed", it is still on an fd_buddy list with
MAX_CALLBACK_FDS - hence it won't be closed either.
So sim/common is doing the same thing as my proposed patch for ppc;
sim/common is just using a more elegant mechanism to avoid calling
close() on these three file descriptors.
Kevin