Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Gary Benson <gbenson@redhat.com>
To: Pedro Alves <palves@redhat.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH] Encapsulate target_fileio file descriptors
Date: Wed, 18 Mar 2015 18:45:00 -0000	[thread overview]
Message-ID: <20150318184538.GA32134@blade.nx> (raw)
In-Reply-To: <55099F05.1010501@redhat.com>

Pedro Alves wrote:
> On 03/18/2015 01:20 PM, Gary Benson wrote:
> > Various target_fileio_* functions use integer file descriptors to
> > refer to open files, which can cause problems if the target stack
> > changes between the file being opened and other file operations
> > being performed on that file.  This commit makes the
> > target_fileio_* functions that use file descriptors use an opaque
> > target_fileio_t handle instead that encapsulates both the file
> > descriptor itself and the target_ops vector that should be used
> > to access it.
> 
> Thanks Gary.
> 
> I think this deserves an expanded explanation, for posterity.
...
> And obviously, if FD happens to be a file descriptor number that
> happens to be open in GDB as well, we'll close it by mistake.
> That's the sort of random issue that wouldn't be very fun to track
> down!

Yeah, like GDB printing 350MB of poll errors because it closed one
of its readline pipes :)

> It works today, though I suspect that it may cause problems in
> the future.  When we get to multi-target, and target_ops instances
> become objects instantiated on the heap, we'll have the problem that
> the target_ops pointer in the handle becomes invalid as soon as the
> target_ops object is closed/destroyed/released (unless the target
> object is refcounted, which isn't clear it should).
> 
> A table-based solution, where target.c maintains (something
> conceptually like) a table of "target file descriptor + target_ops"
> elements, and passes an index into that table as file handle to
> target_fileio_ callers, would make it possible to invalidate the
> file handles directly in the table when a target is closed, so
> that e.g., target_fileio_close (etc.) could detect that the file
> handle is now invalid, and return error with errno=EBADF _without_
> calling through the now invalid target_ops pointer.

The files could be closed when the table entry is invalidated too.
I'll reimplement this and post a new patch tomorrow or Friday.

> Speaking of EBADF, I noticed that remote_hostio_send_command
> fails with ENOSYS if the remote connection is closed, which
> seems wrong to me.

That seems intuitive for the ones that take file descriptor
arguments (remote_hostio_{pread,write,fstat,close}).  Not sure
if that makes sense for the ones that take filenames (open,
readlink, unlink).  ENOSYS isn't really correct for those
either--they are implemented, you just can't do it right now.
ECOMM?  ECONNABORTED?  ENOTCONN?  EPIPE?  EREMOTEIO?
I'm open to suggestions :)

Cheers,
Gary

-- 
http://gbenson.net/


  reply	other threads:[~2015-03-18 18:45 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-18 13:21 Gary Benson
2015-03-18 15:51 ` Pedro Alves
2015-03-18 18:45   ` Gary Benson [this message]
2015-03-20 16:06     ` [PATCH v2] Associate target_ops with " Gary Benson
2015-03-24 13:22       ` Pedro Alves
2015-03-24 16:17         ` Gary Benson
2015-03-24 16:36           ` Pedro Alves
2015-03-24 16:55             ` Pedro Alves
2015-03-25 11:32               ` [pushed] " Gary Benson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150318184538.GA32134@blade.nx \
    --to=gbenson@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=palves@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox