[ltp] Detecting a kernel message

Robert Hajime Lanning linux-thinkpad@www.bm-soft.com
Sun, 16 Sep 2001 01:38:32 -0700 (PDT)


--%--multipart-mixed-boundary-1.12598.1000629512--%
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Attached is a Perl/TK script I wrote for easily managing the schemes.
I have is running with no border decorations, sticky on desktops and skipped
on the window list.

My startup command is:
$ nohup tkcardctl -geometry 170x64-0+0 < /dev/null > /dev/null 2>&1 &

This shows me the current scheme at all times with a drop down list, that
auto updates at the time you drop it down, to easily choose a new scheme.

Also shows what is currently in the sockets.

---- As written by Tino Keitel:
> 
> On Saturday, 15. September 2001 04:56, Thomas Vogels wrote:
> 
> > I guess you leave your pcmcia card always in the laptop?  My simple,
> > hardware-based solution with having to deal with two networks, is to
> > put the network card in the upper slot on campus and in the lower slot
> > at home.  Trivial to handle in network.opts...
> 
> Hm. Maybe I missed the point, but I wrote a script that parses selfmade 
> network configurations in a specific directory ("work", "home" etc.) and 
> shows a dialog where you can choose what network configuration should be 
> used. This script is started by /etc/pcmcia/network.opts whenever a PCMCIA 
> network card is inserted. I found it very usefull.
> 
> I've never heard of the "scheme" option of cardctl, but it seams to me that I 
> reinvented the wheel. :-/
> 
> Tino
> 
> ----- The Linux ThinkPad mailing list -----
> The linux-thinkpad mailing list home page is at:
> http://www.bm-soft.com/~bm/tp_mailing.html
> 


-- 
/* Robert Hajime Lanning                             lanning@lanning.cc
** Trade: Unix Systems Administrator (Senior level) (SAGE IV)
*/
#include <std_disclaimer.h>

--%--multipart-mixed-boundary-1.12598.1000629512--%
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Description: perl script text
Content-Disposition: attachment; filename="tkcardctl"

#! /usr/bin/perl

use Tk;
use Tk::BrowseEntry;
use Tk::Label;

my $Font = "-adobe-helvetica-medium-r-normal-*-8-*-*-*-*-*-iso8859-1";

#
# Subroutine Prototypes
#
sub read_status();  # Read "Status" file for device   args: <device>
sub change_scheme($$); # change the cardctl scheme     args: <scheme>
sub isnewschemes(@);
sub getschemes();
sub mk_scheme_menu();

#
#  Setup vars
#
$NOCARD = "empty";
$Active_Scheme = "UNKNOWN";
$Socket0Label = "Socket 0: ";
$Socket0 =  $Socket0Label . $NOCARD;
$Socket1Label = "Socket 1: ";
$Socket1 =  $Socket1Label . $NOCARD;

if (-r "/etc/pcmcia/network.opts") {
   open(SCHEMES,"</etc/pcmcia/network.opts");
   while(<SCHEMES>) {
      s/[\r\n]+//g;
      if (/^\s*(\w+),.*$/) {
         push(@Schemes,$1);
      }
   }
   close(SCHEMES);
}

if (-r "/var/lib/pcmcia/scheme") {
   open(SCHEME,"</var/lib/pcmcia/scheme");
   while(<SCHEME>) {
      s/[\r\n]+//g;
      $Active_Scheme = $_;
   }
   close(SCHEME);
} else {
   $Active_Scheme = "UNKNOWN";
}

#
#  Setup Window
#
my $rootwin = Tk::MainWindow->new;
$rootwin->Label(
   -height => 1,
   -width => 15,
   -anchor => 'w',
   -textvariable => \$Socket0,
   -padx => 2,
   -pady => 2,
   -font => $Font,
   -foreground => 'black'
)->pack(
   -padx => 1,
   -pady => 1,
   -side => 'top',
   -fill => 'both',
   -expand => 1
);
$rootwin->Label(
   -height => 1,
   -width => 15,
   -anchor => 'w',
   -textvariable => \$Socket1,
   -padx => 2,
   -pady => 2,
   -font => $Font,
   -foreground => 'black'
)->pack(
   -padx => 1,
   -pady => 1,
   -side => 'top',
   -fill => 'both',
   -expand => 1
);
$Scheme_BE = $rootwin->BrowseEntry(
   -label => 'Scheme',
   -variable => \$Active_Scheme,
   -listwidth => 35,
   -browsecmd => \&main::change_scheme,
   -listcmd => \&main::mk_scheme_menu
)->pack(
   -padx => 1,
   -pady => 1,
   -side => 'top',
   -fill => 'both',
   -expand => 1
);

#
# Setup to read apm on regular basis
#
$SIG{'ALRM'} = sub {alarm(0);read_status();alarm(1);};
alarm(1);

#
# Start Event Loop
MainLoop();

#
# Subroutine Definitions
#
sub read_status() {
   if (-r "/var/lib/pcmcia/scheme") {
      open(SCHEME,"</var/lib/pcmcia/scheme");
      while(<SCHEME>) {
         s/[\r\n]+//g;
         $Active_Scheme = $_;
      }
      close(SCHEME);
   } else {
      $Active_Scheme = "UNKNOWN";
   }
   if (-r "/var/lib/pcmcia/stab") {
      open(STAB,"</var/lib/pcmcia/stab");
      while(<STAB>) {
         s/[\r\n]+//g;
         s/\s+$//;
         if (/^Socket 0:\s+(.*)$/) {
            my $cardtype = $1;
            $cardtype =~ s/^(.{0,25}).*$/$1/;
            my $devicename = "";
            if ($cardtype eq "empty") {
               $Socket0 = $Socket0Label . $cardtype;
            } else {
               $devicename = <STAB>;
               $devicename =~ s/[\r\n]+//g;
               $devicename =~ s/\s+$//g;
               $devicename =~ s/^.*\s(\w+)$/$1/;
               $Socket0 = $Socket0Label . $devicename . " - " . $cardtype;
            }
         } elsif (/^Socket 1:\s+(.*)$/) {
            my $cardtype = $1;
            $cardtype =~ s/^(.{0,25}).*$/$1/;
            my $devicename = "";
            if ($cardtype eq "empty") {
               $Socket1 = $Socket1Label . $cardtype;
            } else {
               $devicename = <STAB>;
               $devicename =~ s/[\r\n]+//g;
               $devicename =~ s/\s+$//g;
               $devicename =~ s/^.*\s(\w+)$/$1/;
               $Socket1 = $Socket1Label . $devicename . " - " . $cardtype;
            }
         }
      }
      close(STAB);
   } else {
      $Socket0 = $Socket0Label . $NOCARD;
      $Socket1 = $Socket1Label . $NOCARD;
   }
}

sub isnewschemes(@) {
   my (@newschemes) = (@_);
   my $retval = 0;
   if ($#newschemes != $#Old_Schemes) {
      $retval = 1;
   } else {
      foreach (@newschemes) {
         if(grep(/^$_$/,@Old_Schemes)) {
            $retval = 1;
            last;
         }
      }
   }
   return($retval);
}

sub change_scheme($$) {
   my $widget = shift(@_);
   my $newscheme = shift(@_);

   system("/sbin/cardctl scheme $newscheme");
}

sub getschemes() {
   my @schemes;
   if (-r "/etc/pcmcia/network.opts") {
      while(shift(@Schemes)) { 1; }
      open(SCHEMES,"</etc/pcmcia/network.opts");
      while(<SCHEMES>) {
         s/[\r\n]+//g;
         if (/^\s*(\w+),.*$/) {
            push(@schemes,$1);
         }
      }
      close(SCHEMES);
   }
   return(@schemes);
}

sub mk_scheme_menu() {
   (@Old_Schemes) = (@Schemes);
   @Schemes = getschemes();
   if (isnewschemes(@Schemes)) {
      $Scheme_BE->delete(0,'end');
      foreach (@Schemes) {
         $Scheme_BE->insert('end',$_);
      }
   }
}

--%--multipart-mixed-boundary-1.12598.1000629512--%--

----- The Linux ThinkPad mailing list -----
The linux-thinkpad mailing list home page is at:
http://www.bm-soft.com/~bm/tp_mailing.html