#!/usr/bin/perl -w
##########################################################################
# $Id: init,v 1.6 2002/03/28 05:00:00 kirk Exp $
##########################################################################
# $Log: init,v $
# Revision 1.6  2002/03/28 05:00:00  kirk
# - Implemented several bug fixes and patches that have been sent in
# - Fixed a possible root exploit using a race condition in /tmp
# - Fixed bugs 46371, 56191, 58578, 61202, 61829, 61831, 61832 from bugzilla.redhat.com
#
# Revision 1.5  2000/09/22 15:59:05  kirk
# Prepping for Version 2.0.1
#
# Revision 1.4  2000/09/22 14:47:04  kirk
# *** empty log message ***
#
# Revision 1.3  1998/02/23 01:16:56  kirk
# Getting ready for a first distribution
#
# Revision 1.2  1998/02/23 00:53:42  kirk
# Finished init and modprobe, and added mountd
#
# Revision 1.1  1998/02/23 00:15:39  kirk
# Finished up 'pam', starting on 'init'
#
##########################################################################

########################################################
# This was written and is maintained by:
#    Kirk Bauer <kirk@kaybee.org>
#
# Please send all comments, suggestions, bug reports,
#    etc, to kirk@kaybee.org.
#
########################################################

$Detail = $ENV{'LOGWATCH_DETAIL_LEVEL'};

while (defined($ThisLine = <STDIN>)) {
   if ( $ThisLine =~ s/Switching to runlevel: (.)\s*$/$1/ ) {
# Which runlevel did we change to?
      chomp ($ThisLine);
      $RunLevel{$ThisLine}++;
   }
   elsif ( $ThisLine =~ s/^Entering runlevel: (.)\s*$/$1/ ) {
# Which runlevel did we enter?
      chomp ($ThisLine);
      $RunLevel{$ThisLine}++;
   }
   else {
# report any unmatched entries
      push @OtherList,$ThisLine;
   }
}

if ( ((keys %RunLevel) and ($Detail >= 10)) or (@OtherList) ) {

   print "\n\n ---------------------- Init Begin ------------------------- \n\n";

   if ((keys %RunLevel) and ($Detail >= 10)) {
      foreach $Level (sort keys %RunLevel) {
         print "   Entered or switched to runlevel " . $Level . ": " . $RunLevel{$Level} . " Time(s)\n";
      }
   }

   if ($#OtherList >= 0) {
      print "\n**Unmatched Entries**\n";
      print @OtherList;
   }

   print "\n\n ---------------------- Init End ------------------------- \n\n";

}

exit(0);

