From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id ACBC9139085 for ; Fri, 20 Jan 2017 19:28:39 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id E5446E0DE5; Fri, 20 Jan 2017 19:28:38 +0000 (UTC) Received: from smtp.gentoo.org (woodpecker.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id B3270E0DE5 for ; Fri, 20 Jan 2017 19:28:38 +0000 (UTC) Received: from oystercatcher.gentoo.org (unknown [IPv6:2a01:4f8:202:4333:225:90ff:fed9:fc84]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id E4021341627 for ; Fri, 20 Jan 2017 19:28:36 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 8A2AB2A83 for ; Fri, 20 Jan 2017 19:28:35 +0000 (UTC) From: "Mike Frysinger" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Mike Frysinger" Message-ID: <1484940379.175bcba82218df8e7ad40919b5d45dbcc3d2ac30.vapier@gentoo> Subject: [gentoo-commits] repo/gentoo:master commit in: app-emulation/qemu/, app-emulation/qemu/files/ X-VCS-Repository: repo/gentoo X-VCS-Files: app-emulation/qemu/files/qemu-binfmt.initd.head app-emulation/qemu/files/qemu-binfmt.initd.tail app-emulation/qemu/qemu-9999.ebuild X-VCS-Directories: app-emulation/qemu/ app-emulation/qemu/files/ X-VCS-Committer: vapier X-VCS-Committer-Name: Mike Frysinger X-VCS-Revision: 175bcba82218df8e7ad40919b5d45dbcc3d2ac30 X-VCS-Branch: master Date: Fri, 20 Jan 2017 19:28:35 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: de688c2a-8cbd-4a79-9398-5878d8e41416 X-Archives-Hash: a6d0d7f11839a8aee9f804c6e09c27c8 commit: 175bcba82218df8e7ad40919b5d45dbcc3d2ac30 Author: Mike Frysinger gentoo org> AuthorDate: Fri Jan 20 19:21:20 2017 +0000 Commit: Mike Frysinger gentoo org> CommitDate: Fri Jan 20 19:26:19 2017 +0000 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=175bcba8 app-emulation/qemu: generate init.d script from upstream settings app-emulation/qemu/files/qemu-binfmt.initd.head | 64 +++++++++++++++++++++++++ app-emulation/qemu/files/qemu-binfmt.initd.tail | 14 ++++++ app-emulation/qemu/qemu-9999.ebuild | 49 ++++++++++++++++++- 3 files changed, 125 insertions(+), 2 deletions(-) diff --git a/app-emulation/qemu/files/qemu-binfmt.initd.head b/app-emulation/qemu/files/qemu-binfmt.initd.head new file mode 100644 index 00000000..858d5d7 --- /dev/null +++ b/app-emulation/qemu/files/qemu-binfmt.initd.head @@ -0,0 +1,64 @@ +#!/sbin/openrc-run +# Copyright 1999-2017 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 + +# Enable automatic non-native program execution by the kernel. + +# Defaulting to OC should be safe because it comes down to: +# - do we trust the interp itself to not be malicious? yes; we built it. +# - do we trust the programs we're running? ish; same permission as native +# binaries apply. so if user can do bad stuff natively, cross isn't worse. +: ${QEMU_BINFMT_FLAGS:=OC} + +depend() { + after procfs +} + +start() { + ebegin "Registering qemu-user binaries (flags: ${QEMU_BINFMT_FLAGS})" + + if [ ! -d /proc/sys/fs/binfmt_misc ] ; then + modprobe -q binfmt_misc + fi + + if [ ! -d /proc/sys/fs/binfmt_misc ] ; then + eend 1 "You need support for 'misc binaries' in your kernel!" + return + fi + + if [ ! -f /proc/sys/fs/binfmt_misc/register ] ; then + mount -t binfmt_misc -o nodev,noexec,nosuid \ + binfmt_misc /proc/sys/fs/binfmt_misc >/dev/null 2>&1 + eend $? || return + fi + + # Probe the native cpu type so we don't try registering them. + local cpu="$(uname -m)" + case "${cpu}" in + armv[4-9]*) + cpu="arm" + ;; + i386|i486|i586|i686|i86pc|BePC|x86_64) + cpu="i386" + ;; + m68k) + cpu="m68k" + ;; + mips*) + cpu="mips" + ;; + "Power Macintosh"|ppc|ppc64) + cpu="ppc" + ;; + s390*) + cpu="s390" + ;; + sh*) + cpu="sh" + ;; + sparc*) + cpu="sparc" + ;; + esac + + # Register the interpreter for each cpu except for the native one. diff --git a/app-emulation/qemu/files/qemu-binfmt.initd.tail b/app-emulation/qemu/files/qemu-binfmt.initd.tail new file mode 100644 index 00000000..7679481 --- /dev/null +++ b/app-emulation/qemu/files/qemu-binfmt.initd.tail @@ -0,0 +1,14 @@ + eend 0 +} + +stop() { + # We unregister everything in the "qemu-xxx" namespace. + ebegin "Unregistering qemu-user binaries" + local f + for f in /proc/sys/fs/binfmt_misc/qemu-* ; do + if [ -f "${f}" ] ; then + echo '-1' > "${f}" + fi + done + eend 0 +} diff --git a/app-emulation/qemu/qemu-9999.ebuild b/app-emulation/qemu/qemu-9999.ebuild index 28b1867..6a78bbb 100644 --- a/app-emulation/qemu/qemu-9999.ebuild +++ b/app-emulation/qemu/qemu-9999.ebuild @@ -560,13 +560,58 @@ qemu_python_install() { python_doscript "${S}/scripts/qmp/qemu-ga-client" } +# Generate the /etc/init.d/qemu-binfmt script which registers the user handlers. +generate_initd() { + local out="${T}/qemu-binfmt" + local d="${T}/binfmt.d" + + einfo "Generating qemu init.d script" + + # Generate the debian fragments first. + mkdir -p "${d}" + "${S}"/scripts/qemu-binfmt-conf.sh \ + --debian \ + --exportdir "${d}" \ + --qemu-path "${EPREFIX}/usr/bin" \ + || die + # Then turn the fragments into a shell script we can source. + sed -E -i \ + -e 's:^([^ ]+) (.*)$:\1="\2":' \ + "${d}"/* || die + + # Generate the init.d script by assembling the fragments from above. + local f qcpu package interpreter magic mask + cat "${FILESDIR}"/qemu-binfmt.initd.head >"${out}" || die + for f in "${d}"/qemu-* ; do + source "${f}" + + # Normalize the cpu logic like we do in the init.d for the native cpu. + qcpu=${package#qemu-} + case ${qcpu} in + arm*) qcpu="arm";; + mips*) qcpu="mips";; + ppc*) qcpu="ppc";; + s390*) qcpu="s390";; + sh*) qcpu="sh";; + sparc*) qcpu="sparc";; + esac + + cat <>"${out}" + if [ "\${cpu}" != "${qcpu}" -a -x "${interpreter}" ] ; then + echo ':${package}:M::${magic}:${mask}:${interpreter}:'"\${QEMU_BINFMT_FLAGS}" >/proc/sys/fs/binfmt_misc/register + fi +EOF + done + cat "${FILESDIR}"/qemu-binfmt.initd.tail >>"${out}" || die +} + src_install() { if [[ -n ${user_targets} ]]; then cd "${S}/user-build" emake DESTDIR="${ED}" install - # Install binfmt handler init script for user targets - newinitd "${FILESDIR}/qemu-binfmt.initd-r1" qemu-binfmt + # Install binfmt handler init script for user targets. + doinitd "${T}/qemu-binfmt" fi if [[ -n ${softmmu_targets} ]]; then