Skip to contentSkip to conversation

kbuild: Fix install errors when INSTALL_PATH does not exist

PATCH Superseded Zhang Bingwu 4 participants 10 messages Feb 10, 2024 – Feb 11, 2024 1 message not in the archive

Subsystems (10)
Arm (32-bit) x86 Kbuild RISC-V +6 more subsystems
lore
Share & tools
lore
#0 lore raw

cover kbuild: Fix install errors when INSTALL_PATH does not exist

From: Zhang Bingwu <[email protected]>

When running 'make zinstall INSTALL_PATH=somepath'
where 'somepath' does not exist, the install scripts (install.sh) print error messages
but also return a success status code.
This will make 'make' regard 'install' (and 'zinstall', etc)
succeeded.
When there are also other targets at the same time,
for example, 'make zinstall dtbs_install modules_install', make will keep going on and other outputs will fill stdout, and make the error message hard to find.

dtbs_install and modules_install creates the target directory
if it does not exist. install, zinstall and others should have the same behaviour.

If INSTALL_PATH is not a valid directory, we should create it. If the installation process still fails with errors, for example,
insufficient space on disk or permission denied, make should regard the install target failed, stop as soon as possible,
and exit with error.

Zhang Bingwu (2):
kbuild: Abort make on install failures
kbuild: Create INSTALL_PATH directory if it does not exist

 arch/arm/boot/install.sh   | 2 ++
 arch/arm64/boot/install.sh | 2 ++
 arch/m68k/install.sh       | 2 ++
 arch/nios2/boot/install.sh | 2 ++
 arch/parisc/install.sh     | 2 ++
 arch/riscv/boot/install.sh | 2 ++
 arch/s390/boot/install.sh  | 2 ++
 arch/sparc/boot/install.sh | 2 ++
 arch/x86/boot/install.sh   | 2 ++
 scripts/install.sh         | 4 ++++
 10 files changed, 22 insertions(+)

base-commit: d0f86d080e3d7d5e1e75a56d88daf8e5f56a4146

Signature · 1 line
2.43.0
#1 lore raw

PATCH 1/2 kbuild: Abort make on install failures

From: Zhang Bingwu <[email protected]>

Setting '-e' flag tells shells to exit with error exit code immediately after any of commands fails, and causes make(1) to regard recipes as failed.

Before this, make will still continue to succeed even after the installation failed, for example, for insufficient permission or directory does not exist.

---
 arch/arm/boot/install.sh   | 2 ++
 arch/arm64/boot/install.sh | 2 ++
 arch/m68k/install.sh       | 2 ++
 arch/nios2/boot/install.sh | 2 ++
 arch/parisc/install.sh     | 2 ++
 arch/riscv/boot/install.sh | 2 ++
 arch/s390/boot/install.sh  | 2 ++
 arch/sparc/boot/install.sh | 2 ++
 arch/x86/boot/install.sh   | 2 ++
 9 files changed, 18 insertions(+)
arch/arm/boot/install.sh +2 -0
index 9ec11fac7d8d..34e2c6e31fd1 100755
@@ -17,6 +17,8 @@
 #   $3 - kernel map file
 #   $4 - default install path (blank if root directory)
 
+set -e
+
 if [ "$(basename $2)" = "zImage" ]; then
 # Compressed install
   echo "Installing compressed kernel"
arch/arm64/boot/install.sh +2 -0
index 9b7a09808a3d..cc2f4ccca6c0 100755
@@ -17,6 +17,8 @@
 #   $3 - kernel map file
 #   $4 - default install path (blank if root directory)
 
+set -e
+
 if [ "$(basename $2)" = "Image.gz" ] || [ "$(basename $2)" = "vmlinuz.efi" ]
 then
 # Compressed install
arch/m68k/install.sh +2 -0
index af65e16e5147..b6829b3942b3 100755
@@ -16,6 +16,8 @@
 #   $3 - kernel map file
 #   $4 - default install path (blank if root directory)
 
+set -e
+
 if [ -f $4/vmlinuz ]; then
 	mv $4/vmlinuz $4/vmlinuz.old
 fi
arch/nios2/boot/install.sh +2 -0
index 34a2feec42c8..1161f2bf59ec 100755
@@ -16,6 +16,8 @@
 #   $3 - kernel map file
 #   $4 - default install path (blank if root directory)
 
+set -e
+
 if [ -f $4/vmlinuz ]; then
 	mv $4/vmlinuz $4/vmlinuz.old
 fi
arch/parisc/install.sh +2 -0
index 933d031c249a..664c2d77f776 100755
@@ -16,6 +16,8 @@
 #   $3 - kernel map file
 #   $4 - default install path (blank if root directory)
 
+set -e
+
 if [ "$(basename $2)" = "vmlinuz" ]; then
 # Compressed install
   echo "Installing compressed kernel"
arch/riscv/boot/install.sh +2 -0
index 4c63f3f0643d..a59639dff64f 100755
@@ -17,6 +17,8 @@
 #   $3 - kernel map file
 #   $4 - default install path (blank if root directory)
 
+set -e
+
 if [ "$(basename $2)" = "Image.gz" ]; then
 # Compressed install
   echo "Installing compressed kernel"
arch/s390/boot/install.sh +2 -0
index a13dd2f2aa1c..fa41486258ee 100755
@@ -15,6 +15,8 @@
 #   $3 - kernel map file
 #   $4 - default install path (blank if root directory)
 
+set -e
+
 echo "Warning: '${INSTALLKERNEL}' command not available - additional " \
      "bootloader config required" >&2
 if [ -f "$4/vmlinuz-$1" ]; then mv -- "$4/vmlinuz-$1" "$4/vmlinuz-$1.old"; fi
arch/sparc/boot/install.sh +2 -0
index 4f130f3f30d6..68de67c5621e 100755
@@ -16,6 +16,8 @@
 #   $3 - kernel map file
 #   $4 - default install path (blank if root directory)
 
+set -e
+
 if [ -f $4/vmlinuz ]; then
 	mv $4/vmlinuz $4/vmlinuz.old
 fi
arch/x86/boot/install.sh +2 -0
index 0849f4b42745..93784abcd66d 100755
@@ -16,6 +16,8 @@
 #   $3 - kernel map file
 #   $4 - default install path (blank if root directory)
 
+set -e
+
 if [ -f $4/vmlinuz ]; then
 	mv $4/vmlinuz $4/vmlinuz.old
 fi
Signature · 1 line
2.43.0
#2 lore raw

Re: [PATCH 1/2] kbuild: Abort make on install failures

Quoted 28 lines · Zhang Bingwu

From: Zhang Bingwu <[email protected]>

Setting '-e' flag tells shells to exit with error exit code immediately after any of commands fails, and causes make(1) to regard recipes as failed.

Before this, make will still continue to succeed even after the installation failed, for example, for insufficient permission or directory does not exist.

---
 arch/arm/boot/install.sh   | 2 ++
 arch/arm64/boot/install.sh | 2 ++
 arch/m68k/install.sh       | 2 ++
 arch/nios2/boot/install.sh | 2 ++
 arch/parisc/install.sh     | 2 ++
 arch/riscv/boot/install.sh | 2 ++
 arch/s390/boot/install.sh  | 2 ++
 arch/sparc/boot/install.sh | 2 ++
 arch/x86/boot/install.sh   | 2 ++
 9 files changed, 18 insertions(+)
arch/arm/boot/install.sh +0 -0
index 9ec11fac7d8d..34e2c6e31fd1 100755

arch/arm/boot/install.sh line 21

Quoted 5 lines
arch/arm/boot/install.sh +2 -0
@@ -17,6 +17,8 @@
 #   $3 - kernel map file
 #   $4 - default install path (blank if root directory)
 
+set -e
+

What about #!/bin/sh -e on the first line, which is the more normal way to do this for an entire script?

Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
author
#3 lore raw

Re: [PATCH 1/2] kbuild: Abort make on install failures

Quoted 2 lines · CST Russell King (Oracle)

What about #!/bin/sh -e on the first line, which is the more normal way to do this for an entire script?

Will do this in V2.

Signature · 1 line
xtex @ Sat Feb 10 10:32:32 AM UTC 2024
Reviewed-by
#4 lore raw

Re: [PATCH 1/2] kbuild: Abort make on install failures

In reply to Russell King (Oracle)
Quoted 7 lines · On Sat, Feb 10, 2024 at 10:29:00AM +0000 Russell King (Oracle) wrote:
Quoted 6 lines · Zhang Bingwu

From: Zhang Bingwu <[email protected]>

Setting '-e' flag tells shells to exit with error exit code immediately after any of commands fails, and causes make(1) to regard recipes as failed.

Quoted 6 lines
Quoted 6 lines

Before this, make will still continue to succeed even after the installation failed, for example, for insufficient permission or directory does not exist.

---

Thanks for fixing!

[...]

Quoted 8 lines
Quoted 8 lines
arch/arm/boot/install.sh +0 -0
index 9ec11fac7d8d..34e2c6e31fd1 100755
@@ -17,6 +17,8 @@
 #   $3 - kernel map file
 #   $4 - default install path (blank if root directory)
 
Quoted 5 lines

arch/arm/boot/install.sh line 21

Quoted 2 lines
arch/arm/boot/install.sh +2 -0
+set -e
+

What about #!/bin/sh -e on the first line, which is the more normal way to do this for an entire script?

are you sure? I can find many more occurrences of 'set -e' than the shebang version in the Linux tree, especially in the kbuild scripts, thus it's bike-shedding, isn't it?

Kind regards,
Nicolas

#5 lore raw

Re: [PATCH 1/2] kbuild: Abort make on install failures

Quoted 33 lines · Nicolas Schier
Quoted 7 lines · On Sat, Feb 10, 2024 at 10:29:00AM +0000 Russell King (Oracle) wrote:
Quoted 6 lines · Zhang Bingwu

From: Zhang Bingwu <[email protected]>

Setting '-e' flag tells shells to exit with error exit code immediately after any of commands fails, and causes make(1) to regard recipes as failed.

Quoted 6 lines
Quoted 6 lines

Before this, make will still continue to succeed even after the installation failed, for example, for insufficient permission or directory does not exist.

---

Thanks for fixing!

[...]

Quoted 8 lines
Quoted 8 lines
arch/arm/boot/install.sh +0 -0
index 9ec11fac7d8d..34e2c6e31fd1 100755
@@ -17,6 +17,8 @@
 #   $3 - kernel map file
 #   $4 - default install path (blank if root directory)
 
Quoted 5 lines

arch/arm/boot/install.sh line 21

Quoted 2 lines
arch/arm/boot/install.sh +2 -0
+set -e
+

What about #!/bin/sh -e on the first line, which is the more normal way to do this for an entire script?

Quoted 8 lines

are you sure? I can find many more occurrences of 'set -e' than the shebang version in the Linux tree, especially in the kbuild scripts, thus it's bike-shedding, isn't it?

Kind regards,
Nicolas

When you put -e on the shebang line, like

    #!/bin/sh -e

the option -e is set when you do:

    $ arch/arm/boot/install.sh

But, -e is not set when you do:

    $ sh arch/arm/boot/install.sh

The reason is obvious because the latter case
does not use the shebang line.

In Kbuild, some places run the script directly like the former case, and others use CONFIG_SHELL like

   $(CONFIG_SHELL) arch/arm/boot/install.sh

The inconsistency is not nice, but that is a different issue.

The separate 'set -e' statement works for both cases, so I think this is safer, though it is kind of bike-shedding.

Signature · 2 lines
Best Regards
Masahiro Yamada
author
#6 lore raw

Re: [PATCH 1/2] kbuild: Abort make on install failures

Quoted 3 lines · CST Masahiro Yamada

The separate 'set -e' statement works for both cases, so I think this is safer, though it is kind of bike-shedding.

Thanks!
I also think it is safer to use 'set -e' in the case of 'sh install.sh',
so I support not to use 'sh -e' in the shebang line. The planned V2 patch for
this disappeared.

Signature · 1 line
Zhang Bingwu @ Sun Feb 11 10:27:48 AM UTC 2024
#7 lore raw

PATCH 2/2 kbuild: Create INSTALL_PATH directory if it does not exist

In reply to Zhang Bingwu

From: Zhang Bingwu <[email protected]>

If INSTALL_PATH is not a valid directory, create it, like what modules_install and dtbs_install will do in the same situation.

---
 scripts/install.sh | 4 ++++
 1 file changed, 4 insertions(+)
scripts/install.sh +4 -0
index 9bb0fb44f04a..02b845e7ab33 100755
@@ -20,6 +20,10 @@ do
 	fi
 done
 
+if [ "${INSTALL_PATH}" != "" ] && ! [ -e "${INSTALL_PATH}" ]; then
+	mkdir -p "${INSTALL_PATH}"
+fi
+
 # User/arch may have a custom install script
 for file in "${HOME}/bin/${INSTALLKERNEL}"		\
 	    "/sbin/${INSTALLKERNEL}"			\
Signature · 1 line
2.43.0
Reviewed-by on v1 2/2
#8 lore raw

Re: [PATCH 2/2] kbuild: Create INSTALL_PATH directory if it does not exist

Quoted 28 lines · On Sat, Feb 10, 2024 at 03:46:01PM +0800 Zhang Bingwu wrote:

From: Zhang Bingwu <[email protected]>

If INSTALL_PATH is not a valid directory, create it, like what modules_install and dtbs_install will do in the same situation.

---
 scripts/install.sh | 4 ++++
 1 file changed, 4 insertions(+)
scripts/install.sh +4 -0
index 9bb0fb44f04a..02b845e7ab33 100755
@@ -20,6 +20,10 @@ do
 	fi
 done
 
+if [ "${INSTALL_PATH}" != "" ] && ! [ -e "${INSTALL_PATH}" ]; then
+	mkdir -p "${INSTALL_PATH}"
+fi
+
 # User/arch may have a custom install script
 for file in "${HOME}/bin/${INSTALLKERNEL}"		\
 	    "/sbin/${INSTALLKERNEL}"			\
Signature · 1 line
2.43.0

Thanks.

A message that is not in the archive (sent off-list or not yet received): [email protected]

#10 lore raw

Sorry I forgot to CC these patches to kbuild list.

Signature · 1 line
xtex @ Sat Feb 10 10:16:06 AM UTC 2024