From fbc4c5160fc9c630c17b782fc35029f98f9aff6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leonard=20G=C3=B6hrs?= Date: Wed, 10 Dec 2025 13:49:04 +0100 Subject: [PATCH 1/2] test: cpio: add variant that should fail due to missing cpio util MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Genimage will currently exit with a success exit code when generating a cpio archive fails due to a missing `cpio` util. This is due to a pipe in the `systemp` call and the `pipefail` option not being set. See this issue[1] for mor information. Add a test that checks if genimage fails if the cpio util is missing (which it currently does not but should). [1]: https://github.com/pengutronix/genimage/issues/320 Signed-off-by: Leonard Göhrs --- test/filesystem.test | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/filesystem.test b/test/filesystem.test index f2a1887..22d4eef 100755 --- a/test/filesystem.test +++ b/test/filesystem.test @@ -15,6 +15,10 @@ test_expect_success cpio "cpio" " check_filelist " +test_expect_failure "cpio missing" " + GENIMAGE_CPIO=/usr/bin/cpio-not-available run_genimage_root cpio.config test.cpio +" + exec_test_set_prereq mkfs.cramfs test_expect_success mkfs_cramfs "cramfs" " run_genimage_root cramfs.config test.cramfs && From 5043c36098974933e14798e856da26afebb62652 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leonard=20G=C3=B6hrs?= Date: Wed, 10 Dec 2025 14:01:58 +0100 Subject: [PATCH 2/2] util: systemp: set pipefail flag MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This ensures that the whole call to `systemp` fails if one commands in a command line consisting of multiple commands joined by pipes fails. This is for example relevant for the `cpio` backend, where the `cpio` command is called and its output is piped to `gzip`. If the `cpio` command fails or is not found at all a `.cpio.gz` file will be created containing just the gzip header and genimage will return a successful exit status anyways. This change assumes that all relevant `/bin/sh` implementations support the `-o pipefail` option. We know that at least bash, dash and busybox ash do. Signed-off-by: Leonard Göhrs --- util.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util.c b/util.c index f6641e2..e1054d7 100644 --- a/util.c +++ b/util.c @@ -271,7 +271,7 @@ int systemp(struct image *image, const char *fmt, ...) if (!shell || shell[0] == 0x0) shell = "/bin/sh"; - execl(shell, shell, "-c", buf, NULL); + execl(shell, shell, "-o", "pipefail", "-c", buf, NULL); ret = -errno; error("Cannot execute %s: %s\n", buf, strerror(errno)); goto err_out;