From mboxrd@z Thu Jan 1 00:00:00 1970 X-GM-THRID: 7107445708784926720 X-Received: by 2002:a25:22d5:0:b0:64f:f06c:d96c with SMTP id i204-20020a2522d5000000b0064ff06cd96cmr41059729ybi.123.1654845241155; Fri, 10 Jun 2022 00:14:01 -0700 (PDT) X-BeenThere: isar-users@googlegroups.com Received: by 2002:a05:6902:124d:b0:64f:75f1:6299 with SMTP id t13-20020a056902124d00b0064f75f16299ls4889432ybu.4.gmail; Fri, 10 Jun 2022 00:14:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxlfmR9yjujUYX7U+gtAWYClgzy9pLQ8Mo0ciIMNyRkH/UYfVGnPPpIaPM6gAo/s2Srtsoo X-Received: by 2002:a05:6902:1009:b0:663:93ab:10b with SMTP id w9-20020a056902100900b0066393ab010bmr26406326ybt.356.1654845240417; Fri, 10 Jun 2022 00:14:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654845240; cv=none; d=google.com; s=arc-20160816; b=Ew4IOM2pJOsWlsPXWAWQxHhvRMYDvu4C/lCK9jwdIveWsrZavM70oUvVhw48FLcm1e MP4uQ7XPSfkCgXyAIcqb4HYJOCPIkqJYXfoP7I16lTg1F6L9G/rMqud1tIfB7lTDUbEE lgF7dTONgmPIMkfq6fbvoLA0Qq/spDYtCzReSdlNEe91q8kfRNHVzWE76RV7dK06UCjr 8wvbCCx27KcehIzIi6sLvZnnxAV9FFoldGw9ZlLBl39m9EkD3DOgKzXRyBgUgGLwhA5Z X+Cq0acPYAwrWEjDxRLrh9yisZr6FGWujMz5iPttRvahj0ibGRGok+iofRo20NGaoEWk pwoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from; bh=j4OiR5Ko/QkZ/Gif/ErX2YcWd4OijlmTu0EjgOaVLuc=; b=BTlDHmIDd9k+rAQzLbDKC48khQySQU5e10/tHvBjKfCXtUMaRgy56JzTNpb0AbwQFF HyPfNozWLj9S7F/EcOMPYhQMyPEQLh4odmyBb509AgatOtQdQ8HWtBZtYaUMXyhm9Mlc iQe1YTRMcen2jKHbGXtpeqMB9kBwMTgZWCWlUn2tXU2oX//jZizbH1RLwaEyPcV03LfJ q83qyEyd4wlCkeVG/O5v+cmsIb+9zug+UHaEAnmZuhC1VwHUyU56Tpo9G6YkNnadMpVS JB/yak9wPa1MjwX9T9fYukC8uVwaUtoe2bUrfB3t8P3HLZNxU4+h28mT1MqUPGhUOygC H+fg== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=pass (google.com: domain of ubely@ilbers.de designates 85.214.156.166 as permitted sender) smtp.mailfrom=ubely@ilbers.de Return-Path: Received: from shymkent.ilbers.de (shymkent.ilbers.de. [85.214.156.166]) by gmr-mx.google.com with ESMTPS id 15-20020a81130f000000b0030c468b7bd1si2214715ywt.1.2022.06.10.00.13.59 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 10 Jun 2022 00:14:00 -0700 (PDT) Received-SPF: pass (google.com: domain of ubely@ilbers.de designates 85.214.156.166 as permitted sender) client-ip=85.214.156.166; Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of ubely@ilbers.de designates 85.214.156.166 as permitted sender) smtp.mailfrom=ubely@ilbers.de Received: from home.localnet (44-208-124-178-static.mgts.by [178.124.208.44] (may be forged)) (authenticated bits=0) by shymkent.ilbers.de (8.15.2/8.15.2/Debian-8+deb9u1) with ESMTPSA id 25A7Dujb012881 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 10 Jun 2022 09:13:57 +0200 From: Uladzimir Bely To: isar-users@googlegroups.com, Jan Kiszka Subject: Re: [PATCH] expand-on-first-boot: Fix early exit in helper script Date: Fri, 10 Jun 2022 10:13:54 +0300 Message-ID: <2415021.XAFRqVoOGU@home> In-Reply-To: <3e329667-190f-0021-0b98-4b82b065e0b6@siemens.com> References: <20220610031915.25529-1-ubely@ilbers.de> <3e329667-190f-0021-0b98-4b82b065e0b6@siemens.com> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="nextPart3432402.dWV9SEqChM" Content-Transfer-Encoding: 7Bit X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,HTML_MESSAGE autolearn=unavailable autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on shymkent.ilbers.de X-TUID: lJLPJZR+kZ/p This is a multi-part message in MIME format. --nextPart3432402.dWV9SEqChM Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="iso-8859-1" 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 > > --- > > > > .../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 --nextPart3432402.dWV9SEqChM Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset="iso-8859-1"

In the email from Friday, 10 June 2022 08:14:19 +03 user Jan Kiszka wrot= e:

>= ; 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'<= /p>

>= ; > 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 &= nbsp;       | 2 +-

>= ; >  1 file changed, 1 insertion(+), 1 deletion(-)

>= ; >

>= ; > diff --git

>= ; > a/meta/recipes-support/expand-on-first-boot/files/expand-last-partit= ion.s

>= ; > h

>= ; > b/meta/recipes-support/expand-on-first-boot/files/expand-last-partit= ion.s

>= ; > h index f3e29a1c..934a014f 100755

>= ; > ---

>= ; > a/meta/recipes-support/expand-on-first-boot/files/expand-last-partit= ion.s

>= ; > h +++

>= ; > b/meta/recipes-support/expand-on-first-boot/files/expand-last-partit= ion.s

>= ; > h @@ -11,7 +11,7 @@ set -e

>= ; >

>= ; >  ROOT_DEV=3D"$(findmnt / -o source -n)"

>= ; >  ROOT_DEV_NAME=3D${ROOT_DEV##*/}

>= ; >

>= ; > -ROOT_DEV_SLAVE=3D$(find /sys/block/"${ROOT_DEV_NAME}"/sla= ves -mindepth 1

>= ; > -print -quit 2>/dev/null) +ROOT_DEV_SLAVE=3D$(find

>= ; > /sys/block/"${ROOT_DEV_NAME}"/slaves -mindepth 1 -print -q= uit 2>/dev/null

>= ; > | head -1)>

>= ; >  if [ -n "${ROOT_DEV_SLAVE}" ]; then

>= ; > 

>= ; >      ROOT_DEV=3D/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 no= thing 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 =A0<= /span>
#!/bin/sh

set -e

echo &qu= ot;1: start"
ROOT_DEV=3D"$(findmnt / -o source -n)" echo "2: ROOT_DEV=3D${ROOT_DEV}"
ROOT_DEV_NAME=3D${ROOT= _DEV##*/}
echo "3: ROOT_DEV_NAME=3D${ROOT_DEV_NAME}"
= ROOT_DEV_SLAVE=3D$(find /sys/block/"${ROOT_DEV_NAME}"/slaves -min= depth 1 -print -quit 2>/dev/null)
echo "4: ROOT_DEV_SLAVE=3D$= {ROOT_DEV_SLAVE}"
root@isar:~# sh /boot/test.sh =A0
1: star= t
2: ROOT_DEV=3D/dev/mmcblk0p2
3: ROOT_DEV_NAME=3Dmmcblk0p2 root@isar:~# echo $?
1
root@isar:~# ls /sys/block/ | grep mm= c
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.


--

Ula= dzimir Bely


--nextPart3432402.dWV9SEqChM--