Postinst logging reimplementation
v2 cover Postinst logging reimplementation
From: Chen Qi <[email protected]>
Goal:
1. Enable postinst logging if 'debug-tweaks' is in IMAGE_FEATURES
2. Make rpm, opkg and dpkg not depend on IMAGE_FEATURES and POSTLOG
Implementation:
1. The run-postinst scripts will log outputs by checking the configuration in /etc/default/postinst.
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.
The following changes since commit a9f5bf0ed398bf9cb861feaa8b6fefd8645b1d09:
sanity.bbclass: Attach the missing value to a format string. (2013-05-13 21:54:40 +0300)
are available in the git repository at:
git://git.pokylinux.org/poky-contrib ChenQi/postinst-logging-reimplementation
http://git.pokylinux.org/cgit.cgi/poky-contrib/log/?h=ChenQi/postinst-logging-reimplementation
Chen Qi (4):
image.bbclass: add postinst_enable_logging
dpkg: modify the run-postinst script to enable postinst logging
opkg: modify the run-postinst script to enable postinst logging rpm-postinsts.bb: enable postinst logging
meta/classes/image.bbclass | 7 +++++++ meta/recipes-devtools/dpkg/dpkg.inc | 11 ++++++----- meta/recipes-devtools/opkg/opkg.inc | 11 ++++++----- meta/recipes-devtools/rpm/rpm-postinsts.bb | 13 +++++++------ 4 files changed, 26 insertions(+), 16 deletions(-)
Signature · 1 line
1.7.9.5
PATCH v2 1/4 image.bbclass: add postinst_enable_logging
From: Chen Qi <[email protected]>
Add a function postinst_enable_logging, so that when 'debug-tweaks' is in IMAGE_FEATURES, we create /etc/default/postinst config file, which is sourced by run-postinst scripts to determine whether to log or not.
[YOCTO #4262]
--- meta/classes/image.bbclass | 7 +++++++ 1 file changed, 7 insertions(+)
meta/classes/image.bbclass +7 -0
@@ -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 () { + echo "POSTINST_LOGGING=ENABLED" >> ${IMAGE_ROOTFS}/etc/default/postinst +} + # Turn any symbolic /sbin/init link into a file remove_init_link () { if [ -h ${IMAGE_ROOTFS}/sbin/init ]; then
Signature · 1 line
1.7.9.5
PATCH v2 2/4 dpkg: modify the run-postinst script to enable postinst logging
In reply to [email protected]From: Chen Qi <[email protected]>
Enable postinst logging by checking the configuration in /etc/ default/postinst.
In this way, the postinst logging is enabled if 'debug-tweaks' is in IMAGE_FEATURES, and at the same time, we avoid unnecessary rebuilt if IMAGE_FEATURES is changed.
[YOCTO #4262]
--- meta/recipes-devtools/dpkg/dpkg.inc | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
meta/recipes-devtools/dpkg/dpkg.inc +6 -5
@@ -35,10 +35,6 @@ do_configure () { autotools_do_configure } -POSTLOG ?= "/var/log/postinstall.log" -REDIRECT_CMD = "${@base_contains('IMAGE_FEATURES', 'debug-tweaks', '>${POSTLOG} 2>&1', '', d)}" -REDIRECT_CMD[vardepsexclude] += "IMAGE_FEATURES POSTLOG" - DPKG_INIT_POSITION ?= "98" do_install_append () {
@@ -67,7 +63,12 @@ if [ "x$D" != "x" ] && [ -f $D/var/lib/dpkg/status ]; then # this happens at S98 where our good 'ole packages script used to run echo "#!/bin/sh -dpkg --configure -a ${REDIRECT_CMD} +[ -e /etc/default/postinst ] && . /etc/default/postinst +if [ \"\$POSTINST_LOGGING\" = \"ENABLED\" ]; then + dpkg --configure -a >/var/log/postinstall.log 2>&1 +else + dpkg --configure -a +fi rm -f ${sysconfdir}/rcS.d/S${DPKG_INIT_POSITION}run-postinsts " > $D${sysconfdir}/rcS.d/S${DPKG_INIT_POSITION}run-postinsts chmod 0755 $D${sysconfdir}/rcS.d/S${DPKG_INIT_POSITION}run-postinsts
Signature · 1 line
1.7.9.5
Re: [PATCH V2 2/4] dpkg: modify the run-postinst script to enable postinst logging
Quoted 35 lines · On Monday 20 May 2013 10:50:29 [email protected] wrote:
From: Chen Qi <[email protected]>
Enable postinst logging by checking the configuration in
/etc/default/postinst.In this way, the postinst logging is enabled if 'debug-tweaks' is in
IMAGE_FEATURES, and at the same time, we avoid unnecessary rebuilt ifIMAGE_FEATURESis changed.[YOCTO #4262]
Signed-off-by Chen Qi <[email protected]>--- meta/recipes-devtools/dpkg/dpkg.inc | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)(quoted diff) +0
-0b/meta/recipes-devtools/dpkg/dpkg.inc index d773fbd..c5c8aec 100644
meta/recipes-devtools/dpkg/dpkg.inc +0
-2@@ -35,10 +35,6 @@ do_configure () { autotools_do_configure } -POSTLOG ?= "/var/log/postinstall.log" -REDIRECT_CMD = "${@base_contains('IMAGE_FEATURES', 'debug-tweaks','>${POSTLOG} 2>&1', '', d)}" -REDIRECT_CMD[vardepsexclude] += "
IMAGE_FEATURESPOSTLOG"meta/recipes-devtools/dpkg/dpkg.inc +0
-1- DPKG_INIT_POSITION ?= "98" do_install_append () {@@ -67,7 +63,12 @@ if [ "x$D" != "x" ] && [ -f $D/var/lib/dpkg/status ];then
meta/recipes-devtools/dpkg/dpkg.inc if [ "x$D" != "x" ] && [ -f $D/var/lib/dpkg/status ]; then · line 67
Quoted 5 lines
meta/recipes-devtools/dpkg/dpkg.inc +2
-1# this happens at S98 where our good 'ole packages script used to run echo "#!/bin/sh -dpkg --configure -a ${REDIRECT_CMD} +[ -e /etc/default/postinst ] && . /etc/default/postinst +if [ \"\$POSTINST_LOGGING\" = \"ENABLED\" ]; then
Can we use 1 for this instead of ENABLED? This would be more consistent with how variables such as this are generally used.
Cheers,
Paul
Signature · 2 lines
Paul Eggleton Intel Open Source Technology Centre
Re: [PATCH V2 2/4] dpkg: modify the run-postinst script to enable postinst logging
Quoted 44 lines · Paul Eggleton
Quoted 37 lines · On Monday 20 May 2013 10:50:29 [email protected] wrote:
From: Chen Qi <[email protected]>
Enable postinst logging by checking the configuration in
/etc/default/postinst.In this way, the postinst logging is enabled if 'debug-tweaks' is in
IMAGE_FEATURES, and at the same time, we avoid unnecessary rebuilt ifIMAGE_FEATURESis changed.[YOCTO #4262]
Signed-off-by Chen Qi <[email protected]>--- meta/recipes-devtools/dpkg/dpkg.inc | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)(quoted diff) +0
-0b/meta/recipes-devtools/dpkg/dpkg.inc index d773fbd..c5c8aec 100644
meta/recipes-devtools/dpkg/dpkg.inc +0
-2@@ -35,10 +35,6 @@ do_configure () { autotools_do_configure } -POSTLOG ?= "/var/log/postinstall.log" -REDIRECT_CMD = "${@base_contains('IMAGE_FEATURES', 'debug-tweaks','>${POSTLOG} 2>&1', '', d)}" -REDIRECT_CMD[vardepsexclude] += "
IMAGE_FEATURESPOSTLOG"meta/recipes-devtools/dpkg/dpkg.inc +0
-1- DPKG_INIT_POSITION ?= "98" do_install_append () {@@ -67,7 +63,12 @@ if [ "x$D" != "x" ] && [ -f $D/var/lib/dpkg/status ];then
# this happens at S98 where our good 'ole packages script used to run echo "#!/bin/shmeta/recipes-devtools/dpkg/dpkg.inc if [ "x$D" != "x" ] && [ -f $D/var/lib/dpkg/status ]; then · line 67
Quoted 3 lines
meta/recipes-devtools/dpkg/dpkg.inc +2
-1-dpkg --configure -a ${REDIRECT_CMD} +[ -e /etc/default/postinst ] && . /etc/default/postinst +if [ \"\$POSTINST_LOGGING\" = \"ENABLED\" ]; thenCan we use 1 for this instead of ENABLED? This would be more consistent with how variables such as this are generally used.
Quoted 3 lines
Cheers,
Paul
Thanks, I'll do that and send out a v3 soon.
Best Regards,
Chen Qi
PATCH v2 3/4 opkg: modify the run-postinst script to enable postinst logging
In reply to [email protected]From: Chen Qi <[email protected]>
Enable postinst logging by checking the configuration in /etc/ default/postinst.
In this way, the postinst logging is enabled if 'debug-tweaks' is in IMAGE_FEATURES, and at the same time, we avoid unnecessary rebuilt if IMAGE_FEATURES is changed.
[YOCTO #4262]
--- meta/recipes-devtools/opkg/opkg.inc | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
meta/recipes-devtools/opkg/opkg.inc +6 -5
@@ -57,10 +57,6 @@ do_install_append_class-native() { fi } -POSTLOG ?= "/var/log/postinstall.log" -REDIRECT_CMD = "${@base_contains('IMAGE_FEATURES', 'debug-tweaks', '>${POSTLOG} 2>&1', '', d)}" -REDIRECT_CMD[vardepsexclude] += "IMAGE_FEATURES POSTLOG" - pkg_postinst_${PN} () { #!/bin/sh if [ "x$D" != "x" ] && [ -f $D${OPKGLIBDIR}/opkg/status ]; then
@@ -68,7 +64,12 @@ if [ "x$D" != "x" ] && [ -f $D${OPKGLIBDIR}/opkg/status ]; then # this happens at S98 where our good 'ole packages script used to run echo "#!/bin/sh -opkg-cl configure ${REDIRECT_CMD} +[ -e /etc/default/postinst ] && . /etc/default/postinst +if [ \"\$POSTINST_LOGGING\" = \"ENABLED\" ]; then + opkg-cl configure >/var/log/postinstall.log 2>&1 +else + opkg-cl configure +fi rm -f /${sysconfdir}/rcS.d/S${POSTINSTALL_INITPOSITION}run-postinsts " > $D${sysconfdir}/rcS.d/S${POSTINSTALL_INITPOSITION}run-postinsts chmod 0755 $D${sysconfdir}/rcS.d/S${POSTINSTALL_INITPOSITION}run-postinsts
Signature · 1 line
1.7.9.5
PATCH v2 4/4 rpm-postinsts.bb: enable postinst logging
In reply to [email protected]From: Chen Qi <[email protected]>
Enable postinst logging by checking the configuration in /etc/ default/postinst.
In this way, the postinst logging is enabled if 'debug-tweaks' is in IMAGE_FEATURES, and at the same time, we avoid unnecessary rebuild if IMAGE_FEATURES is changed.
[YOCTO #4262]
--- meta/recipes-devtools/rpm/rpm-postinsts.bb | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
meta/recipes-devtools/rpm/rpm-postinsts.bb +7 -6
@@ -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() { : }
@@ -36,11 +32,16 @@ if [ "x$D" != "x" ] && [ -f $D/var/lib/rpm/Packages ]; then install -d $D/${sysconfdir}/rcS.d cat > $D${sysconfdir}/rcS.d/S${POSTINSTALL_INITPOSITION}run-postinsts << "EOF" #!/bin/sh - +[ -e /etc/default/postinst ] && . /etc/default/postinst [ -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 [ "$POSTINST_LOGGING" = "ENABLED" ]; then + $i >/var/log/postinstall.log 2&>1 + else + $i + fi rm $i else echo "ERROR: postinst $i failed."
Signature · 1 line
1.7.9.5
Re: [PATCH V2 4/4] rpm-postinsts.bb: enable postinst logging
Quoted 34 lines · On 05/19/2013 07:50 PM, [email protected] wrote:
From: Chen Qi <[email protected]>
Enable postinst logging by checking the configuration in
/etc/default/postinst.In this way, the postinst logging is enabled if 'debug-tweaks' is in
IMAGE_FEATURES, and at the same time, we avoid unnecessary rebuild ifIMAGE_FEATURESis changed.[YOCTO #4262]
Signed-off-by Chen Qi <[email protected]>--- meta/recipes-devtools/rpm/rpm-postinsts.bb | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)meta/recipes-devtools/rpm/rpm-postinsts.bb +0
-4@@ -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() { : }@@ -36,11 +32,16 @@ if [ "x$D" != "x" ] && [ -f $D/var/lib/rpm/Packages ]; then install -d $D/${sysconfdir}/rcS.d cat > $D${sysconfdir}/rcS.d/S${POSTINSTALL_INITPOSITION}run-postinsts << "EOF"
meta/recipes-devtools/rpm/rpm-postinsts.bb if [ "x$D" != "x" ] && [ -f $D/var/lib/rpm/Packages ]; then · line 41
Quoted 10 lines
meta/recipes-devtools/rpm/rpm-postinsts.bb +4
-2#!/bin/sh - +[ -e /etc/default/postinst ] && . /etc/default/postinst [ -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 [ "$POSTINST_LOGGING" = "ENABLED" ]; then + $i >/var/log/postinstall.log 2&>1
This will over write the results of a previous postinstall because this is running in a for look, you should use >> instead of >.
I also suggested that the log file be a variable and you should use the ${localestatedir} as the base for /var. So you would add something like POSTINST_LOGFILE.
Thanks
Sau!
Quoted 7 lines
meta/recipes-devtools/rpm/rpm-postinsts.bb +3
-0+ else + $i + fi rm $i else echo "ERROR: postinst $i failed."
Re: [PATCH V2 4/4] rpm-postinsts.bb: enable postinst logging
Quoted 51 lines · Saul Wold
Quoted 38 lines · On 05/19/2013 07:50 PM, [email protected] wrote:
From: Chen Qi <[email protected]>
Enable postinst logging by checking the configuration in
/etc/default/postinst.In this way, the postinst logging is enabled if 'debug-tweaks' is in
IMAGE_FEATURES, and at the same time, we avoid unnecessary rebuild ifIMAGE_FEATURESis changed.[YOCTO #4262]
Signed-off-by Chen Qi <[email protected]>--- meta/recipes-devtools/rpm/rpm-postinsts.bb | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)meta/recipes-devtools/rpm/rpm-postinsts.bb +0
-2@@ -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)}"
meta/recipes-devtools/rpm/rpm-postinsts.bb +0
-2-REDIRECT_CMD[vardepsexclude] += "IMAGE_FEATURES POSTLOG" - do_fetch() { : }@@ -36,11 +32,16 @@ if [ "x$D" != "x" ] && [ -f$D/var/lib/rpm/Packages ]; then
install -d $D/${sysconfdir}/rcS.d cat >$D${sysconfdir}/rcS.d/S${POSTINSTALL_INITPOSITION}run-postinsts << "EOF"
#!/bin/shmeta/recipes-devtools/rpm/rpm-postinsts.bb if [ "x$D" != "x" ] && [ -f $D/var/lib/rpm/Packages ]; then · line 41
Quoted 9 lines
meta/recipes-devtools/rpm/rpm-postinsts.bb +4
-2- +[ -e /etc/default/postinst ] && . /etc/default/postinst [ -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 [ "$POSTINST_LOGGING" = "ENABLED" ]; then + $i >/var/log/postinstall.log 2&>1This will over write the results of a previous postinstall because this is running in a for look, you should use >> instead of >.
Quoted 6 lines
I also suggested that the log file be a variable and you should use the ${localestatedir} as the base for /var. So you would add something like
POSTINST_LOGFILE.Thanks
Sau!
Thanks for pointing the error out.
I'll fix it and send out a V3 soon.
Best Regards,
Chen Qi
Quoted 10 lines
Quoted 8 lines
meta/recipes-devtools/rpm/rpm-postinsts.bb +3
-0+ else + $i + fi rm $i else echo "ERROR: postinst $i failed."