From e8cb9b6f491686dfc80b4786a63b778f034702f8 Mon Sep 17 00:00:00 2001 From: Michael Olbrich Date: Fri, 28 Aug 2020 15:36:48 +0200 Subject: [PATCH 1/4] genimage: make mountpath() argument const It not modified and this will be needed in the next commit. Signed-off-by: Michael Olbrich --- genimage.c | 2 +- genimage.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/genimage.c b/genimage.c index 530a12d..a3994ee 100644 --- a/genimage.c +++ b/genimage.c @@ -465,7 +465,7 @@ static int collect_mountpoints(void) return 0; } -const char *mountpath(struct image *image) +const char *mountpath(const struct image *image) { struct mountpoint *mp; diff --git a/genimage.h b/genimage.h index 59c03ba..58995fd 100644 --- a/genimage.h +++ b/genimage.h @@ -22,7 +22,7 @@ const char *imagepath(void); const char *inputpath(void); const char *rootpath(void); const char *tmppath(void); -const char *mountpath(struct image *); +const char *mountpath(const struct image *); struct flash_type; struct mountpoint { From 866f216e1994c5f58034653c54bc95c2fc2a9525 Mon Sep 17 00:00:00 2001 From: Michael Olbrich Date: Fri, 28 Aug 2020 15:31:26 +0200 Subject: [PATCH 2/4] genimage: make sure that IMAGEMOUNTPATH is exported correctly If the image mountpoint is not explicitly defined, then IMAGEMOUNTPATH is currently no exported. This is incorrect, because the default mountpoint for any image is '/'. Use mountpath() to get the correct path. It handles the default mountpoint correctly. Make sure that IMAGEMOUNTPATH is not set if the image is explicitly marked as empty. Signed-off-by: Michael Olbrich --- genimage.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/genimage.c b/genimage.c index a3994ee..8c91773 100644 --- a/genimage.c +++ b/genimage.c @@ -586,7 +586,7 @@ static int setenv_image(const struct image *image) if (ret) return ret; - ret = overwriteenv("IMAGEMOUNTPATH", image->mp ? image->mp->mountpath : NULL); + ret = overwriteenv("IMAGEMOUNTPATH", image->empty ? NULL : mountpath(image)); if (ret) return ret; From 419730f75b7bb630a2f77f5f61122c35ed42dfdc Mon Sep 17 00:00:00 2001 From: Michael Olbrich Date: Fri, 28 Aug 2020 16:26:49 +0200 Subject: [PATCH 3/4] image-file: quote all paths Signed-off-by: Michael Olbrich --- image-file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/image-file.c b/image-file.c index 776a711..519c65b 100644 --- a/image-file.c +++ b/image-file.c @@ -40,7 +40,7 @@ static int file_generate(struct image *image) if (!strcmp(f->infile, imageoutfile(image))) return 0; - ret = systemp(image, "cp %s %s", f->infile, imageoutfile(image)); + ret = systemp(image, "cp '%s' '%s'", f->infile, imageoutfile(image)); return ret; } From 2b1f054ed1489c63db9f444af1b1a588937ba947 Mon Sep 17 00:00:00 2001 From: Michael Olbrich Date: Fri, 28 Aug 2020 16:29:48 +0200 Subject: [PATCH 4/4] test: add tests to check exec-* commands Signed-off-by: Michael Olbrich --- Makefile.am | 3 +++ test/basic-images.test | 19 ++++++++++++++++++- test/exec-check.sh | 33 +++++++++++++++++++++++++++++++++ test/exec-fail.config | 4 ++++ test/exec.config | 27 +++++++++++++++++++++++++++ 5 files changed, 85 insertions(+), 1 deletion(-) create mode 100755 test/exec-check.sh create mode 100644 test/exec-fail.config create mode 100644 test/exec.config diff --git a/Makefile.am b/Makefile.am index f0bad83..3c8c810 100644 --- a/Makefile.am +++ b/Makefile.am @@ -50,6 +50,9 @@ EXTRA_DIST += \ test/basic-images.test \ test/cpio.config \ test/cramfs.config \ + test/exec-check.sh \ + test/exec-fail.config \ + test/exec.config \ test/ext2.config \ test/ext2test.dump \ test/ext2percent.config \ diff --git a/test/basic-images.test b/test/basic-images.test index cb104c3..059a5dd 100755 --- a/test/basic-images.test +++ b/test/basic-images.test @@ -24,7 +24,7 @@ setup_data() { find "${root_orig}" -print0 | xargs -0 touch -c -d "2011-11-11 UTC" find "${root_orig}"/ -mindepth 1 -printf "%P\n" | sort > "${filelist_orig}" - cp "${testdir}"/*.conf* . + cp "${testdir}"/*.conf* "${testdir}"/*.sh . } run_genimage() { @@ -373,6 +373,23 @@ test_expect_success rauc "rauc" " test_cmp '${testdir}/test2.raucb.info' test2.raucb.info " +setup_exec_files() { + rm -rf input && + mkdir input && + dd if=/dev/zero of=input/file1.img bs=512 count=7 && + dd if=/dev/zero of=input/file2.img bs=512 count=7 && + dd if=/dev/zero of=input/file3.img bs=512 count=7 && + dd if=/dev/zero of=input/file4.img bs=512 count=7 +} + +test_expect_success "exec" " + setup_exec_files && + run_genimage exec.config" + +test_expect_success "exec-fail" " + setup_exec_files && + test_must_fail run_genimage exec-fail.config" + test_done # vim: syntax=sh diff --git a/test/exec-check.sh b/test/exec-check.sh new file mode 100755 index 0000000..ad1373d --- /dev/null +++ b/test/exec-check.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +exec >&2 + +name="${1}" +empty="${2}" + +set -ex + +: OUTPUTPATH +test "${OUTPUTPATH}" = "${PWD}/images" +: INPUTPATH +test "${INPUTPATH}" = "${PWD}/input" +: ROOTPATH +test "${ROOTPATH}" = "${PWD}/root" +: TMPPATH +test "${TMPPATH}" = "${PWD}/tmp" +: IMAGE +test "${IMAGE}" = "${name}" +: IMAGEOUTFILE +test "${IMAGEOUTFILE}" = "${PWD}/images/${name}" +: IMAGENAME +test "${IMAGENAME}" = "exec-test" +: IMAGESIZE +test "${IMAGESIZE}" = "3584" +: IMAGEMOUNTPOINT +test "${IMAGEMOUNTPOINT}" = "" +: IMAGEMOUNTPATH +if [ "${empty}" = "empty" ]; then + test "${IMAGEMOUNTPATH}" = "" +else + test "${IMAGEMOUNTPATH}" = "${PWD}/tmp/root" +fi diff --git a/test/exec-fail.config b/test/exec-fail.config new file mode 100644 index 0000000..dc223e5 --- /dev/null +++ b/test/exec-fail.config @@ -0,0 +1,4 @@ +image file1.img { + file {} + exec-pre = "false" +} diff --git a/test/exec.config b/test/exec.config new file mode 100644 index 0000000..a261276 --- /dev/null +++ b/test/exec.config @@ -0,0 +1,27 @@ +image file1.img { + file {} + name = "exec-test" + exec-pre = "./exec-check.sh file1.img" +} + +image file2.img { + file {} + name = "exec-test" + mountpoint = "/" + exec-post = "./exec-check.sh file2.img" +} + +image file3.img { + file {} + name = "exec-test" + empty = true + exec-pre = "./exec-check.sh file3.img empty" +} + +image file4.img { + file {} + name = "exec-test" + empty = true + mountpoint = "/" + exec-post = "./exec-check.sh file4.img empty" +}