The postinstall script logging tapping into each postinstall script recipe and depending on the value of debug-tweaks in IMAGE_FEATURES isn't quite right, and resulted in bug 4246. In 1.5 we need to rework the implementation so the info is gathered in a more appropriate manner.
The implementation might be different, but I think the key problem here is under which condition should we enable postinst logging. 'debug-tweaks', in my point of view, seems to be a good sign. After all, we usually enable postinst logging for debugging purpose. //Chen Qi
As far as logging on the host goes, we typically log almost everything, so it should always be logged there. For the target, you may be right, debug-tweaks is probably the preferred way to do this; however the postinstall scripts themselves should not be changed dependent on whether or not debug-tweaks is in IMAGE_FEATURES. Either it should be handled through the package manager, or the scripts should check for the presence of a file/config option within the image which would be set at image post-processing time dependent on whether or not debug-tweaks is in IMAGE_FEATURES.
Design Goal: 1. Enable postinst logging if 'debug-tweaks' is in IMAGE_FEATURES 2. Make rpm, opk and dpkg not dependent on IMAGE_FEATURES and POSTLOG Implementation: 1. The run-postinst scripts will log outputs and errors if /etc/.enable_postinst_logging is present. 2. The log location is always /var/log/postinstall.log. Do not allow configuration, because this is mainly for debugging purpose and /var/log/postinstall.log is a good place. Making it configurable is not necessary. Proof-of-concept patch [For rpm package backend, others are similar] diff --git a/meta/classes/image.bbclass b/meta/classes/image.bbclass index 2b42e12..fc5e23c 100644 --- a/meta/classes/image.bbclass +++ b/meta/classes/image.bbclass @@ -175,6 +175,8 @@ MACHINE_POSTPROCESS_COMMAND ?= "" ROOTFS_POSTPROCESS_COMMAND_prepend = "run_intercept_scriptlets; " # Allow dropbear/openssh to accept logins from accounts with an empty password string if debug-tweaks is enabled ROOTFS_POSTPROCESS_COMMAND += '${@base_contains("IMAGE_FEATURES", "debug-tweaks", "ssh_allow_empty_password; ", "",d)}' +# Enable postinst logging if debug-tweaks is enabled +ROOTFS_POSTPROCESS_COMMAND += '${@base_contains("IMAGE_FEATURES", "debug-tweaks", "postinst_enable_logging; ", "",d)}' # some default locales IMAGE_LINGUAS ?= "de-de fr-fr en-gb" @@ -484,6 +486,11 @@ ssh_allow_empty_password () { fi } +# Enable postinst logging if debug-tweaks is enabled +postinst_enable_logging () { + touch ${IMAGE_ROOTFS}/etc/.enable_postinst_logging +} + # Turn any symbolic /sbin/init link into a file remove_init_link () { if [ -h ${IMAGE_ROOTFS}/sbin/init ]; then diff --git a/meta/recipes-devtools/rpm/rpm-postinsts.bb b/meta/recipes-devtools/rpm/rpm-postinsts.bb index 3d2d05d..ae0e37e 100644 --- a/meta/recipes-devtools/rpm/rpm-postinsts.bb +++ b/meta/recipes-devtools/rpm/rpm-postinsts.bb @@ -11,10 +11,6 @@ inherit allarch # POSTINSTALL_INITPOSITION ?= "98" -POSTLOG ?= "/var/log/postinstall.log" -REDIRECT_CMD = "${@base_contains('IMAGE_FEATURES', 'debug-tweaks', '>>${POSTLOG} 2>&1', '', d)}" -REDIRECT_CMD[vardepsexclude] += "IMAGE_FEATURES POSTLOG" - do_fetch() { : } @@ -40,7 +36,12 @@ if [ "x$D" != "x" ] && [ -f $D/var/lib/rpm/Packages ]; then [ -d /etc/rpm-postinsts ] && for i in `ls /etc/rpm-postinsts/`; do i=/etc/rpm-postinsts/$i echo "Running postinst $i..." - if [ -f $i ] && $i ${REDIRECT_CMD}; then + if [ -x $i ]; then + if [ -e /etc/.enable_postinst_logging ]; then + $i >/var/log/postinstall.log 2&>1 + else + $i + fi rm $i else echo "ERROR: postinst $i failed."
merged into poky/master: f7b639e527a65f9ce77aef07651ac5ec1e094e52
Verified with master/31e6eee860b5f9f4ac9ef0889bcff5648de6e3f9
Test case: Steps: 1. Add the following lines to a .bb file. For expample, man_1.6g.bb: pkg_postinst_${PN} () { #!/bin/sh -e if [ x"$D" = "x" ]; then echo "List directory to check the output log" ls / echo "List nonexist directory to check the stderr redirection log" ls /nonexist else exit 1 fi } 2. Add the following line in conf/local.conf to make sure this package is installed in the rootfs: CORE_IMAGE_EXTRA_INSTALL += "man" Make sure the feature "debug-tweaks" is added in conf/local.conf 3. Build a image. 4. Boot up the image and check the /var/log/postinstall.log Expected results: The /var/log/postinstall.log should exist in the first boot. The content of this log is like below: Running postinst /etc/rpm-postinsts/man... List directory to check the output log bin boot dev etc home lib lost+found media mnt proc run sbin sys tmp usr var List nonexist directory to check the stderr redirection log ls: /nonexist: No such file or directory