Package: dpkg
Version: 1.15.5.6

I have installed some hook scripts in /etc/kernel/postinst.d and
/etc/kernel/postrm.d to improve the installation and removal process for
kernel image packages.  I initially did this for custom kernel image packages
created by the make-kpkg command of the kernel-package package, but these
scripts are executed when installing and removing stock kernel image packages
as well.  There are currently three scripts in /etc/kernel/postrm.d.  One
is initramfs-tools, provided by the package of the same name, for handling
kernel image packages created by "make deb-pkg".  It exits without doing
anything when stock kernel image packages or kernel image packages created
by make-kpkg are being removed/purged, since it gets two arguments instead
of the expected one.  The second is initramfs, which is essentially the same
as /usr/share/kernel-package/examples/etc/kernel/postrm.d/initramfs from
the kernel-package package.  The third is symlink_hook, which is a modified
version of
/usr/share/kernel-package/examples/etc/kernel/postinst.d/symlink_hook
from the kernel-image package.  It's purpose is to re-do the symlinks
and re-run the boot loader (zipl in my case, s390 architecture) when a
kernel image package is purged.  The three scripts are executed in
alphabetical order: initramfs, initramfs-tools, symlink_hook.  Thus,
symlink_hook is executed third and last.  The script appears to work
correctly and to exit with a return status of 0.  However, I still get
an error from dpkg when I purge the package.  For example, in response to

dpkg --purge linux-image-2.6.32-trunk-s390x

I get

...
run-parts: executing /etc/kernel/postrm.d/symlink_hook 2.6.32-trunk-s390x 
/boot/vmlinuz-2.6.32-trunk-s390x
dpkg: error processing linux-image-2.6.32-trunk-s390x (--purge):
 subprocess installed post-removal script returned error exit status 128
Errors were encountered while processing:
 linux-image-2.6.32-trunk-s390x

I am running a pure "testing" system (Squeeze).  There are no packages
from "unstable" (Sid).  I am running another (custom) kernel at the time.
(I am not trying to purge a running kernel!)

An exit status of 128 is particularly puzzling.
An exit status is usually between 0 and 127, inclusive.  According to the
man page for bash,

   "The return value of a simple command is its exit status, or 128+n if
   the command is terminated by signal n."

Thus, this would indicate a process terminated by "kill -n 0".  Huh?  What?

I have searched the internet on the string

"subprocess installed post-removal script returned error exit status 128".

I found three other bug reports with this search: 560181, 534648, and 541275.
All these bug reports were against other packages (wwwoffle, wicd, and
ca-certificates, respectively).  However, in each case the respective package
had a postrm script that was returning a non-zero exit status.  In my case,
I am certain that my script is returning a zero exit status.
Therefore, I am filing this bug report against dpkg itself.

Here is my script:

----------

#!/bin/sh -
#                               -*- Mode: Sh -*-
# example.posthook.sh ---
# Author           : Manoj Srivastava ( [email protected] )
# Created On       : Mon Aug 11 14:00:58 2003
# Created On Node  : glaurung.green-gryphon.com
# Last Modified By : Manoj Srivastava
# Last Modified On : Sun Apr 12 17:16:52 2009
# Last Machine Used: anzu.internal.golden-gryphon.com
# Update Count     : 10
# Status           : Unknown, Use with caution!
# HISTORY          :
# Description      :
#
#
# This is an example of a script that can be run as a postrm hook,
# and manages the symbolic links in a manner similar to the kernel
# image default behaviour, except that the latest two versions (as
# determined by ls -lct) are kept. You can modify this script
#
# Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Manoj Srivastava
# Copyright 2009 Darren Salt

set -e
set -x

# The dir where symlinks are managed
SYMLINKDIR=/boot

if [ $# -ne 2 ];then exit 0;fi

version="$1"
vmlinuz_location="$2"
vmlinuz_dir="$(dirname "$2")"

cd $SYMLINKDIR || exit 1
if [ -n "$DEB_MAINT_PARAMS" ]; then
    eval set -- "$DEB_MAINT_PARAMS"
    case "$1" in
        remove)
           : echo nop
           ;;
        *)
           exit 0
           ;;
    esac
fi

rm -f vmlinuz vmlinuz.old initrd.img initrd.img.old

# Create a temporary file safely
if [ -x /bin/tempfile ]; then
    outfile=$(tempfile -p outp -m 0600);
else
    set -e
    mkdir /tmp/kernel-image-$version-$$
    outfile=/tmp/kernel-image-$version-$$/output
fi

(cd "$vmlinuz_dir" && ls -ct vmlinuz-*) > $outfile

STD="$(head -n 1 $outfile |             sed 's/vmlinuz-//')"
OLD="$(head -n 2 $outfile | tail -n 1 | sed 's/vmlinuz-//')"
if [ "X$OLD" = "X$STD" ]; then
    OLD=
fi

if [ "X$STD" = "X" ]; then
    exit 0
fi

# echo Booting $STD, old is $OLD

if [ -f "$vmlinuz_dir/"initrd.img-$STD ] ; then
   ln -s initrd.img-$STD initrd.img
   ln -s vmlinuz-$STD vmlinuz
else
   ln -s vmlinuz-$STD vmlinuz
fi

if [ "X$OLD" != "X" ]; then
    if [ -f "$vmlinuz_dir/"initrd.img-$OLD ] ; then
        ln -s initrd.img-$OLD initrd.img.old
        ln -s vmlinuz-$OLD vmlinuz.old
    else
        ln -s vmlinuz-$OLD vmlinuz.old
    fi
fi

zipl

rm -f $outfile
if [ -d /tmp/kernel-image-$version-$$ ]; then
    rmdir /tmp/kernel-image-$version-$$
fi

exit 0

----------

(Notice the "set -x", which I have added for debugging purposes.)  And
here is a console log of my attempt to purge the package, which has
previously been removed successfully.

----------

debian3:~# dpkg --purge linux-image-2.6.32-trunk-s390x
(Reading database ... 25193 files and directories currently installed.)
Removing linux-image-2.6.32-trunk-s390x ...
Purging configuration files for linux-image-2.6.32-trunk-s390x ...
Examining /etc/kernel/postrm.d .
run-parts: executing /etc/kernel/postrm.d/initramfs 2.6.32-trunk-s390x 
/boot/vmlinuz-2.6.32-trunk-s390x
Cannot delete /boot/initrd.img-2.6.32-trunk-s390x, doesn't exist.
run-parts: executing /etc/kernel/postrm.d/initramfs-tools 2.6.32-trunk-s390x 
/boot/vmlinuz-2.6.32-trunk-s390x
run-parts: executing /etc/kernel/postrm.d/symlink_hook 2.6.32-trunk-s390x 
/boot/vmlinuz-2.6.32-trunk-s390x
+ SYMLINKDIR=/boot
+ [ 2 -ne 2 ]
+ version=2.6.32-trunk-s390x
+ vmlinuz_location=/boot/vmlinuz-2.6.32-trunk-s390x
+ dirname /boot/vmlinuz-2.6.32-trunk-s390x
+ vmlinuz_dir=/boot
+ cd /boot
+ [ -n  ]
+ rm -f vmlinuz vmlinuz.old initrd.img initrd.img.old
+ [ -x /bin/tempfile ]
+ tempfile -p outp -m 0600
+ outfile=/tmp/outpB5mG9b
+ cd /boot
+ ls -ct vmlinuz-2.6.32-customtrunk-s390x
+ sed s/vmlinuz-//
+ head -n 1 /tmp/outpB5mG9b
+ STD=2.6.32-customtrunk-s390x
+ sed s/vmlinuz-//
+ tail -n 1
+ head -n 2 /tmp/outpB5mG9b
+ OLD=2.6.32-customtrunk-s390x
+ [ X2.6.32-customtrunk-s390x = X2.6.32-customtrunk-s390x ]
+ OLD=
+ [ X2.6.32-customtrunk-s390x = X ]
+ [ -f /boot/initrd.img-2.6.32-customtrunk-s390x ]
+ ln -s initrd.img-2.6.32-customtrunk-s390x initrd.img
+ ln -s vmlinuz-2.6.32-customtrunk-s390x vmlinuz
+ [ X != X ]
+ zipl
+ rm -f /tmp/outpB5mG9b
+ [ -d /tmp/kernel-image-2.6.32-trunk-s390x-1071 ]
+ exit 0
dpkg: error processing linux-image-2.6.32-trunk-s390x (--purge):
 subprocess installed post-removal script returned error exit status 128
Errors were encountered while processing:
 linux-image-2.6.32-trunk-s390x
debian3:~# 

----------

By trial and error, I have found that if I comment out the invocation
of the boot loader, zipl, everything works fine.  But if I leave it
uncommented, it fails.  zipl itself works.  It exits with a return status of 0.
But dpkg fails.  Why?  There is a similar symlink_hook script in
/etc/kernel/postinst.d.  It invokes zipl too, and it causes no problems.
Also, all three of the scripts in /etc/kernel/postrm.d can be called
twice for a purge: once for a remove, if the package has not previously
been removed, and then again for a purge.  It only fails on the purge call.
The remove call works fine.




-- 
To UNSUBSCRIBE, email to [email protected]
with a subject of "unsubscribe". Trouble? Contact [email protected]

Reply via email to