[elbe-devel] [PATCH] elbepack: properly log command of do and chroot
Thomas Weißschuh
thomas.weissschuh at linutronix.de
Wed Mar 6 14:35:40 CET 2024
The functions do() and chroot() would only log the executed command.
As finetuning <command>s are fed through /bin/sh only the /bin/sh
command would be logged.
This makes it very confusing for the users as they can't correlate the
log output to the XML file.
Example:
<fine-tuning>
<command>echo hello world</command>
</fine-tuning>
# Before
[CMD] chroot /var/cache/elbe/fe9af34f-af71-4a62-b1ea-3ff131d8cc9a/target /bin/sh
hello world
# After
[CMD] echo hello world
hello world
See https://github.com/Linutronix/elbe/issues/394
Signed-off-by: Thomas Weißschuh <thomas.weissschuh at linutronix.de>
---
elbepack/finetuning.py | 8 +++++---
elbepack/shellhelper.py | 4 ++--
2 files changed, 7 insertions(+), 5 deletions(-)
diff --git a/elbepack/finetuning.py b/elbepack/finetuning.py
index ce98fc8c1bdb..eff5a1dcb5d6 100644
--- a/elbepack/finetuning.py
+++ b/elbepack/finetuning.py
@@ -386,15 +386,17 @@ class CmdAction(ImageFinetuningAction):
if self.node.bool_attr('nomount'):
do('/bin/sh', stdin=script,
- env_add={'ELBE_DEV': dev})
+ env_add={'ELBE_DEV': dev},
+ log_cmd=script)
else:
with ImgMountFilesystem(mnt, dev) as fs:
do('/bin/sh', stdin=script,
- env_add={'ELBE_MNT': fs.path})
+ env_add={'ELBE_MNT': fs.path},
+ log_cmd=script)
def execute(self, _buildenv, target):
with target:
- chroot(target.path, '/bin/sh', stdin=self.node.et.text)
+ chroot(target.path, '/bin/sh', stdin=self.node.et.text, log_cmd=self.node.et.text)
@FinetuningAction.register('buildenv_command')
diff --git a/elbepack/shellhelper.py b/elbepack/shellhelper.py
index be805742fa2f..edbb6f81edf7 100644
--- a/elbepack/shellhelper.py
+++ b/elbepack/shellhelper.py
@@ -199,7 +199,7 @@ def system_out_stderr(cmd, stdin=None, allow_fail=False, env_add=None):
return out, err
-def do(cmd, allow_fail=False, stdin=None, env_add=None):
+def do(cmd, allow_fail=False, stdin=None, env_add=None, log_cmd=None):
"""do() - Execute cmd in a shell and redirect outputs to logging.
Throws a CommandError if cmd failed with allow_Fail=False.
@@ -238,7 +238,7 @@ def do(cmd, allow_fail=False, stdin=None, env_add=None):
if isinstance(stdin, str):
stdin = stdin.encode()
- logging.info(cmd, extra={'context': '[CMD] '})
+ logging.info(log_cmd or cmd, extra={'context': '[CMD] '})
r, w = os.pipe()
---
base-commit: e82cb3cab39d63e6f4b5534c81f655bb9a6fdcb5
change-id: 20240306-command-log-9f13a103f051
Best regards,
--
Thomas Weißschuh <thomas.weissschuh at linutronix.de>
More information about the elbe-devel
mailing list