This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [PATCH 7/7] Implement vFile:setfs in gdbserver
- From: Gary Benson <gbenson at redhat dot com>
- To: Pedro Alves <palves at redhat dot com>
- Cc: gdb-patches at sourceware dot org
- Date: Fri, 17 Apr 2015 17:29:45 +0100
- Subject: Re: [PATCH 7/7] Implement vFile:setfs in gdbserver
- Authentication-results: sourceware.org; auth=none
- References: <1429186791-6867-1-git-send-email-gbenson at redhat dot com> <1429186791-6867-8-git-send-email-gbenson at redhat dot com> <553126FA dot 8030402 at redhat dot com> <20150417160524 dot GC14618 at blade dot nx>
Gary Benson wrote:
> Pedro Alves wrote:
> > So back on linux_ns_enter's naming ---
> >
> > I find the abstraction here a bit odd. It seems to be me that
> > a function that does:
> >
> > #1 - select filesystem/namespace
> > #2 - call foo
> > #3 - restore filesystem/namespace
> >
> > should be a function in common code, and that the only
> > target-specific part is selecting a filesystem/namespace.
> > That is, simplifying, something like:
> >
> > /* Cause the filesystem to appear as it does to process PID and
> > call FUNC with argument ARG, restoring the filesystem to its
> > original state afterwards. Return nonzero if FUNC was called,
> > zero otherwise (and set ERRNO). */
> >
> > int
> > call_with_fs_of (int pid, void (*func) (void *), void *arg)
> > {
> > int ret;
> >
> > target->select_fs (pid);
> > ret = func ();
> > target->select_fs (0);
> > return ret;
> > }
> >
> > Was there a reason this wasn't done that way?
> >
> > (maybe make target->select_fs() return the previous
> > namespace, instead of passing 0 on the second
> > call.)
>
> I'll have a go at doing it that way.
It is kind of uglier doing it that way. It would need to look
something more like this:
struct cleanup **old_chain;
if (target->select_fs (pid, &old_chain) != 0)
return failure_return_value;
ret = func ();
do_cleanups (old_chain);
return ret;
linux_ns_enter has to open file descriptors for its own namespace
and the one it wants to enter. Its own namespace file descriptor
is what it needs to return, and it has to be held open: you can't
flip namespace and then open your own descriptor to flip back.
So the thing target->select_fs would have to return would be an
open file descriptor (to then pass to target->restore_fs, which
would take a file descriptor argument rather than an PID) but
that would be putting a Linuxism into the target vector.
Cheers,
Gary
--
http://gbenson.net/