From mboxrd@z Thu Jan 1 00:00:00 1970 X-GM-THRID: 7107445708784926720 X-Received: by 2002:ab0:2418:0:b0:373:6075:1d22 with SMTP id f24-20020ab02418000000b0037360751d22mr23534610uan.91.1654855421925; Fri, 10 Jun 2022 03:03:41 -0700 (PDT) X-BeenThere: isar-users@googlegroups.com Received: by 2002:a1f:7207:0:b0:35c:fabb:d313 with SMTP id n7-20020a1f7207000000b0035cfabbd313ls1900415vkc.5.gmail; Fri, 10 Jun 2022 03:03:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy38OL7XlUKcNYZc1aD/iO2wOXq6mFjFwbvjz+CgaMot4dUu1zWVBhVXNBdnJpUjzAwtO4Y X-Received: by 2002:a05:6122:c4f:b0:35d:b215:c795 with SMTP id i15-20020a0561220c4f00b0035db215c795mr12770958vkr.35.1654855421200; Fri, 10 Jun 2022 03:03:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654855421; cv=none; d=google.com; s=arc-20160816; b=qEjHr41VwYxlO4/qESjo/C4Yq1MgE8goPGg4fbhKIOybjhpcefQ+YMlpV5b4CmppYu ySSqmiq5W0psLO1fErAnypNAQzmknhcdHUfEnn2KUCKEToXHW/j3QERi6OPiUW7UVheA VaxYCabAhFLVqsmM4iutFuDc7Yfg8cKiEgw2jEClAEU0C6fTfnspHTEP3uS2yEFPj9vu xLCr2zghnzXmj2d1+Vbjw0D9bZ94VZV07a6fYcA5q0OYhEzwWPP272Oro8ASIyfWzvgm GQXbppP/7Wwy29D1dCHxlvSdI/QZX2Sp3TCZYhXKU4TC5rzk2g73mdn7r/nrf8g3osb7 zd/Q== 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:cc:to:from; bh=tfJglAn0R9NWLL9i9GYMtz3m765snnQwFW3yIyz2iAk=; b=oVZWof2yKyzBo58mrGYuv0LpcL+e/zaEQgbtS0zl4JeBmWchPSSM4XVqtxNpGW0SQF PCd1g6b5CFIcQja+H4s60DRENcMc8dSBw+OlmFU0vrJW269ExAIpybOI2P1GjyR8rOVS 7oOpFcE49weB5DQi+uSS+GDFe8WSHX3ALh2bgBsHtpMpjGkeCCa1YNEhNYmKG/AuaPIS PBmJb3L+gRhetaLMoAgiO7D5HPB1h9TUElf5gklhV3sKG28zw4409IzNjQ0JJb13UuvG m8VCsMf9b6yQyMPsFdX9oCQaTWM248FBGgi2H3B3PbmSMlEDwNPBNAMbvLCwW98qug/I PgcQ== 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 e17-20020a056122041100b003529b5015acsi1171490vkd.2.2022.06.10.03.03.40 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 10 Jun 2022 03:03:40 -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 25AA3bIe013586 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 10 Jun 2022 12:03:38 +0200 From: Uladzimir Bely To: Henning Schild Cc: isar-users@googlegroups.com, Jan Kiszka Subject: Re: [PATCH] expand-on-first-boot: Fix early exit in helper script Date: Fri, 10 Jun 2022 13:03:36 +0300 Message-ID: <4916772.Qq0lBPeGtt@home> In-Reply-To: <20220610113253.123f3f75@md1za8fc.ad001.siemens.net> References: <20220610031915.25529-1-ubely@ilbers.de> <2415021.XAFRqVoOGU@home> <20220610113253.123f3f75@md1za8fc.ad001.siemens.net> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED 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: 2aUjuqu2BiLi In the email from Friday, 10 June 2022 12:32:53 +03 user Henning Schild wrote: > Am Fri, 10 Jun 2022 10:13:54 +0300 > > schrieb Uladzimir Bely : > > 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-partitio > > > > n.s > > > > h > > > > b/meta/recipes-support/expand-on-first-boot/files/expand-last-partitio > > > > n.s > > > > h index f3e29a1c..934a014f 100755 > > > > --- > > > > a/meta/recipes-support/expand-on-first-boot/files/expand-last-partitio > > > > n.s > > > > h +++ > > > > b/meta/recipes-support/expand-on-first-boot/files/expand-last-partitio > > > > n.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. > > i think something other than head would be better to catch the case > where find does not find anything. > > i.e. > > rc=0 > find || rc=$? > if [ $rc -eq 0 -a -n "${ROOT_DEV_SLAVE}" ]; then > > or simply use a "find || true" > > Henning Yes, '|| true' also works. And it looks better then 'tee' or 'head'. I'd also like to make this more clear for me... On my machine I have ROOT_DEV_NAME=nvme0n1p3 (partition #3), but in "/sys/block/" I have only "nvme0n1" (whole device) directory with empty "slaves" inside. Similar thing I see on Raspberry - ROOT_DEV_NAME is a partition on sdcard, while only whole (mmcblk0) device is mentioned in "/sys/block/" In which cases nodes for the partition could exist in "/sys/block", so that 'find' would not produce errors? -- Uladzimir Bely