qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Alex Bennée" <alex.bennee@linaro.org>
To: Fam Zheng <famz@redhat.com>
Cc: cota@braap.org, "Daniel P. Berrange" <berrange@redhat.com>,
	"Philippe Mathieu-Daudé" <f4bug@amsat.org>,
	"Richard Henderson" <richard.henderson@linaro.org>,
	balrogg@gmail.com, aurelien@aurel32.net,
	"Alexander Graf" <agraf@suse.de>,
	"QEMU Developers" <qemu-devel@nongnu.org>
Subject: Re: [Qemu-devel] [PATCH v3 for 3.0 17/18] docker: perform basic binfmt_misc validation in docker.py
Date: Tue, 24 Jul 2018 09:55:17 +0100	[thread overview]
Message-ID: <87fu09t3m2.fsf@linaro.org> (raw)
In-Reply-To: <CAK1Eb9kWAni0uWVtxvx-4FpND2iQ2DG22ARjQQwRcKnSzc+_LA@mail.gmail.com>


Fam Zheng <famz@redhat.com> writes:

> On Wed, Jul 18, 2018 at 4:02 AM Alex Bennée <alex.bennee@linaro.org> wrote:
>>
>> Setting up binfmt_misc is outside of the scope of the docker.py script
>> but we can at least validate it with any given executable so we have a
>> more useful error message than the sed line of deboostrap failing
>> cryptically.
>>
>> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
>> Reported-by: Richard Henderson <richard.henderson@linaro.org>
>> ---
>>  tests/docker/docker.py | 30 ++++++++++++++++++++++++++++++
>>  1 file changed, 30 insertions(+)
>>
>> diff --git a/tests/docker/docker.py b/tests/docker/docker.py
>> index 523f4b95a2..a3f5b0c1b0 100755
>> --- a/tests/docker/docker.py
>> +++ b/tests/docker/docker.py
>> @@ -112,6 +112,31 @@ def _copy_binary_with_libs(src, dest_dir):
>>              so_path = os.path.dirname(l)
>>              _copy_with_mkdir(l , dest_dir, so_path)
>>
>> +
>> +def _check_binfmt_misc(executable):
>> +    """Check binfmt_misc has entry for executable in the right place.
>> +
>> +    The details of setting up binfmt_misc are outside the scope of
>> +    this script but we should at least fail early with a useful
>> +    message if it won't work."""
>> +
>> +    binary = os.path.basename(executable)
>> +    binfmt_entry = "/proc/sys/fs/binfmt_misc/%s" % (binary)
>> +
>> +    if not os.path.exists(binfmt_entry):
>> +        print ("No binfmt_misc entry for %s" % (binary))
>> +        return False
>> +
>> +    with open(binfmt_entry) as x: entry = x.read()
>> +
>> +    qpath = "/usr/bin/%s" % (binary)
>
> Is it intended to hardcode this to /usr/bin? I thought we were more
> flexible than that..

That's where we currently copy it. However we are certainly capable of
being more flexible. For example as long at there is an entry visible to
the host file-system with the "F" flag we can actually create and run
docker images without copying QEMU inside the container.

However if we don't we certainly need to copy it to the same place in
the container than it is used outside the container.

>
> Fam
>
>> +    if not re.search("interpreter %s\n" % (qpath), entry):
>> +        print ("binfmt_misc for %s does not point to %s" % (binary, qpath))
>> +        return False
>> +
>> +    return True
>> +
>> +
>>  def _read_qemu_dockerfile(img_name):
>>      # special case for Debian linux-user images
>>      if img_name.startswith("debian") and img_name.endswith("user"):
>> @@ -315,6 +340,11 @@ class BuildCommand(SubCommand):
>>              # Create a docker context directory for the build
>>              docker_dir = tempfile.mkdtemp(prefix="docker_build")
>>
>> +            # Validate binfmt_misc will work
>> +            if args.include_executable:
>> +                if not _check_binfmt_misc(args.include_executable):
>> +                    return 1
>> +
>>              # Is there a .pre file to run in the build context?
>>              docker_pre = os.path.splitext(args.dockerfile)[0]+".pre"
>>              if os.path.exists(docker_pre):
>> --
>> 2.17.1
>>


--
Alex Bennée

  reply	other threads:[~2018-07-24  8:55 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-17 19:55 [Qemu-devel] [PATCH v3 for 3.0 00/18] docker fixes (and one tcg test tweak) Alex Bennée
2018-07-17 19:55 ` [Qemu-devel] [PATCH v3 for 3.0 01/18] tests/.gitignore: don't ignore docker tests Alex Bennée
2018-07-17 19:55 ` [Qemu-devel] [PATCH v3 for 3.0 02/18] docker: base debian-tricore on qemu:debian9 Alex Bennée
2018-07-17 19:55 ` [Qemu-devel] [PATCH v3 for 3.0 03/18] docker: par down QEMU_CONFIGURE_OPTS in debian-tricore-cross Alex Bennée
2018-07-17 19:55 ` [Qemu-devel] [PATCH v3 for 3.0 04/18] docker: fail more gracefully on docker.py check Alex Bennée
2018-07-17 19:55 ` [Qemu-devel] [PATCH v3 for 3.0 05/18] docker: split configure_qemu from build_qemu Alex Bennée
2018-07-17 19:55 ` [Qemu-devel] [PATCH v3 for 3.0 06/18] docker: move make check into check_qemu helper Alex Bennée
2018-07-17 19:55 ` [Qemu-devel] [PATCH v3 for 3.0 07/18] docker: gracefully skip check_qemu Alex Bennée
2018-07-17 19:55 ` [Qemu-devel] [PATCH v3 for 3.0 08/18] docker: Makefile.include don't include partial images Alex Bennée
2018-07-17 19:55 ` [Qemu-devel] [PATCH v3 for 3.0 09/18] docker: disable debian-powerpc-user-cross Alex Bennée
2018-07-23 15:09   ` Alex Bennée
2018-07-17 19:55 ` [Qemu-devel] [PATCH v3 for 3.0 10/18] docker: add test-unit runner Alex Bennée
2018-07-17 19:55 ` [Qemu-devel] [PATCH v3 for 3.0 11/18] docker: add expansion for docker-test-FOO to Makefile.include Alex Bennée
2018-07-17 19:55 ` [Qemu-devel] [PATCH v3 for 3.0 12/18] docker: drop QEMU_TARGET check, fallback in EXECUTABLE not set Alex Bennée
2018-07-17 19:55 ` [Qemu-devel] [PATCH v3 for 3.0 13/18] docker: add --hint to docker.py check Alex Bennée
2018-07-24  7:46   ` Fam Zheng
2018-07-24  8:52     ` Alex Bennée
2018-07-17 19:55 ` [Qemu-devel] [PATCH v3 for 3.0 14/18] docker: Update debootstrap script after Debian migration from Alioth to Salsa Alex Bennée
2018-07-17 19:55 ` [Qemu-devel] [PATCH v3 for 3.0 15/18] docker: add commentary to debian-bootstrap.docker Alex Bennée
2018-07-17 19:55 ` [Qemu-devel] [PATCH v3 for 3.0 16/18] docker: ignore distro versioning of debootstrap Alex Bennée
2018-07-17 19:55 ` [Qemu-devel] [PATCH v3 for 3.0 17/18] docker: perform basic binfmt_misc validation in docker.py Alex Bennée
2018-07-24  7:50   ` Fam Zheng
2018-07-24  8:55     ` Alex Bennée [this message]
2018-07-17 19:55 ` [Qemu-devel] [PATCH v3 for 3.0 18/18] tests/tcg: remove runcom test Alex Bennée
2018-07-24  9:53   ` Peter Maydell
2018-07-23 10:03 ` [Qemu-devel] [PATCH v3 for 3.0 00/18] docker fixes (and one tcg test tweak) Alex Bennée
2018-07-24  7:57   ` Fam Zheng
2018-07-24  8:56     ` Alex Bennée
2018-07-24  9:09       ` Fam Zheng

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=87fu09t3m2.fsf@linaro.org \
    --to=alex.bennee@linaro.org \
    --cc=agraf@suse.de \
    --cc=aurelien@aurel32.net \
    --cc=balrogg@gmail.com \
    --cc=berrange@redhat.com \
    --cc=cota@braap.org \
    --cc=f4bug@amsat.org \
    --cc=famz@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    /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).