From 184217373b42e74cec8573632119c6e4c1cb2f83 Mon Sep 17 00:00:00 2001 From: "Guilherme G. Piccoli" Date: Thu, 24 Nov 2022 19:29:18 -0300 Subject: [PATCH] all: Allow multiple config files This is somewhat an intrusive change, but necessary if we want to upstream the kdump tooling while allowing great extent of customizations on SteamOS. With this change, we have now a kdump.d folder on /usr/share, that holds configuration files in the same way sysctl.d does. In other words, we can easily override default settings by just having more configuration files, which are sourced following natural name sorting, i.e., we have now the concept of config file precedence in kdump. Our default config file is called 00-default, so we eventually might have a 01-steamos e.g., with Deck's custom settings. This is planned to other package though. Signed-off-by: Guilherme G. Piccoli --- kdump.conf => 00-default.conf | 0 Makefile | 2 +- kdump-collect.sh | 8 +++++++- kdump-load.sh | 18 +++++++++++++----- module-setup.sh | 31 ++++++++++++++++++++----------- save-dumps.sh | 21 ++++++++++++++------- 6 files changed, 55 insertions(+), 25 deletions(-) rename kdump.conf => 00-default.conf (100%) diff --git a/kdump.conf b/00-default.conf similarity index 100% rename from kdump.conf rename to 00-default.conf diff --git a/Makefile b/Makefile index 24de2f8..7e54172 100644 --- a/Makefile +++ b/Makefile @@ -20,4 +20,4 @@ install: all install -D -m0644 README.md $(DESTDIR)$(dracutmodulesdir)/55kdump/README install -D -m0755 kdump-load.sh $(DESTDIR)$(libdir)/kdump/kdump-load.sh install -D -m0755 save-dumps.sh $(DESTDIR)$(libdir)/kdump/save-dumps.sh - install -D -m0644 kdump.conf $(DESTDIR)$(sharedir)/kdump/kdump.conf + install -D -m0644 00-default.conf $(DESTDIR)$(sharedir)/kdump.d/00-default diff --git a/kdump-collect.sh b/kdump-collect.sh index 08d2ce0..488f277 100644 --- a/kdump-collect.sh +++ b/kdump-collect.sh @@ -13,7 +13,13 @@ # output for the user. # -. /usr/lib/kdump/kdump.conf +# We have a more controlled situation with regards the config +# files here, since we manually added them in the initrd and +# the validation also happened there, during such addition, +# hence not requiring checking here. +for cfg in "/usr/lib/kdump/conf/"/*; do + . "$cfg" +done VMCORE="/proc/vmcore" KDUMP_TIMESTAMP=$(date -u +"%Y%m%d%H%M") diff --git a/kdump-load.sh b/kdump-load.sh index 0fbab0c..39045f0 100644 --- a/kdump-load.sh +++ b/kdump-load.sh @@ -78,14 +78,22 @@ cleanup_unused_initrd() { rm -f "${INSTALLED_KERNELS}" } +# Load the necessary external variables, otherwise it'll fail later. +HAVE_CFG_FILES=0 +shopt -s nullglob +for cfg in "/usr/share/kdump.d"/*; do + if [ -f "$cfg" ]; then + . "$cfg" + HAVE_CFG_FILES=1 + fi +done +shopt -u nullglob -if [ ! -s "/usr/share/kdump/kdump.conf" ]; then - logger "kdump: /usr/share/kdump/kdump.conf is missing, aborting." - exit 0 +if [ ${HAVE_CFG_FILES} -eq 0 ]; then + logger "kdump: no config files in /usr/share/kdump.d/ - aborting." + exit 1 fi -. /usr/share/kdump/kdump.conf - # Find the proper mount point expected for kdump collection: DEVN_MOUNTED="$(findmnt "${MOUNT_DEVNODE}" -fno TARGET)" diff --git a/module-setup.sh b/module-setup.sh index 3fc2c3d..75016d1 100644 --- a/module-setup.sh +++ b/module-setup.sh @@ -19,20 +19,12 @@ installkernel() { } install() { - # Having a valid /usr/share/kdump/kdump.conf is essential for kdump. - if [ ! -s "/usr/share/kdump/kdump.conf" ]; then - logger "kdump: failed to create initrd, kdump.conf is missing" - exit 1 - fi - - # Also true for makedumpfile... + # A valid makedumpfile is essential for the kdump initrd creation. if [ ! -x "$(command -v makedumpfile)" ]; then logger "kdump: failed to create initrd, makedumpfile is missing" exit 1 fi - . /usr/share/kdump/kdump.conf - # First clear all unnecessary firmwares/drivers added by drm in order to # reduce the size of this minimal initramfs being created. This should # be already done via command-line arguments, but let's play safe and delete @@ -45,7 +37,25 @@ install() { inst sync inst makedumpfile - mkdir -p "$initdir"/usr/lib/kdump + mkdir -p "$initdir"/usr/lib/kdump/conf + + # Load the necessary external variables, otherwise it'll fail later. + HAVE_CFG_FILES=0 + shopt -s nullglob + for cfg in "/usr/share/kdump.d"/*; do + if [ -f "$cfg" ]; then + . "$cfg" + HAVE_CFG_FILES=1 + fi + done + shopt -u nullglob + + if [ ${HAVE_CFG_FILES} -eq 0 ]; then + logger "kdump: no config files in /usr/share/kdump.d/ - aborting." + exit 1 + fi + + cp -LR --preserve=all "/usr/share/kdump.d"/* "$initdir"/usr/lib/kdump/conf/ # Determine the numerical devnode for kdump, and save it on initrd; # notice that partset link is not available that early in boot time. @@ -53,7 +63,6 @@ install() { echo "${DEVN}" > "$initdir"/usr/lib/kdump/kdump.devnode cp -LR --preserve=all /usr/lib/kdump/* "$initdir"/usr/lib/kdump/ - cp -LR --preserve=all /usr/share/kdump/kdump.conf "$initdir"/usr/lib/kdump/kdump.conf inst_hook pre-mount 01 "$moddir/kdump-collect.sh" } diff --git a/save-dumps.sh b/save-dumps.sh index 2a55def..a4fc039 100644 --- a/save-dumps.sh +++ b/save-dumps.sh @@ -9,14 +9,21 @@ # collected data and save it in the local disk, in the next successful boot. # -# We do some validation to be sure KDUMP_MNT pointed path is valid... -# That and having a valid /usr/share/kdump/kdump.conf are essential conditions. -if [ ! -s "/usr/share/kdump/kdump.conf" ]; then - logger "kdump: /usr/share/kdump/kdump.conf is missing, aborting." - exit 0 -fi +# Load the necessary external variables, otherwise it'll fail later. +HAVE_CFG_FILES=0 +shopt -s nullglob +for cfg in "/usr/share/kdump.d"/*; do + if [ -f "$cfg" ]; then + . "$cfg" + HAVE_CFG_FILES=1 + fi +done +shopt -u nullglob -. /usr/share/kdump/kdump.conf +if [ ${HAVE_CFG_FILES} -eq 0 ]; then + logger "kdump: no config files in /usr/share/kdump.d/ - aborting." + exit 1 +fi KDUMP_MAIN_FOLDER="$(cat "${KDUMP_MNT}")" rm -f "${KDUMP_MNT}"