Patchwork [V2,4/4] rpm-postinsts.bb: enable postinst logging

login
register
mail settings
Submitter Qi.Chen@windriver.com
Date May 20, 2013, 2:50 a.m.
Message ID <a0237296a606069eb2987ff126be556c61f62b7b.1369018014.git.Qi.Chen@windriver.com>
Download mbox | patch
Permalink /patch/50127/
State New
Headers show

Comments

Qi.Chen@windriver.com - May 20, 2013, 2:50 a.m.
From: Chen Qi <Qi.Chen@windriver.com>

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]

Signed-off-by: Chen Qi <Qi.Chen@windriver.com>
---
 meta/recipes-devtools/rpm/rpm-postinsts.bb |   13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
Saul Wold - May 20, 2013, 3:38 p.m.
On 05/19/2013 07:50 PM, Qi.Chen@windriver.com wrote:
> From: Chen Qi <Qi.Chen@windriver.com>
>
> 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]
>
> Signed-off-by: Chen Qi <Qi.Chen@windriver.com>
> ---
>   meta/recipes-devtools/rpm/rpm-postinsts.bb |   13 +++++++------
>   1 file changed, 7 insertions(+), 6 deletions(-)
>
> diff --git a/meta/recipes-devtools/rpm/rpm-postinsts.bb b/meta/recipes-devtools/rpm/rpm-postinsts.bb
> index 3d2d05d..01d7450 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() {
>   	:
>   }
> @@ -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

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!



> +		else
> +			$i
> +		fi
>   		rm $i
>   	else
>   		echo "ERROR: postinst $i failed."
>
Qi.Chen@windriver.com - May 21, 2013, 2:27 a.m.
On 05/20/2013 11:38 PM, Saul Wold wrote:
> On 05/19/2013 07:50 PM, Qi.Chen@windriver.com wrote:
>> From: Chen Qi <Qi.Chen@windriver.com>
>>
>> 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]
>>
>> Signed-off-by: Chen Qi <Qi.Chen@windriver.com>
>> ---
>>   meta/recipes-devtools/rpm/rpm-postinsts.bb |   13 +++++++------
>>   1 file changed, 7 insertions(+), 6 deletions(-)
>>
>> diff --git a/meta/recipes-devtools/rpm/rpm-postinsts.bb 
>> b/meta/recipes-devtools/rpm/rpm-postinsts.bb
>> index 3d2d05d..01d7450 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() {
>>       :
>>   }
>> @@ -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
>
> 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!
>
>
Thanks for pointing the error out.

I'll fix it and send out a V3 soon.

Best Regards,
Chen Qi
>
>> +        else
>> +            $i
>> +        fi
>>           rm $i
>>       else
>>           echo "ERROR: postinst $i failed."
>>
>
>

Patch

diff --git a/meta/recipes-devtools/rpm/rpm-postinsts.bb b/meta/recipes-devtools/rpm/rpm-postinsts.bb
index 3d2d05d..01d7450 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() {
 	:
 }
@@ -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."