From patchwork Tue Jul 24 10:51:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 948394 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="FhhdhGR1"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41ZbFp54Z7z9s0R for ; Tue, 24 Jul 2018 21:08:45 +1000 (AEST) Received: from localhost ([::1]:39552 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fhvBI-0006g4-Ap for incoming@patchwork.ozlabs.org; Tue, 24 Jul 2018 07:08:40 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34079) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fhv1o-0007R3-Ad for qemu-devel@nongnu.org; Tue, 24 Jul 2018 06:58:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fhv1n-0000li-E6 for qemu-devel@nongnu.org; Tue, 24 Jul 2018 06:58:52 -0400 Received: from mail-wm0-x22c.google.com ([2a00:1450:400c:c09::22c]:54857) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fhv1n-0000lJ-7L for qemu-devel@nongnu.org; Tue, 24 Jul 2018 06:58:51 -0400 Received: by mail-wm0-x22c.google.com with SMTP id c14-v6so2072213wmb.4 for ; Tue, 24 Jul 2018 03:58:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=PnFN5FS2xP69E9wMMeQYrIzwdK/U7cqY4mU/KHwg9jw=; b=FhhdhGR1o+6RImJA81GJHr4ARn11nBbpM7iTWcdl8iUsz7ZIRy9nUxUnRohUajWm7S 8Krmq9ciuWUB8RtY8cCGYJoZwrvUgbN/kpu/7upGRk4m+2ii4QGVDmzoPE71zBiWkTzv 69F+t0T+Y3XCnggUTOi3aecniOqnuuWeXlFo8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=PnFN5FS2xP69E9wMMeQYrIzwdK/U7cqY4mU/KHwg9jw=; b=ZDyi+qKA9O6MfJr7Ue/3xQ7ZkhAk9yrrSWve9rLRe/N06heqCPcTuHHXQ5Ykorn7mk ZcLT7uXccakBJLN+FywSwVN/cvjpqmITN2nuZBvbuEy50ApTc0rOAyMhNTOxEJmgDbvM WFq3DWzFWl1N1DLKDKW+5A/aPAlIpXJ/sdI/Xwqp1EiESIkho2caW8hxeB8cqzJdguTm 3oc+ZFhN7U3URImaHyrPKkEMVNQWDLVF6TaJG3Zl/FrBhv7kE7LoA8PBxDTxugmRvlmG JhrPI0mGb5T7GXP5EYAq9P4W5OiWDcgw3Y+zZsRiK4sgohyeeaggmPHK4zB+22dk3Y6F Qutw== X-Gm-Message-State: AOUpUlG7wZLEWE12m12l6MoiFRWDZdE3gUPTFU0uxhmwyEO4KPVk+6Dv w2qOOz/j7+e6HW3jxaNn1y5ldA== X-Google-Smtp-Source: AAOMgpcDWuB5CEBWid5AGL+TKGdbOuizGbq11LPw9FMRxDOxILqGK3/PmGjayGWnEtqMavOf1tIZQw== X-Received: by 2002:a1c:8a04:: with SMTP id m4-v6mr1592336wmd.137.1532429930068; Tue, 24 Jul 2018 03:58:50 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id h5-v6sm8718020wre.46.2018.07.24.03.58.46 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 24 Jul 2018 03:58:46 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 21EBF3E0719; Tue, 24 Jul 2018 11:51:11 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: peter.maydell@linaro.org Date: Tue, 24 Jul 2018 11:51:08 +0100 Message-Id: <20180724105109.8392-17-alex.bennee@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180724105109.8392-1-alex.bennee@linaro.org> References: <20180724105109.8392-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c09::22c Subject: [Qemu-devel] [PULL 16/17] docker: perform basic binfmt_misc validation in docker.py X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Fam Zheng , =?utf-8?q?Alex_Benn=C3=A9e?= , qemu-devel@nongnu.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 Reported-by: Richard Henderson diff --git a/tests/docker/docker.py b/tests/docker/docker.py index 2f81c6b13b..d3006d4dae 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) + 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):