[elbe-devel] [PATCH] elbepack: finetuning: run raw_cmd without a shell
Thomas Weißschuh
thomas.weissschuh at linutronix.de
Thu Jul 11 10:08:02 CEST 2024
In diet mode there very well may not be a shell available in the target
system during finetuning.
Run `<raw_cmd>` actions without a shell.
Historically a shell was used for `<raw_cmd>`, but that was the buildenv
one, leading to surprising results.
Removing the shell from `<raw_cmd>` now also makes the difference
between it and `<command>` clear.
Also align the schema documentation and tests to that effect.
Closes #408
Signed-off-by: Thomas Weißschuh <thomas.weissschuh at linutronix.de>
---
elbepack/finetuning.py | 2 +-
elbepack/schema/dbsfed.xsd | 2 +-
newsfragments/+raw_cmd-noshell.bugfix.rst | 1 +
tests/simple-validation-image-test.py | 6 +++++-
tests/simple-validation-image.xml | 3 ++-
5 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/elbepack/finetuning.py b/elbepack/finetuning.py
index bf532ad73c73..070a4e3b3afa 100644
--- a/elbepack/finetuning.py
+++ b/elbepack/finetuning.py
@@ -300,7 +300,7 @@ class RawCmdAction(FinetuningAction):
def execute(self, _buildenv, target):
with target:
- chroot(target.path, self.node.et.text)
+ chroot(target.path, shlex.split(self.node.et.text))
@FinetuningAction.register('command')
diff --git a/elbepack/schema/dbsfed.xsd b/elbepack/schema/dbsfed.xsd
index f75ac7e174b1..9f41dcbf47e3 100644
--- a/elbepack/schema/dbsfed.xsd
+++ b/elbepack/schema/dbsfed.xsd
@@ -2180,7 +2180,7 @@ SPDX-FileCopyrightText: Linutronix GmbH
<element name="raw_cmd" type="rfs:string" minOccurs="0">
<annotation>
<documentation>
- execute the defined command
+ execute the defined command without a shell
</documentation>
</annotation>
</element>
diff --git a/newsfragments/+raw_cmd-noshell.bugfix.rst b/newsfragments/+raw_cmd-noshell.bugfix.rst
new file mode 100644
index 000000000000..f42e4ae2b543
--- /dev/null
+++ b/newsfragments/+raw_cmd-noshell.bugfix.rst
@@ -0,0 +1 @@
+Execute `<raw_cmd>` without a shell.
diff --git a/tests/simple-validation-image-test.py b/tests/simple-validation-image-test.py
index 4a56e6d6c5e1..d8880caaed23 100755
--- a/tests/simple-validation-image-test.py
+++ b/tests/simple-validation-image-test.py
@@ -163,10 +163,14 @@ def _test_finetuning(root):
assert root.joinpath('testfile').is_file()
assert root.joinpath('testfile').read_text() == 'Some cöntent wíth spe©ial characters'
- # <raw_cmd>cat /etc/hosts | cat -n > /etc/hosts4</raw_cmd>
+ # <command>cat /etc/hosts | cat -n > /etc/hosts4</command>
assert root.joinpath('etc', 'hosts4').is_file()
assert root.joinpath('etc', 'hosts4').read_text().startswith(' 1\t127.0.0.1\tlocalhost\n')
+ # <raw_cmd>cp /etc/hosts /etc/hosts5</raw_cmd>
+ assert root.joinpath('etc', 'hosts5').is_file()
+ assert root.joinpath('etc', 'hosts5').read_text().startswith('127.0.0.1\tlocalhost\n')
+
def _test_rfs_partition(build_dir, part):
assert part.number == 1
diff --git a/tests/simple-validation-image.xml b/tests/simple-validation-image.xml
index 575470c684cd..2764749d5ff1 100644
--- a/tests/simple-validation-image.xml
+++ b/tests/simple-validation-image.xml
@@ -69,7 +69,8 @@ SPDX-FileCopyrightText: Linutronix GmbH
Some cöntent wíth spe©ial characters
</file>
- <raw_cmd>cat /etc/hosts | cat -n > /etc/hosts4</raw_cmd>
+ <command>cat /etc/hosts | cat -n > /etc/hosts4</command>
+ <raw_cmd>cp /etc/hosts /etc/hosts5</raw_cmd>
</finetuning>
<project-finetuning>
---
base-commit: 37f0b5f2794e2eb1c58089a8559c126a45b7c13d
change-id: 20240711-raw_cmd-noshell-ff185f66c4de
Best regards,
--
Thomas Weißschuh <thomas.weissschuh at linutronix.de>
More information about the elbe-devel
mailing list