commit:     dd7015229da7ba9823e0d446231d6bd4c819c396
Author:     Yixun Lan <dlan <AT> gentoo <DOT> org>
AuthorDate: Sat Jul  2 09:34:07 2022 +0000
Commit:     Yixun Lan <dlan <AT> gentoo <DOT> org>
CommitDate: Sat Jul  2 09:34:20 2022 +0000
URL:        https://gitweb.gentoo.org/proj/riscv.git/commit/?id=dd701522

sys-apps/kexec-tools: import original 2.0.24 from official tree

Signed-off-by: Yixun Lan <dlan <AT> gentoo.org>

 sys-apps/kexec-tools/Manifest                      |   1 +
 sys-apps/kexec-tools/files/90_kexec                |   9 +
 sys-apps/kexec-tools/files/README.Gentoo           |  33 ++++
 sys-apps/kexec-tools/files/kexec-r2.init           | 200 +++++++++++++++++++++
 .../kexec-tools-2.0.4-disable-kexec-test.patch     |  17 ++
 .../files/kexec-tools-2.0.4-out-of-source.patch    |  24 +++
 sys-apps/kexec-tools/files/kexec.conf              |  16 ++
 sys-apps/kexec-tools/files/kexec.conf-2.0.4        |  34 ++++
 sys-apps/kexec-tools/files/kexec.service           |  16 ++
 sys-apps/kexec-tools/kexec-tools-2.0.24.ebuild     | 124 +++++++++++++
 sys-apps/kexec-tools/metadata.xml                  |  13 ++
 11 files changed, 487 insertions(+)

diff --git a/sys-apps/kexec-tools/Manifest b/sys-apps/kexec-tools/Manifest
new file mode 100644
index 0000000..d6b3aa3
--- /dev/null
+++ b/sys-apps/kexec-tools/Manifest
@@ -0,0 +1 @@
+DIST kexec-tools-2.0.24.tar.xz 303808 BLAKE2B 
8188602f1b843c1dccc0307131f8c9ec0426c6cb3de898040352c1fed5f6d4bd7c58a0c2bf54290b91c8fe3401180df682959ee6c41693d07acc199c087c7db2
 SHA512 
ef7cf78246e2d729d81a3649791a5a23c385353cc75cbe8ef279616329fdaccc876d614c7f51e1456822a13a11520296070d9897467d24310399909e049c3822

diff --git a/sys-apps/kexec-tools/files/90_kexec 
b/sys-apps/kexec-tools/files/90_kexec
new file mode 100644
index 0000000..40bad42
--- /dev/null
+++ b/sys-apps/kexec-tools/files/90_kexec
@@ -0,0 +1,9 @@
+#!/bin/sh
+
+version="$1" ; shift
+image="$1" ; shift
+
+exec sed \
+       -e "s:\"vmlinuz-.*\":\"vmlinuz-${version}\":" \
+       -e "s:/boot/initramfs-.*\.img:/boot/initramfs-${version}\.img:" \
+       -i /etc/kexec.conf

diff --git a/sys-apps/kexec-tools/files/README.Gentoo 
b/sys-apps/kexec-tools/files/README.Gentoo
new file mode 100644
index 0000000..7735e32
--- /dev/null
+++ b/sys-apps/kexec-tools/files/README.Gentoo
@@ -0,0 +1,33 @@
+Usage
+=====
+
+Do
+ $ man 8 kexec
+for full understanding of the underlying kexec command.
+Gentoo offers a wrapper to the bare kexec command through
+/etc/init.d/kexec.
+
+Configuration
+-------------
+
+Configuration is done in /etc/conf.d/kexec, which is self-documented.
+
+Usage
+-----
+
+In Gentoo, kexec is invoked, i.e., the new kernel will be booted when
+rebooting, by reboot (8) command or by pressing Ctrl+Alt+Del.
+
+If you want to use kexec once, just run
+ $ /etc/init.d/kexec start
+
+It'll reserve kexec call at reboot. Later on, you can reboot anytime,
+letting kexec starts another (or the same) kernel. When all is done in
+the runlevel 6 - killing processes, unmounting volumes, etc - kexec
+starts the new kernel instead of doing the normal hardware reboot.
+
+If you want kexec to be run every time you reboot, add it to a runlevel:
+ $ rc-update add kexec <runlevel>
+
+If you want to reboot in the normal way this time, do:
+ $ touch /nokexec

diff --git a/sys-apps/kexec-tools/files/kexec-r2.init 
b/sys-apps/kexec-tools/files/kexec-r2.init
new file mode 100644
index 0000000..0578f51
--- /dev/null
+++ b/sys-apps/kexec-tools/files/kexec-r2.init
@@ -0,0 +1,200 @@
+#!/sbin/openrc-run
+# Copyright 1999-2020 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+# Set up some defaults.
+: "${LOAD_DURING_SHUTDOWN:=yes}"
+: "${BOOTPART:=/boot}"
+: "${DONT_MOUNT_BOOT:=no}"
+
+depend() {
+       need localmount
+}
+
+auto_prefix_bootpath() {
+       # Only auto-add prefix to relative paths.
+       case $1 in
+               */*) echo "$1";;
+               *)   echo "${BOOTPART}/$1" ;;
+       esac
+}
+
+get_genkernel_arch() {
+       case $1 in
+               x86_64) echo "amd64" ;;
+               i[3456]86) echo "x86" ;;
+               *) echo "$1" ;;
+       esac
+}
+
+image_path() {
+       # Do no sanity checking if the user has set a value.
+       if [ -n "${KNAME}" ]; then
+               auto_prefix_bootpath "${KNAME}"
+               return
+       fi
+
+       local x kver="$(uname -r)" karch="$(uname -m)"
+       local gkarch="$(get_genkernel_arch $karch)"
+       for x in \
+               "bzImage" \
+               "vmlinux" \
+               "vmlinuz" \
+               "kernel" \
+               "bzImage-${kver}" \
+               "vmlinux-${kver}" \
+               "vmlinuz-${kver}" \
+               "kernel-genkernel-${karch}-${kver}" \
+               "kernel-genkernel-${gkarch}-${kver}" \
+               "kernel-${kver}" \
+               "kernel-${karch}"; do
+               if [ -e "${BOOTPART}/${x}" ]; then
+                       echo "${BOOTPART}/${x}"
+                       return
+               fi
+       done
+
+       return 1
+}
+
+initrd_path() {
+       # Do no sanity checking if the user has set a value.
+       if [ -n "${INITRD}" ]; then
+               auto_prefix_bootpath "${INITRD}"
+               return 0
+       fi
+
+       local x kver="$(uname -r)" karch="$(uname -m)"
+       local gkarch="$(get_genkernel_arch $karch)"
+       for x in \
+               "initrd" \
+               "initramfs" \
+               "initrd.img-${kver}" \
+               "initrd-${kver}.img" \
+               "initrd-${kver}" \
+               "initramfs-${kver}.img" \
+               "initramfs-genkernel-${karch}-${kver}" \
+               "initramfs-genkernel-${gkarch}-${kver}"; do
+               if [ -e "${BOOTPART}/${x}" ]; then
+                       echo "${BOOTPART}/${x}"
+                       return 0
+               fi
+       done
+
+       return 1
+}
+
+mount_boot() {
+       [ "${DONT_MOUNT_BOOT}" != "no" ] && return 1
+       mountinfo -q "${BOOTPART}" && return 1
+
+       ebegin "Mounting ${BOOTPART}"
+       mount "${BOOTPART}"
+       eend $?
+}
+
+load_image() {
+       if [ "${KNAME}" = "-" ]; then
+               ebegin "Disabling kexec"
+               kexec -u
+               eend $?
+               return  # eend preserved $? for us.
+       fi
+
+       local img initrd="$(initrd_path)" mounted=false kparamopt initrdopt
+
+       if ! img="$(image_path)"; then
+               if mount_boot; then
+                       if img="$(image_path)"; then
+                               mounted=true
+                               initrd="$(initrd_path)"
+                       else
+                               eerror "No kernel image found in ${BOOTPART}!"
+                               umount "${BOOTPART}"
+                               return 1
+                       fi
+               else
+                       eerror "No kernel image found in ${BOOTPART}!"
+                       return 1
+               fi
+       fi
+
+       local is_rootpart_autodetected=no
+       if [ -z "${ROOTPART}" ]; then
+               ROOTPART="$(readlink -f "$(sed -n '/^\/[^ ]* \/ / s,^\([^ 
]*\).*,\1,p' /proc/mounts)")"
+               is_rootpart_autodetected=yes
+       fi
+
+       local is_reusing_cmdline=no
+       if [ -z "${KPARAM}" ]; then
+               kparamopt="--reuse-cmdline"
+               is_reusing_cmdline=yes
+       fi
+
+       if ! yesno "${is_rootpart_autodetected}" || ! yesno 
"${is_reusing_cmdline}"; then
+               # Only append root when explicit set in config or
+               # if we aren't re-using kernel cmdline
+               KPARAM="${KPARAM:+"${KPARAM} "}root=${ROOTPART}"
+       fi
+
+       if [ -n "${initrd}" ]; then
+               initrdopt="--initrd=${initrd}"
+       fi
+
+       local msg
+       [ -n "${initrd}" ] && \
+               msg=" (with ${initrd})"
+       ebegin "Using kernel image ${img}${msg} for kexec"
+
+       kexec ${KEXEC_OPT_ARGS} ${kparamopt} \
+               -l "${img}" ${KPARAM:+--append="${KPARAM}"} ${initrdopt}
+       local ret=$?
+
+       ${mounted} && umount "${BOOTPART}"
+       eend ${ret}
+       return ${ret}
+}
+
+start() {
+       if [ "${LOAD_DURING_SHUTDOWN}" = "yes" ]; then
+               local mounted
+               if mount_boot; then
+                       mounted=true
+               fi
+               if ! image_path >/dev/null; then
+                       ewarn "Cannot find kernel image!"
+                       ewarn "Please make sure a valid kernel image is present 
before reboot."
+                       return 0
+               fi
+               if [ -n "${mounted}" ]; then
+                       ebegin "Unmounting ${BOOTPART}"
+                       umount "${BOOTPART}"
+                       eend $?
+               fi
+               # $? is already set to the previous calls.
+               return
+       else
+               load_image
+       fi
+}
+
+stop() {
+       if ! yesno ${RC_REBOOT}; then
+               ebegin "Not rebooting; disabling kexec"
+               kexec -u
+               eend $?
+               return
+       fi
+
+       if [ -f /nokexec ]; then
+               ebegin "Rebooting; disabling kexec due to /nokexec"
+               rm -f /nokexec
+               kexec -u
+               eend $?
+               return
+       fi
+
+       if [ "${LOAD_DURING_SHUTDOWN}" = "yes" ]; then
+               load_image
+       fi
+}

diff --git 
a/sys-apps/kexec-tools/files/kexec-tools-2.0.4-disable-kexec-test.patch 
b/sys-apps/kexec-tools/files/kexec-tools-2.0.4-disable-kexec-test.patch
new file mode 100644
index 0000000..6fc73f2
--- /dev/null
+++ b/sys-apps/kexec-tools/files/kexec-tools-2.0.4-disable-kexec-test.patch
@@ -0,0 +1,17 @@
+diff --git kexec-tools-2.0.3/kexec_test/Makefile 
kexec-tools-2.0.3/kexec_test/Makefile
+index fec6210..2ed4d51 100644
+--- kexec-tools-2.0.3/kexec_test/Makefile
++++ kexec-tools-2.0.3/kexec_test/Makefile
+@@ -8,12 +8,6 @@ dist += kexec_test/Makefile $(KEXEC_TEST_SRCS)                
                \
+       kexec_test/x86-setup-legacy-pic.S
+ 
+ BUILD_KEXEC_TEST = no
+-ifeq ($(ARCH),i386)
+-BUILD_KEXEC_TEST = yes
+-endif
+-ifeq ($(ARCH),x86_64)
+-BUILD_KEXEC_TEST = yes
+-endif
+ 
+ ifeq ($(BUILD_KEXEC_TEST),yes)
+ 

diff --git a/sys-apps/kexec-tools/files/kexec-tools-2.0.4-out-of-source.patch 
b/sys-apps/kexec-tools/files/kexec-tools-2.0.4-out-of-source.patch
new file mode 100644
index 0000000..64c6cd8
--- /dev/null
+++ b/sys-apps/kexec-tools/files/kexec-tools-2.0.4-out-of-source.patch
@@ -0,0 +1,24 @@
+ Makefile.in | 3 ++-
+ 1 file changed, 2 insertions(+), 1 deletion(-)
+
+diff --git a/Makefile.in b/Makefile.in
+index c1859d1..1aa8559 100644
+--- a/Makefile.in
++++ b/Makefile.in
+@@ -44,7 +44,7 @@ TARGET_CFLAGS        = @TARGET_CFLAGS@
+ 
+ # Base compiler flags. These are extended by the subcomponent-Makefiles
+ # where necessary.
+-CPPFLAGS      = @CPPFLAGS@ -I$(srcdir)/include -I$(srcdir)/util_lib/include \
++CPPFLAGS      = @CPPFLAGS@ -I$(top_builddir)/include -I$(srcdir)/include 
-I$(srcdir)/util_lib/include \
+                       -Iinclude/ $($(ARCH)_CPPFLAGS)
+ CFLAGS                = @CFLAGS@ -fno-strict-aliasing -Wall 
-Wstrict-prototypes
+ PURGATORY_EXTRA_CFLAGS = @PURGATORY_EXTRA_CFLAGS@
+@@ -77,6 +77,7 @@ pkgincludedir = $(includedir)/$(PACKAGE_NAME)
+ DESTDIR =
+ 
+ srcdir                = @srcdir@
++top_builddir = @top_builddir@
+ VPATH         = .:$(srcdir)
+ 
+ # install paths

diff --git a/sys-apps/kexec-tools/files/kexec.conf 
b/sys-apps/kexec-tools/files/kexec.conf
new file mode 100644
index 0000000..aa829b9
--- /dev/null
+++ b/sys-apps/kexec-tools/files/kexec.conf
@@ -0,0 +1,16 @@
+# Kernel image pathname, relative from /boot.
+KNAME="bzimage"
+
+# Additional arguments passed to kexec (8)
+# Following arguments are support:
+#
+# --reuse-cmdline
+#   Use the current boot command line
+#
+# --command-line=string
+#   Use a different command line
+#
+# --initrd=file
+#   Specify an initrd to use
+#
+KEXEC_OPT_ARGS="--reuse-cmdline"

diff --git a/sys-apps/kexec-tools/files/kexec.conf-2.0.4 
b/sys-apps/kexec-tools/files/kexec.conf-2.0.4
new file mode 100644
index 0000000..b71ea2b
--- /dev/null
+++ b/sys-apps/kexec-tools/files/kexec.conf-2.0.4
@@ -0,0 +1,34 @@
+# Load kexec kernel image into memory during shutdown instead of bootup
+# (default: yes)
+#LOAD_DURING_SHUTDOWN="yes"
+
+# Additional arguments passed to kexec (8)
+#KEXEC_OPT_ARGS=""
+
+# Kernel image partition. Mounted automatically if not.
+# (default: /boot)
+#BOOTPART="/boot"
+
+# Root partition (should be autodetected)
+#ROOTPART="/dev/hda3"
+
+# Kernel image pathname, relative from BOOTPART.
+# If it's one of 
+# {kernel-genkernel,bzImage,vmlinuz,kernel}-<currently running kernel version>,
+# or bzImage, vmlinuz (without suffix),
+# then it's automaticaly detected.
+# Setting it to "-" will disable kexec.
+#KNAME="vmlinuz-3.9.0"
+
+# Initrd
+# Same automatic detection restriction as for KNAME apply.
+# initramfs-genkernel-<currently running kernel version>,
+# initrd{,.img}-<currently running kernel version>{,.img}
+# will be detected.
+#INITRD="/boot/fbsplash-emergence-1024x768"
+
+# Kernel parameters (should be autodetected)
+#KPARAM="splash=silent,theme:emergence"
+
+# Do not try to mount /boot
+# DONT_MOUNT_BOOT="yes"

diff --git a/sys-apps/kexec-tools/files/kexec.service 
b/sys-apps/kexec-tools/files/kexec.service
new file mode 100644
index 0000000..289aae0
--- /dev/null
+++ b/sys-apps/kexec-tools/files/kexec.service
@@ -0,0 +1,16 @@
+[Unit]
+Description=Gracefully restart the box
+Documentation=man:kexec(8)
+After=boot.mount
+Before=shutdown.target umount.target final.target
+ConditionPathExists=!/nokexec
+
+[Service]
+Type=oneshot
+RemainAfterExit=yes
+EnvironmentFile=/etc/kexec.conf
+ExecStart=/usr/sbin/kexec -l /boot/${KNAME} ${KEXEC_OPT_ARGS}
+ExecStop=/usr/sbin/kexec -l /boot/${KNAME} ${KEXEC_OPT_ARGS}
+
+[Install]
+WantedBy=multi-user.target

diff --git a/sys-apps/kexec-tools/kexec-tools-2.0.24.ebuild 
b/sys-apps/kexec-tools/kexec-tools-2.0.24.ebuild
new file mode 100644
index 0000000..5723fa8
--- /dev/null
+++ b/sys-apps/kexec-tools/kexec-tools-2.0.24.ebuild
@@ -0,0 +1,124 @@
+# Copyright 1999-2022 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=8
+
+inherit libtool linux-info systemd
+
+if [[ ${PV} == "9999" ]] ; then
+       inherit git-r3 autotools
+       
EGIT_REPO_URI="https://git.kernel.org/pub/scm/utils/kernel/kexec/kexec-tools.git";
+else
+       
SRC_URI="https://www.kernel.org/pub/linux/utils/kernel/kexec/${P/_/-}.tar.xz";
+       [[ "${PV}" == *_rc* ]] || \
+       KEYWORDS="~amd64 ~arm64 ~ppc64 ~x86"
+fi
+
+DESCRIPTION="Load another kernel from the currently executing Linux kernel"
+HOMEPAGE="https://kernel.org/pub/linux/utils/kernel/kexec/";
+
+LICENSE="GPL-2"
+SLOT="0"
+IUSE="booke lzma xen zlib"
+
+REQUIRED_USE="lzma? ( zlib )"
+
+DEPEND="
+       lzma? ( app-arch/xz-utils )
+       zlib? ( sys-libs/zlib )"
+RDEPEND="${DEPEND}"
+
+S="${WORKDIR}/${P/_/-}"
+
+CONFIG_CHECK="~KEXEC"
+
+PATCHES=(
+       "${FILESDIR}"/${PN}-2.0.4-disable-kexec-test.patch
+       "${FILESDIR}"/${PN}-2.0.4-out-of-source.patch
+)
+
+pkg_setup() {
+       # GNU Make's $(COMPILE.S) passes ASFLAGS to $(CCAS), CCAS=$(CC)
+       export ASFLAGS="${CCASFLAGS}"
+}
+
+src_prepare() {
+       default
+
+       # Append PURGATORY_EXTRA_CFLAGS flags set by configure, instead of 
overriding them completely.
+       sed -e "/^PURGATORY_EXTRA_CFLAGS =/s/=/+=/" -i Makefile.in || die
+
+       if [[ "${PV}" == 9999 ]] ; then
+               eautoreconf
+       else
+               elibtoolize
+       fi
+}
+
+src_configure() {
+       local myeconfargs=(
+               $(use_with booke)
+               $(use_with lzma)
+               $(use_with xen)
+               $(use_with zlib)
+       )
+       econf "${myeconfargs[@]}"
+}
+
+src_compile() {
+       # Respect CFLAGS for purgatory.
+       # purgatory/Makefile uses PURGATORY_EXTRA_CFLAGS variable.
+       # -mfunction-return=thunk and -mindirect-branch=thunk conflict with
+       # -mcmodel=large which is added by build system.
+       # Replace them with -mfunction-return=thunk-inline and 
-mindirect-branch=thunk-inline.
+       local flag flags=()
+       for flag in ${CFLAGS}; do
+               [[ ${flag} == -mfunction-return=thunk ]] && 
flag="-mfunction-return=thunk-inline"
+               [[ ${flag} == -mindirect-branch=thunk ]] && 
flag="-mindirect-branch=thunk-inline"
+               flags+=("${flag}")
+       done
+       local -x PURGATORY_EXTRA_CFLAGS="${flags[*]}"
+
+       default
+}
+
+src_install() {
+       default
+
+       dodoc "${FILESDIR}"/README.Gentoo
+
+       newinitd "${FILESDIR}"/kexec-r2.init kexec
+       newconfd "${FILESDIR}"/kexec.conf-2.0.4 kexec
+
+       insinto /etc
+       doins "${FILESDIR}"/kexec.conf
+
+       insinto /etc/kernel/postinst.d
+       doins "${FILESDIR}"/90_kexec
+
+       systemd_dounit "${FILESDIR}"/kexec.service
+}
+
+pkg_postinst() {
+       if systemd_is_booted || has_version sys-apps/systemd; then
+               elog "For systemd support the new config file is"
+               elog "   /etc/kexec.conf"
+               elog "Please adopt it to your needs as there is no autoconfig 
anymore"
+       fi
+
+       local n_root_args=$(grep -o -- '\<root=' /proc/cmdline 2>/dev/null | wc 
-l)
+       local has_rootpart_set=no
+       if [[ -f "${EROOT}/etc/conf.d/kexec" ]]; then
+               if grep -q -E -- '^ROOTPART=' "${EROOT}/etc/conf.d/kexec" 
2>/dev/null; then
+                       has_rootpart_set=yes
+               fi
+       fi
+
+       if [[ ${n_root_args} -gt 1 && "${has_rootpart_set}" == "no"  ]]; then
+               ewarn "WARNING: Multiple root arguments (root=) on kernel 
command-line detected!"
+               ewarn "This was probably caused by a previous version of ${PN}."
+               ewarn "Please reboot system once *without* kexec to avoid boot 
problems"
+               ewarn "in case running system and initramfs do not agree on 
detected"
+               ewarn "root device name!"
+       fi
+}

diff --git a/sys-apps/kexec-tools/metadata.xml 
b/sys-apps/kexec-tools/metadata.xml
new file mode 100644
index 0000000..d56b5de
--- /dev/null
+++ b/sys-apps/kexec-tools/metadata.xml
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE pkgmetadata SYSTEM "https://www.gentoo.org/dtd/metadata.dtd";>
+<pkgmetadata>
+  <maintainer type="project">
+    <email>[email protected]</email>
+    <name>Gentoo Base System</name>
+  </maintainer>
+  <use>
+    <flag name="lzma">Enables support for LZMA compressed kernel images</flag>
+    <flag name="booke">Include support for Book-E memory management</flag>
+    <flag name="xen">Enable extended xen support</flag>
+  </use>
+</pkgmetadata>

Reply via email to