Blame SOURCES/0076-Add-grub-get-kernel-settings-and-use-it-in-10_linux.patch

d9d99f
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
d9d99f
From: Peter Jones <pjones@redhat.com>
d9d99f
Date: Thu, 23 Jun 2016 11:01:39 -0400
d9d99f
Subject: [PATCH] Add grub-get-kernel-settings and use it in 10_linux
d9d99f
d9d99f
This patch adds grub-get-kernel-settings, which reads the system kernel
d9d99f
installation configuration from /etc/sysconfig/kernel, and outputs
d9d99f
${GRUB_...} variables suitable for evaluation by grub-mkconfig.  Those
d9d99f
variables are then used by 10_linux to choose whether or not to create
d9d99f
debug stanzas.
d9d99f
d9d99f
Resolves: rhbz#1226325
d9d99f
---
d9d99f
 configure.ac                                   |  2 +
d9d99f
 Makefile.util.def                              |  7 +++
d9d99f
 .gitignore                                     |  2 +
d9d99f
 util/bash-completion.d/grub-completion.bash.in | 22 ++++++++
d9d99f
 util/grub-get-kernel-settings.3                | 20 +++++++
d9d99f
 util/grub-get-kernel-settings.in               | 78 ++++++++++++++++++++++++++
d9d99f
 util/grub-mkconfig.in                          |  3 +
d9d99f
 util/grub.d/10_linux.in                        | 23 ++++++--
d9d99f
 8 files changed, 152 insertions(+), 5 deletions(-)
d9d99f
 create mode 100644 util/grub-get-kernel-settings.3
d9d99f
 create mode 100644 util/grub-get-kernel-settings.in
d9d99f
d9d99f
diff --git a/configure.ac b/configure.ac
d9d99f
index 71d1056969e..aa06ed59c8d 100644
d9d99f
--- a/configure.ac
d9d99f
+++ b/configure.ac
d9d99f
@@ -58,6 +58,7 @@ grub_TRANSFORM([grub-install])
d9d99f
 grub_TRANSFORM([grub-mkconfig])
d9d99f
 grub_TRANSFORM([grub-mkfont])
d9d99f
 grub_TRANSFORM([grub-mkimage])
d9d99f
+grub_TRANSFORM([grub-get-kernel-settings])
d9d99f
 grub_TRANSFORM([grub-glue-efi])
d9d99f
 grub_TRANSFORM([grub-mklayout])
d9d99f
 grub_TRANSFORM([grub-mkpasswd-pbkdf2])
d9d99f
@@ -75,6 +76,7 @@ grub_TRANSFORM([grub-file])
d9d99f
 grub_TRANSFORM([grub-bios-setup.3])
d9d99f
 grub_TRANSFORM([grub-editenv.1])
d9d99f
 grub_TRANSFORM([grub-fstest.3])
d9d99f
+grub_TRANSFORM([grub-get-kernel-settings.3])
d9d99f
 grub_TRANSFORM([grub-glue-efi.3])
d9d99f
 grub_TRANSFORM([grub-install.1])
d9d99f
 grub_TRANSFORM([grub-kbdcomp.3])
d9d99f
diff --git a/Makefile.util.def b/Makefile.util.def
d9d99f
index fd91045bd6d..2d032643de7 100644
d9d99f
--- a/Makefile.util.def
d9d99f
+++ b/Makefile.util.def
d9d99f
@@ -714,6 +714,13 @@ script = {
d9d99f
   installdir = sbin;
d9d99f
 };
d9d99f
 
d9d99f
+script = {
d9d99f
+  name = grub-get-kernel-settings;
d9d99f
+  common = util/grub-get-kernel-settings.in;
d9d99f
+  mansection = 3;
d9d99f
+  installdir = sbin;
d9d99f
+};
d9d99f
+
d9d99f
 script = {
d9d99f
   name = grub-set-default;
d9d99f
   common = util/grub-set-default.in;
d9d99f
diff --git a/.gitignore b/.gitignore
d9d99f
index 5066689bc0a..54795fa60be 100644
d9d99f
--- a/.gitignore
d9d99f
+++ b/.gitignore
d9d99f
@@ -68,6 +68,8 @@ grub-*.tar.*
d9d99f
 /grub*-fs-tester
d9d99f
 /grub*-fstest
d9d99f
 /grub*-fstest.1
d9d99f
+/grub*-get-kernel-settings
d9d99f
+/grub*-get-kernel-settings.3
d9d99f
 /grub*-glue-efi
d9d99f
 /grub*-glue-efi.1
d9d99f
 /grub*-install
d9d99f
diff --git a/util/bash-completion.d/grub-completion.bash.in b/util/bash-completion.d/grub-completion.bash.in
d9d99f
index 44bf135b9f8..5c4acd496d4 100644
d9d99f
--- a/util/bash-completion.d/grub-completion.bash.in
d9d99f
+++ b/util/bash-completion.d/grub-completion.bash.in
d9d99f
@@ -264,6 +264,28 @@ have ${__grub_sparc64_setup_program} && \
d9d99f
 unset __grub_sparc64_setup_program
d9d99f
 
d9d99f
 
d9d99f
+#
d9d99f
+# grub-get-kernel-settings
d9d99f
+#
d9d99f
+_grub_get_kernel_settings () {
d9d99f
+    local cur
d9d99f
+
d9d99f
+    COMPREPLY=()
d9d99f
+    cur=`_get_cword`
d9d99f
+
d9d99f
+    if [[ "$cur" == -* ]]; then
d9d99f
+        __grubcomp "$(__grub_get_options_from_help)"
d9d99f
+    else
d9d99f
+        # Default complete with a filename
d9d99f
+        _filedir
d9d99f
+    fi
d9d99f
+}
d9d99f
+__grub_get_kernel_settings_program="@grub_get_kernel_settings@"
d9d99f
+have ${__grub_get_kernel_settings_program} && \
d9d99f
+ complete -F _grub_get_kernel_settings -o filenames ${__grub_get_kernel_settings_program}
d9d99f
+unset __grub_get_kernel_settings_program
d9d99f
+
d9d99f
+
d9d99f
 #
d9d99f
 # grub-install
d9d99f
 #
d9d99f
diff --git a/util/grub-get-kernel-settings.3 b/util/grub-get-kernel-settings.3
d9d99f
new file mode 100644
d9d99f
index 00000000000..ba33330e28d
d9d99f
--- /dev/null
d9d99f
+++ b/util/grub-get-kernel-settings.3
d9d99f
@@ -0,0 +1,20 @@
d9d99f
+.TH GRUB-GET-KERNEL-SETTINGS 3 "Thu Jun 25 2015"
d9d99f
+.SH NAME
d9d99f
+\fBgrub-get-kernel-settings\fR \(em Evaluate the system's kernel installation settings for use while making a grub configuration file.
d9d99f
+
d9d99f
+.SH SYNOPSIS
d9d99f
+\fBgrub-get-kernel-settings\fR [OPTION]
d9d99f
+
d9d99f
+.SH DESCRIPTION
d9d99f
+\fBgrub-get-kernel-settings\fR reads the kernel installation settings on the host system, and emits a set of grub settings suitable for use when creating a grub configuration file.
d9d99f
+
d9d99f
+.SH OPTIONS
d9d99f
+.TP
d9d99f
+-h, --help
d9d99f
+Display program usage and exit.
d9d99f
+.TP
d9d99f
+-v, --version
d9d99f
+Display the current version.
d9d99f
+
d9d99f
+.SH SEE ALSO
d9d99f
+.BR "info grub"
d9d99f
diff --git a/util/grub-get-kernel-settings.in b/util/grub-get-kernel-settings.in
d9d99f
new file mode 100644
d9d99f
index 00000000000..12046219878
d9d99f
--- /dev/null
d9d99f
+++ b/util/grub-get-kernel-settings.in
d9d99f
@@ -0,0 +1,78 @@
d9d99f
+#!/bin/sh
d9d99f
+set -e
d9d99f
+
d9d99f
+# Evaluate new-kernel-pkg's configuration file.
d9d99f
+# Copyright (C) 2016 Free Software Foundation, Inc.
d9d99f
+#
d9d99f
+# GRUB is free software: you can redistribute it and/or modify
d9d99f
+# it under the terms of the GNU General Public License as published by
d9d99f
+# the Free Software Foundation, either version 3 of the License, or
d9d99f
+# (at your option) any later version.
d9d99f
+#
d9d99f
+# GRUB is distributed in the hope that it will be useful,
d9d99f
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
d9d99f
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
d9d99f
+# GNU General Public License for more details.
d9d99f
+#
d9d99f
+# You should have received a copy of the GNU General Public License
d9d99f
+# along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
d9d99f
+
d9d99f
+PACKAGE_NAME=@PACKAGE_NAME@
d9d99f
+PACKAGE_VERSION=@PACKAGE_VERSION@
d9d99f
+datadir="@datadir@"
d9d99f
+if [ "x$pkgdatadir" = x ]; then
d9d99f
+    pkgdatadir="${datadir}/@PACKAGE@"
d9d99f
+fi
d9d99f
+
d9d99f
+self=`basename $0`
d9d99f
+
d9d99f
+export TEXTDOMAIN=@PACKAGE@
d9d99f
+export TEXTDOMAINDIR="@localedir@"
d9d99f
+
d9d99f
+. "${pkgdatadir}/grub-mkconfig_lib"
d9d99f
+
d9d99f
+# Usage: usage
d9d99f
+# Print the usage.
d9d99f
+usage () {
d9d99f
+    gettext_printf "Usage: %s [OPTION]\n" "$self"
d9d99f
+    gettext "Evaluate new-kernel-pkg configuration"; echo
d9d99f
+    echo
d9d99f
+    print_option_help "-h, --help" "$(gettext "print this message and exit")"
d9d99f
+    print_option_help "-v, --version" "$(gettext "print the version information and exit")"
d9d99f
+    echo
d9d99f
+}
d9d99f
+
d9d99f
+# Check the arguments.
d9d99f
+while test $# -gt 0
d9d99f
+do
d9d99f
+    option=$1
d9d99f
+    shift
d9d99f
+
d9d99f
+    case "$option" in
d9d99f
+    -h | --help)
d9d99f
+	usage
d9d99f
+	exit 0 ;;
d9d99f
+    -v | --version)
d9d99f
+	echo "$self (${PACKAGE_NAME}) ${PACKAGE_VERSION}"
d9d99f
+	exit 0 ;;
d9d99f
+    -*)
d9d99f
+	gettext_printf "Unrecognized option \`%s'\n" "$option" 1>&2
d9d99f
+	usage
d9d99f
+	exit 1
d9d99f
+	;;
d9d99f
+    # Explicitly ignore non-option arguments, for compatibility.
d9d99f
+    esac
d9d99f
+done
d9d99f
+
d9d99f
+if test -f /etc/sysconfig/kernel ; then
d9d99f
+    . /etc/sysconfig/kernel
d9d99f
+fi
d9d99f
+
d9d99f
+if [ "$MAKEDEBUG" = "yes" ]; then
d9d99f
+    echo GRUB_LINUX_MAKE_DEBUG=true
d9d99f
+    echo export GRUB_LINUX_MAKE_DEBUG
d9d99f
+    echo GRUB_CMDLINE_LINUX_DEBUG=\"systemd.log_level=debug systemd.log_target=kmsg\"
d9d99f
+    echo export GRUB_CMDLINE_LINUX_DEBUG
d9d99f
+    echo GRUB_LINUX_DEBUG_TITLE_POSTFIX=\" with debugging\"
d9d99f
+    echo export GRUB_LINUX_DEBUG_TITLE_POSTFIX
d9d99f
+fi
d9d99f
diff --git a/util/grub-mkconfig.in b/util/grub-mkconfig.in
d9d99f
index bdb9982aefb..8218f3d477f 100644
d9d99f
--- a/util/grub-mkconfig.in
d9d99f
+++ b/util/grub-mkconfig.in
d9d99f
@@ -45,6 +45,7 @@ grub_probe="${sbindir}/@grub_probe@"
d9d99f
 grub_file="${bindir}/@grub_file@"
d9d99f
 grub_editenv="${bindir}/@grub_editenv@"
d9d99f
 grub_script_check="${bindir}/@grub_script_check@"
d9d99f
+grub_get_kernel_settings="${sbindir}/@grub_get_kernel_settings@"
d9d99f
 
d9d99f
 export TEXTDOMAIN=@PACKAGE@
d9d99f
 export TEXTDOMAINDIR="@localedir@"
d9d99f
@@ -158,6 +159,8 @@ if test -f ${sysconfdir}/default/grub ; then
d9d99f
   . ${sysconfdir}/default/grub
d9d99f
 fi
d9d99f
 
d9d99f
+eval "$("${grub_get_kernel_settings}")" || true
d9d99f
+
d9d99f
 if [ "x$GRUB_DISABLE_UUID" != "xtrue" ]; then
d9d99f
   if [ -z "$GRUB_DEVICE_UUID" ]; then
d9d99f
     GRUB_DEVICE_UUID="$GRUB_DEVICE_UUID_GENERATED"
d9d99f
diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in
d9d99f
index a8a8e2cf325..4e49ccdf742 100644
d9d99f
--- a/util/grub.d/10_linux.in
d9d99f
+++ b/util/grub.d/10_linux.in
d9d99f
@@ -111,7 +111,8 @@ linux_entry ()
d9d99f
   os="$1"
d9d99f
   version="$2"
d9d99f
   type="$3"
d9d99f
-  args="$4"
d9d99f
+  isdebug="$4"
d9d99f
+  args="$5"
d9d99f
 
d9d99f
   if [ -z "$boot_device_id" ]; then
d9d99f
       boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")"
d9d99f
@@ -123,6 +124,9 @@ linux_entry ()
d9d99f
 	  quoted="$(echo "$GRUB_ACTUAL_DEFAULT" | grub_quote)"
d9d99f
 	  title_correction_code="${title_correction_code}if [ \"x\$default\" = '$quoted' ]; then default='$(echo "$replacement_title" | grub_quote)'; fi;"
d9d99f
       fi
d9d99f
+      if [ x$isdebug = xdebug ]; then
d9d99f
+	  title="$title${GRUB_LINUX_DEBUG_TITLE_POSTFIX}"
d9d99f
+      fi
d9d99f
       echo "menuentry '$(echo "$title" | grub_quote)' ${CLASS} \$menuentry_id_option 'gnulinux-$version-$type-$boot_device_id' {" | sed "s/^/$submenu_indentation/"
d9d99f
   else
d9d99f
       echo "menuentry '$(echo "$os" | grub_quote)' ${CLASS} \$menuentry_id_option 'gnulinux-simple-$boot_device_id' {" | sed "s/^/$submenu_indentation/"
d9d99f
@@ -295,11 +299,15 @@ while [ "x$list" != "x" ] ; do
d9d99f
   fi
d9d99f
 
d9d99f
   if [ "x$is_top_level" = xtrue ] && [ "x${GRUB_DISABLE_SUBMENU}" != xtrue ]; then
d9d99f
-    linux_entry "${OS}" "${version}" simple \
d9d99f
+    linux_entry "${OS}" "${version}" simple standard \
d9d99f
     "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}"
d9d99f
+    if [ "x$GRUB_LINUX_MAKE_DEBUG" = "xtrue" ]; then
d9d99f
+      linux_entry "${OS}" "${version}" simple debug \
d9d99f
+        "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT} ${GRUB_CMDLINE_LINUX_DEBUG}"
d9d99f
+    fi
d9d99f
 
d9d99f
     submenu_indentation="$grub_tab"
d9d99f
-    
d9d99f
+
d9d99f
     if [ -z "$boot_device_id" ]; then
d9d99f
 	boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")"
d9d99f
     fi
d9d99f
@@ -308,10 +316,15 @@ while [ "x$list" != "x" ] ; do
d9d99f
     is_top_level=false
d9d99f
   fi
d9d99f
 
d9d99f
-  linux_entry "${OS}" "${version}" advanced \
d9d99f
+  linux_entry "${OS}" "${version}" advanced standard \
d9d99f
               "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}"
d9d99f
+  if [ "x$GRUB_LINUX_MAKE_DEBUG" = "xtrue" ]; then
d9d99f
+    linux_entry "${OS}" "${version}" advanced debug \
d9d99f
+                "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT} ${GRUB_CMDLINE_LINUX_DEBUG}"
d9d99f
+  fi
d9d99f
+
d9d99f
   if [ "x${GRUB_DISABLE_RECOVERY}" != "xtrue" ]; then
d9d99f
-    linux_entry "${OS}" "${version}" recovery \
d9d99f
+    linux_entry "${OS}" "${version}" recovery standard \
d9d99f
                 "single ${GRUB_CMDLINE_LINUX}"
d9d99f
   fi
d9d99f