initramfs-fsck-hook: bump version and improve error handling

Message ID 20240906093927.1814962-1-kumar.rakesh@siemens.com
State Superseded, archived
Headers show
Series initramfs-fsck-hook: bump version and improve error handling | expand

Commit Message

Rakesh Kumar Sept. 6, 2024, 9:39 a.m. UTC
* Bump initramfs-fsck-hook version from 0.2 to 0.3.
* Renamed the package from initramfs-fsck-hook-ext4 to initramfs-fsck-ext4
  for better readability.
* Improved error handling in the hook script by introducing the
  hook_error() function to handle failures during copy_exec calls.
* Corrected the path for fsck from /sbin/fsck to /usr/sbin/fsck to
  reflect the correct location of the binary.

The script now provides clear error messages and exits on failure,
preventing silent errors during the initramfs setup.

Signed-off-by: Rakesh Kumar <kumar.rakesh@siemens.com>
---
 ...sck.ext4.hook => initramfs-fsck-ext4.hook} | 21 +++++++------------
 ....triggers => initramfs-fsck-ext4.triggers} |  0
 .../initramfs-fsck-ext4_0.3.bb                | 19 +++++++++++++++++
 .../initramfs-fsck-hook-ext4_0.2.bb           | 18 ----------------
 4 files changed, 26 insertions(+), 32 deletions(-)
 rename meta/recipes-support/initramfs-fsck-hook/files/{initramfs.fsck.ext4.hook => initramfs-fsck-ext4.hook} (51%)
 rename meta/recipes-support/initramfs-fsck-hook/files/{initramfs-fsck-hook-ext4.triggers => initramfs-fsck-ext4.triggers} (100%)
 create mode 100644 meta/recipes-support/initramfs-fsck-hook/initramfs-fsck-ext4_0.3.bb
 delete mode 100644 meta/recipes-support/initramfs-fsck-hook/initramfs-fsck-hook-ext4_0.2.bb

Comments

Jan Kiszka Sept. 6, 2024, 9:56 a.m. UTC | #1
On 06.09.24 11:39, Rakesh Kumar wrote:
> * Bump initramfs-fsck-hook version from 0.2 to 0.3.
> * Renamed the package from initramfs-fsck-hook-ext4 to initramfs-fsck-ext4
>   for better readability.
> * Improved error handling in the hook script by introducing the
>   hook_error() function to handle failures during copy_exec calls.
> * Corrected the path for fsck from /sbin/fsck to /usr/sbin/fsck to
>   reflect the correct location of the binary.

4 topics, 4 patches. Well, maybe 3. But not just 1.

Jan

> 
> The script now provides clear error messages and exits on failure,
> preventing silent errors during the initramfs setup.
> 
> Signed-off-by: Rakesh Kumar <kumar.rakesh@siemens.com>
> ---
>  ...sck.ext4.hook => initramfs-fsck-ext4.hook} | 21 +++++++------------
>  ....triggers => initramfs-fsck-ext4.triggers} |  0
>  .../initramfs-fsck-ext4_0.3.bb                | 19 +++++++++++++++++
>  .../initramfs-fsck-hook-ext4_0.2.bb           | 18 ----------------
>  4 files changed, 26 insertions(+), 32 deletions(-)
>  rename meta/recipes-support/initramfs-fsck-hook/files/{initramfs.fsck.ext4.hook => initramfs-fsck-ext4.hook} (51%)
>  rename meta/recipes-support/initramfs-fsck-hook/files/{initramfs-fsck-hook-ext4.triggers => initramfs-fsck-ext4.triggers} (100%)
>  create mode 100644 meta/recipes-support/initramfs-fsck-hook/initramfs-fsck-ext4_0.3.bb
>  delete mode 100644 meta/recipes-support/initramfs-fsck-hook/initramfs-fsck-hook-ext4_0.2.bb
> 
> diff --git a/meta/recipes-support/initramfs-fsck-hook/files/initramfs.fsck.ext4.hook b/meta/recipes-support/initramfs-fsck-hook/files/initramfs-fsck-ext4.hook
> similarity index 51%
> rename from meta/recipes-support/initramfs-fsck-hook/files/initramfs.fsck.ext4.hook
> rename to meta/recipes-support/initramfs-fsck-hook/files/initramfs-fsck-ext4.hook
> index 259b73b4..e81f06f9 100644
> --- a/meta/recipes-support/initramfs-fsck-hook/files/initramfs.fsck.ext4.hook
> +++ b/meta/recipes-support/initramfs-fsck-hook/files/initramfs-fsck-ext4.hook
> @@ -5,8 +5,6 @@
>  
>  #!/bin/sh
>  
> -set -e
> -
>  PREREQ=""
>  
>  prereqs()
> @@ -24,16 +22,11 @@ esac
>  . /usr/share/initramfs-tools/scripts/functions
>  . /usr/share/initramfs-tools/hook-functions
>  
> -if [ ! -x /sbin/fsck ]; then
> -	echo "Warning: couldn't find /sbin/fsck!"
> -	exit 0
> -fi
> -
> -copy_exec /sbin/fsck
> -copy_exec /sbin/logsave
> +hook_error() {
> +    echo "(ERROR): $1" >&2
> +    exit 1
> +}
>  
> -if prog="$(command -v fsck.ext4)"; then
> -  copy_exec "$prog"
> -else
> -  echo "Warning: /sbin/fsck.ext4 doesn't exist, can't install to initramfs, ignoring."
> -fi
> +copy_exec /usr/sbin/fsck || hook_error "Unable to copy /usr/sbin/fsck"
> +copy_exec /usr/sbin/logsave || hook_error "Unable to copy /usr/sbin/logsave"
> +copy_exec /usr/sbin/fsck.ext4 || hook_error "Unable to copy /usr/sbin/fsck.ext4"
> diff --git a/meta/recipes-support/initramfs-fsck-hook/files/initramfs-fsck-hook-ext4.triggers b/meta/recipes-support/initramfs-fsck-hook/files/initramfs-fsck-ext4.triggers
> similarity index 100%
> rename from meta/recipes-support/initramfs-fsck-hook/files/initramfs-fsck-hook-ext4.triggers
> rename to meta/recipes-support/initramfs-fsck-hook/files/initramfs-fsck-ext4.triggers
> diff --git a/meta/recipes-support/initramfs-fsck-hook/initramfs-fsck-ext4_0.3.bb b/meta/recipes-support/initramfs-fsck-hook/initramfs-fsck-ext4_0.3.bb
> new file mode 100644
> index 00000000..c2136f9d
> --- /dev/null
> +++ b/meta/recipes-support/initramfs-fsck-hook/initramfs-fsck-ext4_0.3.bb
> @@ -0,0 +1,19 @@
> +# This software is a part of ISAR.
> +# Copyright (C) Siemens AG, 2019
> +#
> +# SPDX-License-Identifier: MIT
> +
> +
> +DESCRIPTION = "Recipe to add fsck hook to the initramfs"
> +
> +DEBIAN_DEPENDS   = "e2fsprogs,initramfs-tools"
> +
> +inherit dpkg-raw
> +SRC_URI = "file://${PN}.triggers    \
> +           file://${PN}.hook        \
> +          "
> +do_install[cleandirs] += "${D}/etc/initramfs-tools/hooks"
> +
> +do_install() {
> +        install -m 0755 ${WORKDIR}/${PN}.hook ${D}/etc/initramfs-tools/hooks/
> +}
> diff --git a/meta/recipes-support/initramfs-fsck-hook/initramfs-fsck-hook-ext4_0.2.bb b/meta/recipes-support/initramfs-fsck-hook/initramfs-fsck-hook-ext4_0.2.bb
> deleted file mode 100644
> index 9860dbc8..00000000
> --- a/meta/recipes-support/initramfs-fsck-hook/initramfs-fsck-hook-ext4_0.2.bb
> +++ /dev/null
> @@ -1,18 +0,0 @@
> -# This software is a part of ISAR.
> -# Copyright (C) Siemens AG, 2019
> -#
> -# SPDX-License-Identifier: MIT
> -
> -
> -DESCRIPTION = "Recipe to add fsck hook to the initramfs"
> -
> -inherit dpkg-raw
> -SRC_URI = "file://initramfs-fsck-hook-ext4.triggers \
> -           file://initramfs.fsck.ext4.hook \
> -          "
> -
> -
> -do_install() {
> -        install -m 0755 -d ${D}/etc/initramfs-tools/hooks
> -        install -m 0740 ${WORKDIR}/initramfs.fsck.ext4.hook ${D}/etc/initramfs-tools/hooks/fsck.ext4.hook
> -}

Patch

diff --git a/meta/recipes-support/initramfs-fsck-hook/files/initramfs.fsck.ext4.hook b/meta/recipes-support/initramfs-fsck-hook/files/initramfs-fsck-ext4.hook
similarity index 51%
rename from meta/recipes-support/initramfs-fsck-hook/files/initramfs.fsck.ext4.hook
rename to meta/recipes-support/initramfs-fsck-hook/files/initramfs-fsck-ext4.hook
index 259b73b4..e81f06f9 100644
--- a/meta/recipes-support/initramfs-fsck-hook/files/initramfs.fsck.ext4.hook
+++ b/meta/recipes-support/initramfs-fsck-hook/files/initramfs-fsck-ext4.hook
@@ -5,8 +5,6 @@ 
 
 #!/bin/sh
 
-set -e
-
 PREREQ=""
 
 prereqs()
@@ -24,16 +22,11 @@  esac
 . /usr/share/initramfs-tools/scripts/functions
 . /usr/share/initramfs-tools/hook-functions
 
-if [ ! -x /sbin/fsck ]; then
-	echo "Warning: couldn't find /sbin/fsck!"
-	exit 0
-fi
-
-copy_exec /sbin/fsck
-copy_exec /sbin/logsave
+hook_error() {
+    echo "(ERROR): $1" >&2
+    exit 1
+}
 
-if prog="$(command -v fsck.ext4)"; then
-  copy_exec "$prog"
-else
-  echo "Warning: /sbin/fsck.ext4 doesn't exist, can't install to initramfs, ignoring."
-fi
+copy_exec /usr/sbin/fsck || hook_error "Unable to copy /usr/sbin/fsck"
+copy_exec /usr/sbin/logsave || hook_error "Unable to copy /usr/sbin/logsave"
+copy_exec /usr/sbin/fsck.ext4 || hook_error "Unable to copy /usr/sbin/fsck.ext4"
diff --git a/meta/recipes-support/initramfs-fsck-hook/files/initramfs-fsck-hook-ext4.triggers b/meta/recipes-support/initramfs-fsck-hook/files/initramfs-fsck-ext4.triggers
similarity index 100%
rename from meta/recipes-support/initramfs-fsck-hook/files/initramfs-fsck-hook-ext4.triggers
rename to meta/recipes-support/initramfs-fsck-hook/files/initramfs-fsck-ext4.triggers
diff --git a/meta/recipes-support/initramfs-fsck-hook/initramfs-fsck-ext4_0.3.bb b/meta/recipes-support/initramfs-fsck-hook/initramfs-fsck-ext4_0.3.bb
new file mode 100644
index 00000000..c2136f9d
--- /dev/null
+++ b/meta/recipes-support/initramfs-fsck-hook/initramfs-fsck-ext4_0.3.bb
@@ -0,0 +1,19 @@ 
+# This software is a part of ISAR.
+# Copyright (C) Siemens AG, 2019
+#
+# SPDX-License-Identifier: MIT
+
+
+DESCRIPTION = "Recipe to add fsck hook to the initramfs"
+
+DEBIAN_DEPENDS   = "e2fsprogs,initramfs-tools"
+
+inherit dpkg-raw
+SRC_URI = "file://${PN}.triggers    \
+           file://${PN}.hook        \
+          "
+do_install[cleandirs] += "${D}/etc/initramfs-tools/hooks"
+
+do_install() {
+        install -m 0755 ${WORKDIR}/${PN}.hook ${D}/etc/initramfs-tools/hooks/
+}
diff --git a/meta/recipes-support/initramfs-fsck-hook/initramfs-fsck-hook-ext4_0.2.bb b/meta/recipes-support/initramfs-fsck-hook/initramfs-fsck-hook-ext4_0.2.bb
deleted file mode 100644
index 9860dbc8..00000000
--- a/meta/recipes-support/initramfs-fsck-hook/initramfs-fsck-hook-ext4_0.2.bb
+++ /dev/null
@@ -1,18 +0,0 @@ 
-# This software is a part of ISAR.
-# Copyright (C) Siemens AG, 2019
-#
-# SPDX-License-Identifier: MIT
-
-
-DESCRIPTION = "Recipe to add fsck hook to the initramfs"
-
-inherit dpkg-raw
-SRC_URI = "file://initramfs-fsck-hook-ext4.triggers \
-           file://initramfs.fsck.ext4.hook \
-          "
-
-
-do_install() {
-        install -m 0755 -d ${D}/etc/initramfs-tools/hooks
-        install -m 0740 ${WORKDIR}/initramfs.fsck.ext4.hook ${D}/etc/initramfs-tools/hooks/fsck.ext4.hook
-}