[debhelper-devel] maintainer scripts and `exit 0`

Lukas Schwaighofer lukas at schwaighofer.name
Fri Jun 16 22:25:25 UTC 2017


Hi,

I looked at a postinst script earlier today and realized that an
`exit 0` in maintainer scripts before the commands expanded from
#DEBHELPER# is (almost always) wrong.  That is because the debhelper
inserted code may still want to act, even though the maintainer's own
code is done.


A cursory search revealed a few examples where the resulting code is
wrong, although the resulting problem is very minor.  The most common
case was that the postinst aborts (succeeds) if not called with
configure, e.g.

    [ "$1" = "configure" ] || exit 0

and later debhelper inserts something like

    if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ]; then
    # (...)

but the "abort-upgrade" part can never be reached.  Affected scripts I
noticed are:
 * cron.postinst
 * ipsec-tools.postinst
 * isc-dhcp-server.postinst
 * man-db.postinst

There are other cases, e.g. where scripts succeed with `exit 0` if
their user/group already exists (and thereby also skip the debhelper
code).


I suspect (without much packaging experience), that any kind of
successful termination (`exit 0`) inserted before #DEBHELPER# is a
potential bug and should be avoided.

This also applies to the "called with unknown argument" error which is
still handled using `exit 0` by quite a few maintainer scripts.  (The
default in the example script/template provided by the dh-make package
has been `exit 1` since version 0.27 from 2001.)

I suspect the only exception where the `exit 0` may be justified is
the "triggered" parameter of postinst.  But if we were to allow that,
writing a lintian tag that can reliably detect this problem would
become very hard.


One way to avoid this problem altogether would be to have #DEBHELPER#
at the start of the script by convention.  I do not know if this has
unintended side-effects or if there are other reasons why that code is
most often at the end of the script.


Regards,
Lukas
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 833 bytes
Desc: OpenPGP digital signature
URL: <http://lists.alioth.debian.org/pipermail/debhelper-devel/attachments/20170617/1a71ab77/attachment.sig>


More information about the debhelper-devel mailing list