[Initscripts-ng-commits] r993 - in /trunk/src/insserv/debian: changelog check-archive-initd-scripts rules

pere at users.alioth.debian.org pere at users.alioth.debian.org
Wed Sep 9 19:47:52 UTC 2009


Author: pere
Date: Wed Sep  9 19:47:52 2009
New Revision: 993

URL: http://svn.debian.org/wsvn/initscripts-ng/?sc=1&rev=993
Log:
Add script check-archive-initd-scripts to check all init.d scripts
in the Debian archive for consistency.

Added:
    trunk/src/insserv/debian/check-archive-initd-scripts   (with props)
Modified:
    trunk/src/insserv/debian/changelog
    trunk/src/insserv/debian/rules

Modified: trunk/src/insserv/debian/changelog
URL: http://svn.debian.org/wsvn/initscripts-ng/trunk/src/insserv/debian/changelog?rev=993&op=diff
==============================================================================
--- trunk/src/insserv/debian/changelog (original)
+++ trunk/src/insserv/debian/changelog Wed Sep  9 19:47:52 2009
@@ -8,6 +8,8 @@
     to Laurent Bonnaud for discovering the problem.
   * Drop the Loading... messages from the default verbosity level, and
     only show then when -v is used several times.
+  * Add script check-archive-initd-scripts to check all init.d scripts
+    in the Debian archive for consistency.
 
  -- Petter Reinholdtsen <pere at debian.org>  Tue, 08 Sep 2009 08:51:43 +0200
 

Added: trunk/src/insserv/debian/check-archive-initd-scripts
URL: http://svn.debian.org/wsvn/initscripts-ng/trunk/src/insserv/debian/check-archive-initd-scripts?rev=993&op=file
==============================================================================
--- trunk/src/insserv/debian/check-archive-initd-scripts (added)
+++ trunk/src/insserv/debian/check-archive-initd-scripts Wed Sep  9 19:47:52 2009
@@ -1,0 +1,190 @@
+#!/usr/bin/perl
+#
+# Check the consistency of all init.d scripts in the archive.  Run
+# this on bellini.debian.org.
+
+use warnings;
+use strict;
+use File::Basename;
+
+my $warn = 1;
+
+my @scripts = @ARGV;
+ at scripts = </org/lintian.debian.org/laboratory/binary/*/init.d/*>
+    unless @scripts;
+
+my %scriptinfo;
+my %provides;
+
+my @virts = qw($local_fs $remote_fs $syslog $time $named
+               $portmap $network $all
+               $mail-transport-agent
+               );
+my @depheaders = qw(required-start required-stop should-start
+                    should-stop x-start-before x-stop-after);
+my $lsbheaders = "Provides|Required-Start|Required-Stop|Default-Start|Default-Stop";
+my $optheaders = "x-start-before|x-stop-after|should-start|should-stop";
+
+for my $virt (@virts) {
+    $provides{$virt} = ['/etc/insserv.conf'];
+}
+
+# Ignore obsolete scripts, as these are unlikely to cause problems.
+for my $old (qw(glibc devfsd hotplug evms raid2)) {
+    $provides{$old} = ['obsolete'];
+}
+
+# First pass to load the database
+for my $initdscript (@scripts) {
+    next if $initdscript =~ m%/rc|/rcS|/README%;
+    my %lsbinfo = parse_lsb_header($initdscript);
+    $scriptinfo{$initdscript} = \%lsbinfo;
+    next unless ($lsbinfo{'found'});
+
+    my %checked;
+    for my $provide (split(/[ ,\t]+/, $lsbinfo{provides})) {
+        if (exists $provides{$provide}) {
+            push(@{$provides{$provide}}, $initdscript)
+        } else {
+            $provides{$provide} = [$initdscript];
+        }
+        $checked{$provide} = 1;
+    }
+}
+
+for my $provide (sort keys %provides) {
+    if (1 < scalar @{$provides{$provide}}) {
+        my %script;
+        map { $script{basename($_)} = 1; } @{$provides{$provide}};
+        if (1 < scalar keys %script) {
+            error("duplicate provide '$provide' in scripts "
+                  . join(" ", @{$provides{$provide}}));
+        }
+    }
+}
+
+# Second pass, to see which dependencies are missing
+for my $initdscript (@scripts) {
+    next unless ($scriptinfo{$initdscript}->{'found'});
+    my %checked;
+    my @missing = ();
+    for my $header (@depheaders) {
+        my $list = $scriptinfo{$initdscript}->{$header};
+        next unless defined $list;
+        for my $facility (split(/[ ,\t]+/, $list)) {
+            next if exists $checked{$facility};
+            $checked{$facility} = 1;
+            push(@missing, $facility)
+                unless exists $provides{$facility};
+        }
+    }
+    error("script $initdscript relate to non-existing provides: "
+          . join(" ", @missing)) if (@missing);
+
+    if (!exists $checked{'$remote_fs'}
+        && $scriptinfo{$initdscript}->{'need_remove_fs'}) {
+        warning("script $initdscript possibly missing dependency on \$remote_fs");
+    } elsif (!exists $checked{'$local_fs'}
+             && !exists $checked{'$remote_fs'}
+             && $scriptinfo{$initdscript}->{'need_local_fs'}) {
+        warning("script $initdscript possibly missing dependency on \$local_fs");
+    }
+
+    my %provided;
+    for my $provide (split(/[ ,\t]+/,
+                           $scriptinfo{$initdscript}->{provides})) {
+        $provided{$provide} = 1;
+    }
+
+    my $basename = basename($initdscript, ".sh");
+    warning("script $initdscript do not provide its own name")
+        unless exists $provided{$basename};
+
+    # Detect common problems with runlevel settings.
+    my @startrl = sort split(/\s+/, lc($scriptinfo{$initdscript}->{'default-start'}));
+    my @stoprl = sort split(/\s+/, lc($scriptinfo{$initdscript}->{'default-stop'}));
+
+    # Scripts starting in rcS.d/ normally do not stop or only stop
+    # during hald and shutdown.
+    if ((array_equal(['s'], \@startrl) && array_equal([], \@stoprl))
+        || ( array_equal(['s'], \@startrl)
+             && array_equal(['0','6'], \@stoprl))) {
+        # OK
+    } else {
+        # Most scripts either start in rcS.d, or in runlevels 2-5
+        if (!array_equal(['2', '3', '4', '5'], \@startrl) &&
+            !array_equal(['s'], \@startrl)) {
+            warning("script $initdscript do not start in the usual runlevels");
+        }
+        # And most scripts stop in runlevel 1 or runlevels 0, 1 and 6
+        if (!array_equal(['0', '1', '6'], \@stoprl) &&
+            !array_equal(['1'], \@stoprl)) {
+            warning("script $initdscript do not stop in the usual runlevels");
+        }
+    }
+}
+
+exit 0;
+
+sub parse_lsb_header {
+    my $initdscript = shift;
+    my %lsbinfo;
+    unless (open(INIT, "<", $initdscript)) {
+        error("unable to read $initdscript");
+        return ();
+    }
+    my $inheader = 0;
+    while (<INIT>) {
+#        print;
+        chomp;
+        if (m/^\#\#\# BEGIN INIT INFO\s*$/) {
+            $lsbinfo{'found'} = 1;
+            $inheader = 1;
+        }
+        $inheader = 0 if (m/\#\#\# END INIT INFO$/);
+        if ($inheader
+            && m/^\# ($lsbheaders|$optheaders):\s*(\S?.*)$/i) {
+#            print "$1\n";
+            $lsbinfo{lc($1)} = $2;
+        }
+        $lsbinfo{'need_remove_fs'} = 1 if m%/usr/s?bin/%;
+        $lsbinfo{'need_local_fs'} = 1 if m%/var/%;
+    }
+    close(INIT);
+
+    # Check that all the required headers are present
+    if (!$lsbinfo{'found'}) {
+        error("script $initdscript is missing LSB header");
+    } else {
+        for my $key (split(/\|/, lc($lsbheaders))) {
+            if (!exists $lsbinfo{$key}) {
+                error("$initdscript missing LSB keyword '$key'");
+            }
+        }
+    }
+    return %lsbinfo
+}
+
+sub array_equal {
+    my ($a1, $a2) = @_;
+    return 0 if (scalar @{$a1} != scalar @{$a2});
+
+    my $i = 0;
+    while ($i < scalar @{$a1}) {
+        return 0 if $a1->[$i] ne $a2->[$i];
+        $i++;
+    }
+    return 1;
+}
+
+sub info {
+    print "info: @_\n";
+}
+
+sub warning {
+    print "warning: @_\n" if $warn;
+}
+
+sub error {
+    print "error: @_\n";
+}

Propchange: trunk/src/insserv/debian/check-archive-initd-scripts
------------------------------------------------------------------------------
    svn:executable = *

Modified: trunk/src/insserv/debian/rules
URL: http://svn.debian.org/wsvn/initscripts-ng/trunk/src/insserv/debian/rules?rev=993&op=diff
==============================================================================
--- trunk/src/insserv/debian/rules (original)
+++ trunk/src/insserv/debian/rules Wed Sep  9 19:47:52 2009
@@ -64,6 +64,8 @@
 	done
 
 	$(INSTALL) debian/check-initd-order $(DESTDIR)$(pkgdatadir)/.
+	$(INSTALL) debian/check-archive-initd-scripts \
+		$(DESTDIR)$(pkgdatadir)/.
 	$(INSTALL) debian/seq-changes $(DESTDIR)$(pkgdatadir)/.
 	$(INSTALL) debian/make-testsuite $(DESTDIR)$(pkgdatadir)/.
 	$(INSTALL) debian/update-bootsystem-insserv $(DESTDIR)$(sbindir)/.




More information about the Initscripts-ng-commits mailing list