From: Uladzimir Bely <ubely@ilbers.de>
To: isar-users@googlegroups.com, Jan Kiszka <jan.kiszka@siemens.com>
Subject: Re: [PATCH] expand-on-first-boot: Fix early exit in helper script
Date: Fri, 10 Jun 2022 10:13:54 +0300 [thread overview]
Message-ID: <2415021.XAFRqVoOGU@home> (raw)
In-Reply-To: <3e329667-190f-0021-0b98-4b82b065e0b6@siemens.com>
[-- Attachment #1: Type: text/plain, Size: 2615 bytes --]
In the email from Friday, 10 June 2022 08:14:19 +03 user Jan Kiszka wrote:
> On 10.06.22 05:19, Uladzimir Bely wrote:
> > Changes in 342a751e introduced a regression when error from 'find'
> > makes helper script early exit (with -1 error code) just after an
> > attempt to assign ROOT_DEV_SLAVE variable. So, the last partition
> > remained not resized.
> >
> > Passing 'find' output to 'head -1' masks possible error from 'find'
> > without breaking the logic and continues the script execution.
> >
> > Signed-off-by: Uladzimir Bely <ubely@ilbers.de>
> > ---
> >
> > .../expand-on-first-boot/files/expand-last-partition.sh | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git
> > a/meta/recipes-support/expand-on-first-boot/files/expand-last-partition.s
> > h
> > b/meta/recipes-support/expand-on-first-boot/files/expand-last-partition.s
> > h index f3e29a1c..934a014f 100755
> > ---
> > a/meta/recipes-support/expand-on-first-boot/files/expand-last-partition.s
> > h +++
> > b/meta/recipes-support/expand-on-first-boot/files/expand-last-partition.s
> > h @@ -11,7 +11,7 @@ set -e
> >
> > ROOT_DEV="$(findmnt / -o source -n)"
> > ROOT_DEV_NAME=${ROOT_DEV##*/}
> >
> > -ROOT_DEV_SLAVE=$(find /sys/block/"${ROOT_DEV_NAME}"/slaves -mindepth 1
> > -print -quit 2>/dev/null) +ROOT_DEV_SLAVE=$(find
> > /sys/block/"${ROOT_DEV_NAME}"/slaves -mindepth 1 -print -quit 2>/dev/null
> > | head -1)>
> > if [ -n "${ROOT_DEV_SLAVE}" ]; then
> >
> > ROOT_DEV=/dev/${ROOT_DEV_SLAVE##*/}
> >
> > fi
>
> "-quit" is supposed to obsolete "head -1". Feel free to prove me wrong,
> but that was the reason for dropping it.
>
> Jan
Yes, "-quit" makes 'find' to exit after first match. But if nothing found, the return code of 'find' is
"-1" and due to script's "set -e" it just exits.
An example that demonstrates the behaviour (on raspberry):
root@isar:~# cat /boot/test.sh
#!/bin/sh
set -e
echo "1: start"
ROOT_DEV="$(findmnt / -o source -n)"
echo "2: ROOT_DEV=${ROOT_DEV}"
ROOT_DEV_NAME=${ROOT_DEV##*/}
echo "3: ROOT_DEV_NAME=${ROOT_DEV_NAME}"
ROOT_DEV_SLAVE=$(find /sys/block/"${ROOT_DEV_NAME}"/slaves -mindepth 1 -print -quit
2>/dev/null)
echo "4: ROOT_DEV_SLAVE=${ROOT_DEV_SLAVE}"
root@isar:~# sh /boot/test.sh
1: start
2: ROOT_DEV=/dev/mmcblk0p2
3: ROOT_DEV_NAME=mmcblk0p2
root@isar:~# echo $?
1
root@isar:~# ls /sys/block/ | grep mmc
mmcblk0
root@isar:~#
So, the easiest way to mask error returned by 'find' is to use something like 'head -1' or 'tee /
dev/null'. In this case script just continues with empty ROOT_DEV_SLAVE.
--
Uladzimir Bely
[-- Attachment #2: Type: text/html, Size: 7241 bytes --]
next prev parent reply other threads:[~2022-06-10 7:14 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-10 3:19 Uladzimir Bely
2022-06-10 5:14 ` Jan Kiszka
2022-06-10 7:13 ` Uladzimir Bely [this message]
2022-06-10 9:32 ` Henning Schild
2022-06-10 10:03 ` Uladzimir Bely
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2415021.XAFRqVoOGU@home \
--to=ubely@ilbers.de \
--cc=isar-users@googlegroups.com \
--cc=jan.kiszka@siemens.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox