# $Id: Global.pm,v 1.47 2002/10/09 21:01:37 jeffb Exp $ # Cobalt Networks, Inc http::/www.cobalt.com # Copyright 2002 Sun Microsystems, Inc. All rights reserved. package Global; use strict; require Exporter; use vars qw(@ISA @EXPORT @EXPORT_OK); @ISA = qw(Exporter); @EXPORT = qw( &cmuLog &getBuild &parseD &memInfo $validExport $validImport %adjustPath ); @EXPORT_OK = qw(); use vars qw($validExport $validImport %adjustPath); $validExport = { Qube2 => 1, Qube3 => 1, RaQ2 => 1, RaQ3 => 1, RaQ4 => 1, RaQXTR => 1, RaQ550 => 1, }; $validImport = { Qube3 => 1, RaQ3 => 1, RaQ4 => 1, RaQXTR => 1, RaQ550 => 1, }; %adjustPath = ( Qube2 => 'Qube3', RaQ2 => 'RaQ3', RaQ3 => 'RaQ4', RaQ4 => 'RaQXTR', RaQXTR => 'RaQ550', ); 1; sub cmuLog # This function will print error messages to screen and the log file. # Arguments: code, message # Returns: none # Side Effects: writes info to the log file and maybe the screen { my $code = shift; my $string = shift; my $logFile = "/home/cmu/cmu.log"; if($string =~ /^(INFO: )(.*)/) { print $2, "\n"; } elsif($string =~ /^ERROR/) { print $string; } # Everything get logged, biaaaatch! my $msg = $code.": ".$string; system("echo -n \"$msg\" >> $logFile"); } sub getBuild # Translates all of build tags into basic product names # Arguments: none # Returns: name of build # Side Effects: selling out { my $bldFile = "/etc/build"; my %bldHash = ( # Qube Builds "2800WG", "Qube2", "4000WG", "Qube3", "4010WG", "Qube3", "4100WG", "Qube3", # RaQ Builds "2700R", "RaQ1", "2799R", "RaQ2", "2800R", "RaQ2", "3000R", "RaQ3", "3001R", "RaQ4", "3100R", "RaQ4", "3500R", "RaQXTR", "3599R", "RaQXTR", "4100R", "RaQ550", "5100R", "RaQ550" ); open(FH, "< $bldFile") || die "Error opening file $bldFile: $!"; my $data; while() { $data .= $_; } close(FH); for (sort keys %bldHash) { return $bldHash{$_} if ($data =~ /\Q$_\E/); } } sub parseD # Arguments: the -d option # Returns: the full path to the dir # Side effects: will create dirs on export { my $dir = shift; my $pwd; if ($dir eq ".") { $pwd = `/bin/pwd`; chomp $pwd; $dir = $pwd; } unless($dir =~ /^\//) { $pwd = `/bin/pwd`; chomp $pwd; $dir = $pwd."/".$dir; } if($0 =~ /Export/ && -d $dir) { print "Directory already exists: $dir Overwrite? (Yes/No) "; my $opt = ; unless($opt =~ /(yes|y)/oi) { cmuLog("ERROR","Need valid export directory\n"); exit 1; } } return $dir; } sub memInfo { my $pid = $$; open(FH, "< /proc/$pid/status") || return "Cannot open file /proc/$pid:$!\n"; my $mem; while() { if(/^VmSize:\s*(.*)$/) { $mem = $1; last; } } close(FH); ($mem) ? (return $mem) : (return "memInfo: FAILED"); } 1;