qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Peter Maydell <peter.maydell@linaro.org>
To: Eric Blake <eblake@redhat.com>
Cc: Richard Henderson <rth@twiddle.net>,
	Richard Henderson <richard.henderson@linaro.org>,
	QEMU Developers <qemu-devel@nongnu.org>
Subject: Re: [Qemu-devel] [PATCH] linux-user: Use *at functions to implement interp_prefix
Date: Tue, 13 Feb 2018 16:43:24 +0000	[thread overview]
Message-ID: <CAFEAcA-xRtcaRA6_ApZ2Ohfpz0ZCED1y3SyLpGCOWThPFpUr_Q@mail.gmail.com> (raw)
In-Reply-To: <aff1a8c0-4e99-b52e-f933-fdc900bd91fd@redhat.com>

On 13 February 2018 at 16:38, Eric Blake <eblake@redhat.com> wrote:
> On 02/13/2018 09:31 AM, Richard Henderson wrote:
>>>
>>> I wonder if there are guest programs that make assumptions about
>>> file descriptor numbers such that it would be worthwhile dup2'ing
>>> the interp_dirfd away from the presumably low number fd it will
>>> get by default into something larger...
>>
>>
>> Hmm.  Using dup2(probe, probe) to test if the new (high) fd itself has not
>> been
>> allocated?
>
>
> fcntl(F_DUPFD[_CLOEXEC]) is smarter than dup2/3, if you plan on atomically
> guaranteeing a dup to a not-in-use fd.
>
> Will dup'ing to a high fd violate assumptions of programs that assume that
> open() and friends favor the next available fd by default, rather than
> having a gap?  (Probably not, but skipping fds is not usual, so it's worth
> asking.)

Well, the idea is that this fd is qemu-internal, so we want the guest
to see that from its point of view the first fd it opens will be 3
if it starts with the usual stdin/stdout/stderr. If we don't move it
then interp_dirfd gets 3 and the guest sees a "gap" from its POV.

(Not being able to hide this qemu-internal fd from the guest properly
is the one awkward part of this patch.)

OTOH, maybe we should just go ahead without weird games with dup2 and
see whether any real code gets confused...

thanks
-- PMM

  reply	other threads:[~2018-02-13 16:43 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-28 22:15 [Qemu-devel] [PATCH] linux-user: Use *at functions to implement interp_prefix Richard Henderson
2018-01-28 22:20 ` no-reply
2018-02-13 12:12 ` Peter Maydell
2018-02-13 15:31   ` Richard Henderson
2018-02-13 16:38     ` Eric Blake
2018-02-13 16:43       ` Peter Maydell [this message]
2018-02-13 16:50         ` Peter Maydell
2018-02-13 17:22           ` Richard Henderson

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=CAFEAcA-xRtcaRA6_ApZ2Ohfpz0ZCED1y3SyLpGCOWThPFpUr_Q@mail.gmail.com \
    --to=peter.maydell@linaro.org \
    --cc=eblake@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    --cc=rth@twiddle.net \
    /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;
as well as URLs for NNTP newsgroup(s).