home *** CD-ROM | disk | FTP | other *** search
- #!/usr/bin/perl
- #
- # beware the nasty modeline --> vi:set ts=6|set sw=3:
- #
- # errlogd: forward spu:/mnt/errlog to do syslogd
- # until we merge do syslog and errlog, this'll have to do.
- #
- # periodically examine spu's errlog file for growth since last time
- # looked. retrieve only new part, discarding date stamps, and do syslog'ing
- # with facility class LOCAL0 anything else, priority set to be INFO for
- # routine stuff and NOTICE for other stuff. reserve higher pris for
- # internal problems. note that you only see things that occur while JP
- # running, ie, no panic messages, diags, etc.
- #
- # written by tom christiansen
- #
- # updated 15 jan 89 to use ioctl() rather than re-exec'ing
- # /usr/bin/X11/execqt on itself
-
- ($program = $0) =~ s%.*/%%;
-
- $\ = "\n"; $! = 0;
-
- # magic to check for run time switches
- eval '$'.$1.'$2;' while $ARGV[0] =~ /^([A-Za-z_]+=)(.*)/ && shift;
-
- $priority = "warn" unless $priority; # should really
- $facility = "local0" unless $facility;
- $sleep = 3 unless $sleep;
- $sleep *= 60;
-
- die "$program: not superuser\n" if $>;
- die "$program: usage error; see man page\n" if $#ARGV > $[;
-
- if ( `tty` !~ /^not a tty/ ) {
- # do 'ioctl.pl' || die 'can't do ioctl.pl';
- $TIOCNOTTY = 0x20007471; # i know this is the right value
- if (open(tty,'/dev/tty') && !ioctl(tty, $TIOCNOTTY, 0)) {
- do syslog("warn","can't detach");
- }
- fork && exit;
- }
-
-
- # wanna get this:
- # + ls -l /mnt/errlog -rw-rw-rw- 1 root 5613 Feb 4 15:51 /mnt/errlog
- # 0 1 2 3 4 5 6 7 8 9 10 11
- #
- again:
- $log = `/usr/convex/spucmd ls -l /mnt/errlog 2>&1 `;
- @log = split(/\s+/,$log);
- #die "$program: initial /usr/convex/spucmd exited ".($?>>8)."\n" if $?;
-
- if ($#log != 11) {
- #do syslog("err","initial /usr/convex/spucmd seems misformatted: @log\n");
- sleep 60;
- goto again;
- }
-
- $size = $log[7];
-
- do syslog("debug","startup, spu:/mnt/errlog @ $size bytes");
-
- if (open(pidlog, ">/usr/adm/tmp/errlogd.pid")) {
- print pidlog $$;
- close pidlog;
- } else {
- do syslog("err","couldn't log pid $$");
- }
-
-
- foreach $signal ((
- 'QUIT', 'ILL', 'TRAP', 'IOT', 'EMT', 'FPE', 'BUS', 'SEGV', 'SYS',
- 'PIPE', 'ALRM', 'TERM', 'URG', 'IO', 'POLL', 'XCPU', 'XFSZ', 'VTALRM',
- 'PROF', 'LOST', 'USR1', 'USR2' ))
- {
- $SIG{$signal} = 'godown';
- }
-
- $SIG{'ALRM'} = "IGNORE"; # spurious SIGALRMs by impatient sysadmins
- $SIG{'HUP'} = "reboot"; # why do this? new script i guess
-
- for (;;) {
- sleep $sleep;
- @log = split(/\s+/,`/usr/convex/spucmd ls -l /mnt/errlog 2>&1`);
-
- if ($?) {
- #do syslog("notice", "/usr/convex/spucmd exited ".($?>>8));
- next; # maybe should exit
- }
-
- if ($#log != 11) {
- #do syslog("notice", "\`/usr/convex/spucmd ls -l /mnt/errlog\` seems misformatted: \"@log\"");
- next; # maybe should exit
- }
- next if $log[7] == $size; # no growth
- if ($log[7] < $size) {
- do syslog("debug", "spu:/mnt/errlog just shrank from " .
- $size . " to " . $log[7] . " bytes long");
- $size = 0; # negative growth; assume new file
- }
- $tail = sprintf("/usr/convex/spucmd tail +%dc /mnt/errlog | ",$size+1);
- $size = $log[7];
- open tail || (do syslog("err","can't open \"$tail\": $!"), next);
- $oldwho = ""; # no previous logger
- while(<tail>) {
- next if /<(Mon|Tue|Wed|Thu|Fri|Sat|Sun) (Jan|Feb|Mar|Apr|May|Ju[nl]|Aug|Sep|Oct|Nov|Dec) [ 123]\d \d+>$/ || /CPU date\/time changed/ ; # skip ugly datestamps
- ($who,$which,$when,$msg) = # parse message
- /^\[(SPU|C[CP]U)(\d*)[_ ]*@(\d\d.\d\d.\d\d\])\s*(.*)/;
- $who =~ tr/A-Z/a-z/; # tolower
- $which += 0 if length($which); # force string to numeric to trim leading 0
- next unless $who; # race condition?
- $who .= $which if length($which); # catenate unit number of cpu or ccu
- if ( $who ne $oldwho ) {
- close logger if $oldwho; # logger id (spu,ccuX,..) changed
- $pri = $priority; # assume defualt level unless boring
- $pri = "notice" if /sniff/ || /\bta\d+:/ || /NFS/; # too boring to biff us for
- $logger = sprintf("| logger -t %s -p %s.%s", $who, $facility, $pri);
- open logger ||(do syslog("err","\"$logger\" wouldn't open: $!"),last);
- select(logger); $| = 1; # unbuffer PIPE, just in case
- select(stdout); # just in case
- $oldwho = $who; # remember who just spoke
- }
- print logger $msg; # off to syslog we go
- }
- close logger if $oldwho; # send EOF to logger PIPE if one started
- close tail; # until next time
- } # forever loop
-
-
- # usage: do syslog("alert","some message string");
- sub syslog {
- local ($level,$message) = @_;
- system "logger","-t",$program,"-p",$facility.".".$level,$message;
- }
-
- # generic interrupt handler
- sub godown {
- local($signal) = @_;
- do syslog("notice","going down on SIG$signal");
- exit(1);
- }
-
- sub reboot {
- do syslog("notice","restarting $mypath");
- exec($mypath);
- }
-