[Pkg-sysvinit-devel] Bug#738759: /etc/init.d/rc: adding/removing init scripts during runlevel switch results in double/no run for specific init scripts

FUCHS Gerfried Gerfried.FUCHS at svc.co.at
Wed Feb 12 18:48:30 UTC 2014


Package: initscripts
Version: 2.88dsf-13.1+squeeze1
Severity: important
File: /etc/init.d/rc

       Hi!

 Just right from the start, the issue appears also in wheezy and jessie because it has the same code segment.  The troublesome part is this snippet (taken from jessie because that's what I have at hands, but it's the same in its core also in squeeze where this was found):

#v+
                # Now run the START scripts for this runlevel.
                # Run all scripts with the same level in parallel
                CURLEVEL=""
                for s in /etc/rc$runlevel.d/S*
                do
                        # Extract order value from symlink
                        level=${s#/etc/rc$runlevel.d/S}
                        level=${level%%[a-zA-Z]*}
                        if [ "$level" = "$CURLEVEL" ]
                        then
                                continue
                        fi
                        CURLEVEL=$level
                        SCRIPTS=""
                        for i in /etc/rc$runlevel.d/S$level*
                        do
#v-

 (the same snippet appears a second time for K links)

 What this does is scan first all start links in the runlevel dir, but in the end only uses the order value from it, and then scans the directory for each found level *again* and finally runs all the scripts for the specific order value.

 If now during the runlevel change an init script gets added (or removed), insserv will reorder the scripts accordingly.  This probably results in different order values for certain scripts, resulting in scripts to either be run multiple times (in case they were already run at that time and get a higher order value after the reordering which isn't proceeded yet), or not at all (if they receive a lower order value and weren't proceeded yet, *or* if they have a higher order level than the one that originally was the highest one).

 This is a very critical side effect of this code, and I would really encourage to rewrite so that it scans the directory only *once* and works with the data from there on.  Scanning the directory only once, adding scripts to a special array and running stuff only when the level changes instead of scanning it on every new level again would work around the situation.

 I know this is a special setup in which this only can appear, it doesn't happen very often that init scripts get added/removed during a runlevel switch, but when it does, this code makes it go boom.

 I hope this can get fixed in all supported releases as it seems to be part of all of them.

 Thanks in advance,
Rhonda


More information about the Pkg-sysvinit-devel mailing list