Commit e2ed8a1c authored by Mac Newbold's avatar Mac Newbold

Lots of small changes for turning our 'require lib*' lines into 'use lib*'...

Lots of small changes for turning our 'require lib*' lines into 'use lib*' lines. Proper modules declare themselves as a package, and use Exporter to export the names of the subroutines that should be visible from the outside world. Many of ours didn't do that, it was just a file with a bunch of subs in it. So now I've fixed many of them to be proper, and removed the requires and 'push(@INC,...)' hacks and changed it to the proper 'use lib @prefix@/lib/;' and use lib*.
parent 9a449cbc
...@@ -31,9 +31,9 @@ my $d = 0; ...@@ -31,9 +31,9 @@ my $d = 0;
$| = 1; $| = 1;
# Load the Testbed support stuff. # Load the Testbed support stuff.
push(@INC, "$TB/lib"); use lib "@prefix@/lib";
require libdb; use libdb;
require libtestbed; use libtestbed;
# #
# We don't want to run this script unless its the real version. # We don't want to run this script unless its the real version.
......
...@@ -17,6 +17,7 @@ use Fcntl ':flock'; ...@@ -17,6 +17,7 @@ use Fcntl ':flock';
# #
my $TB = "@prefix@"; my $TB = "@prefix@";
my $TBOPS = "@TBOPSEMAIL@"; my $TBOPS = "@TBOPSEMAIL@";
my $TESTMODE = "@TESTMODE@";
# Note no -n option. We redirect stdin from the new exports file below. # Note no -n option. We redirect stdin from the new exports file below.
my $SSH = "$TB/bin/sshtb -l root fs.emulab.net"; my $SSH = "$TB/bin/sshtb -l root fs.emulab.net";
...@@ -59,20 +60,26 @@ use libtestbed; ...@@ -59,20 +60,26 @@ use libtestbed;
# We need to serialize this script to avoid a trashed map file. Use # We need to serialize this script to avoid a trashed map file. Use
# a dummy file in /var/tmp, opened for writing and flock'ed. # a dummy file in /var/tmp, opened for writing and flock'ed.
# #
open(LOCK, ">>$lockfile") || fatal("Couldn't open $lockfile\n"); if (!$TESTMODE) {
$count = 0; open(LOCK, ">>$lockfile") || fatal("Couldn't open $lockfile\n");
while (flock(LOCK, LOCK_EX|LOCK_NB) == 0) { $count = 0;
while (flock(LOCK, LOCK_EX|LOCK_NB) == 0) {
print "Another /etc/exports update in progress. Waiting a moment ...\n"; print "Another /etc/exports update in progress. Waiting a moment ...\n";
if ($count++ > 20) { if ($count++ > 20) {
fatal("Could not get the lock after a long time!\n"); fatal("Could not get the lock after a long time!\n");
} }
sleep(1); sleep(1);
}
} }
# #
# We stick the new map entries into the tail file. First zero it out. # We stick the new map entries into the tail file. First zero it out.
# #
open(MAP, ">$exportstail") || fatal("Couldn't open $exportstail\n"); if (!$TESTMODE) {
open(MAP, ">$exportstail") || fatal("Couldn't open $exportstail\n");
} else {
open(MAP, ">/dev/null") || fatal("Couldn't open /dev/null\n");
}
print MAP "\n"; print MAP "\n";
print MAP "#\n"; print MAP "#\n";
print MAP "# DO NOT EDIT below this point. Auto generated entries!\n"; print MAP "# DO NOT EDIT below this point. Auto generated entries!\n";
...@@ -220,16 +227,18 @@ close(MAP); ...@@ -220,16 +227,18 @@ close(MAP);
# Fire the new tail file over to the fileserver to finish. We cat the file # Fire the new tail file over to the fileserver to finish. We cat the file
# right into it. # right into it.
# #
$UID = 0; if (!$TESTMODE) {
system("$SSH $PROG < $exportstail") == 0 or $UID = 0;
system("$SSH $PROG < $exportstail") == 0 or
fatal("Failed: $SSH $PROG < $exportstail: $?"); fatal("Failed: $SSH $PROG < $exportstail: $?");
unlink("$exportstail");
unlink("$exportstail"); #
# Close the lock file. Exiting releases it, but might as well.
#
close(LOCK);
}
#
# Close the lock file. Exiting releases it, but might as well.
#
close(LOCK);
exit(0); exit(0);
sub fatal { sub fatal {
......
#!/usr/bin/perl -w #!/usr/bin/perl -w
use POSIX; use POSIX;
package libtbsetup;
use Exporter;
@ISA = "Exporter";
@EXPORT =
qw ( tbs_initdbi tbs_initlog tbs_prefix tbs_out tbs_exec );
# This has the common functionality for tbprerun/tbrun/tbend. # This has the common functionality for tbprerun/tbrun/tbend.
# tbs_initdbi(dbname) - Initializes a DBI connection to the testbed database # tbs_initdbi(dbname) - Initializes a DBI connection to the testbed database
......
#!/usr/bin/perl -w #!/usr/bin/perl -w
use English; use English;
# package libtestbed;
use Exporter;
@ISA = "Exporter";
@EXPORT =
qw ( SENDMAIL OPENMAIL );
# A library of useful stuff. # A library of useful stuff.
#
#
# Send an email message via sendmail -t. # Send an email message via sendmail -t.
# #
# I am mimicking the PHP mail interface, only because I'm old and its # I am mimicking the PHP mail interface, only because I'm old and its
......
...@@ -50,9 +50,9 @@ $| = 1; ...@@ -50,9 +50,9 @@ $| = 1;
# #
# Load the Testbed support stuff. # Load the Testbed support stuff.
# #
push(@INC, "$TB/lib"); use lib "@prefix@/lib";
require libtestbed; use libdb;
require libdb; use libtestbed;
# #
# Check args. # Check args.
......
...@@ -34,8 +34,8 @@ $| = 1; ...@@ -34,8 +34,8 @@ $| = 1;
# #
# Load the Testbed support stuff. # Load the Testbed support stuff.
# #
push(@INC, "$TB/lib"); use lib "@prefix@/lib";
require libdb; use libdb;
# #
# Check args. # Check args.
......
...@@ -41,9 +41,9 @@ my $MAXLOADS = 2; ...@@ -41,9 +41,9 @@ my $MAXLOADS = 2;
# #
# Load the Testbed support stuff. # Load the Testbed support stuff.
# #
push(@INC, "$TB/lib"); use lib "@prefix@/lib";
require libdb; use libdb;
require libtestbed; use libtestbed;
my $BOSSADDR = "boss.emulab.net"; my $BOSSADDR = "boss.emulab.net";
my $USERADDR = "users.emulab.net"; my $USERADDR = "users.emulab.net";
......
...@@ -26,6 +26,7 @@ my $optlist = ""; ...@@ -26,6 +26,7 @@ my $optlist = "";
my $TB = "@prefix@"; my $TB = "@prefix@";
my $DBNAME = "@TBDBNAME@"; my $DBNAME = "@TBDBNAME@";
my $TBOPS = "@TBOPSEMAIL@"; my $TBOPS = "@TBOPSEMAIL@";
my $TESTMODE = "@TESTMODE@";
my $TFTP = "/tftpboot"; my $TFTP = "/tftpboot";
# #
...@@ -235,8 +236,10 @@ for ($i = 0; $i < $db_result->numrows; $i++) { ...@@ -235,8 +236,10 @@ for ($i = 0; $i < $db_result->numrows; $i++) {
# no need to create any new children here. We just wait until it exits, # no need to create any new children here. We just wait until it exits,
# which means all the nodes are actually rebooting. # which means all the nodes are actually rebooting.
# #
if (system("$nodereboot @nodes")) { if (!$TESTMODE) {
if (system("$nodereboot @nodes")) {
die("Failed to reboot some nodes!"); die("Failed to reboot some nodes!");
}
} }
print STDOUT "Waiting for testbed nodes to finish rebooting ...\n"; print STDOUT "Waiting for testbed nodes to finish rebooting ...\n";
......
...@@ -44,11 +44,9 @@ $| = 1; ...@@ -44,11 +44,9 @@ $| = 1;
$ENV{'PATH'} = "/bin:/usr/bin:"; $ENV{'PATH'} = "/bin:/usr/bin:";
delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'}; delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};
#
# Testbed Support library # Testbed Support library
# use lib "@prefix@/lib";
push(@INC, "$TB/lib"); use libtestbed;
require libtestbed;
# #
# Parse command arguments. Once we return from getopts, all that should be # Parse command arguments. Once we return from getopts, all that should be
......
...@@ -43,12 +43,10 @@ delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'}; ...@@ -43,12 +43,10 @@ delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};
# #
$| = 1; $| = 1;
#
# Load the Testbed support stuff. # Load the Testbed support stuff.
# use lib "@prefix@/lib";
push(@INC, "$TB/lib"); use libdb;
require libtestbed; use libtestbed;
require libdb;
# #
# Check args. # Check args.
......
...@@ -26,8 +26,8 @@ my $TB = "@prefix@"; ...@@ -26,8 +26,8 @@ my $TB = "@prefix@";
# #
# Load the Testbed support stuff. # Load the Testbed support stuff.
# #
push(@INC, "$TB/lib"); use lib "@prefix@/lib";
require libdb; use libdb;
my $osload = "$TB/bin/os_load"; my $osload = "$TB/bin/os_load";
my $nalloc = "$TB/bin/nalloc"; my $nalloc = "$TB/bin/nalloc";
......
...@@ -17,8 +17,8 @@ sub usage() { ...@@ -17,8 +17,8 @@ sub usage() {
my $TB = "@prefix@"; my $TB = "@prefix@";
# Load the Testbed support stuff. # Load the Testbed support stuff.
push(@INC, "$TB/lib"); use lib "@prefix@/lib";
require libdb; use libdb;
my $nalloc = "$TB/bin/nalloc"; my $nalloc = "$TB/bin/nalloc";
my $debug = 0; my $debug = 0;
......
...@@ -58,11 +58,9 @@ $| = 1; ...@@ -58,11 +58,9 @@ $| = 1;
$ENV{'PATH'} = '/bin:/usr/bin'; $ENV{'PATH'} = '/bin:/usr/bin';
delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'}; delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};
#
# Testbed Support library # Testbed Support library
# use lib "@prefix@/lib";
push(@INC, "$TB/lib"); use libtbsetup;
require libtestbed;
# #
# Parse command arguments. Once we return from getopts, all that should # Parse command arguments. Once we return from getopts, all that should
......
...@@ -12,16 +12,16 @@ use DBI; ...@@ -12,16 +12,16 @@ use DBI;
# Set up paths # Set up paths
$TBDB = "@TBDBNAME@"; $TBDB = "@TBDBNAME@";
$TBROOT = "@prefix@"; $TBROOT = "@prefix@";
$TBSETUPLIB = "$TBROOT/lib";
$ENV{'PATH'} = "/usr/bin:$TBROOT/libexec:$TBROOT/libexec/ns2ir" . $ENV{'PATH'} = "/usr/bin:$TBROOT/libexec:$TBROOT/libexec/ns2ir" .
":$TBROOT/sbin:$TBROOT/bin"; ":$TBROOT/sbin:$TBROOT/bin";
push(@INC,$TBSETUPLIB);
# Turn off line buffering. # Turn off line buffering.
$| = 1; $| = 1;
require exitonwarn; use lib "@prefix@/lib";
require libtbsetup; use libtbsetup;
require exitonwarn; # exitonwarn isn't really a module, so just require it
$dolog = 1; $dolog = 1;
$force = 0; $force = 0;
......
...@@ -13,16 +13,16 @@ use DBI; ...@@ -13,16 +13,16 @@ use DBI;
# Set up paths # Set up paths
$TBDB = "@TBDBNAME@"; $TBDB = "@TBDBNAME@";
$TBROOT = "@prefix@"; $TBROOT = "@prefix@";
$TBSETUPLIB = "$TBROOT/lib";
$ENV{'PATH'} = "/usr/bin:$TBROOT/libexec:$TBROOT/libexec/ns2ir" . $ENV{'PATH'} = "/usr/bin:$TBROOT/libexec:$TBROOT/libexec/ns2ir" .
":$TBROOT/sbin:$TBROOT/bin"; ":$TBROOT/sbin:$TBROOT/bin";
push(@INC,$TBSETUPLIB);
# Turn off line buffering. # Turn off line buffering.
$| = 1; $| = 1;
require exitonwarn; use lib "@prefix@/lib";
require libtbsetup; use libtbsetup;
require exitonwarn; # exitonwarn isn't really a module, so just require it
if ($#ARGV < 2 || $#ARGV > 3 || if ($#ARGV < 2 || $#ARGV > 3 ||
($#ARGV == 3 && $ARGV[0] ne "-nologfile")) { ($#ARGV == 3 && $ARGV[0] ne "-nologfile")) {
......
...@@ -16,16 +16,16 @@ use DBI; ...@@ -16,16 +16,16 @@ use DBI;
$TESTMODE = @TESTMODE@; $TESTMODE = @TESTMODE@;
$TBDB = "@TBDBNAME@"; $TBDB = "@TBDBNAME@";
$TBROOT = "@prefix@"; $TBROOT = "@prefix@";
$TBSETUPLIB = "$TBROOT/lib";
$ENV{'PATH'} = "/usr/bin:$TBROOT/libexec:$TBROOT/libexec/ns2ir" . $ENV{'PATH'} = "/usr/bin:$TBROOT/libexec:$TBROOT/libexec/ns2ir" .
":$TBROOT/sbin:$TBROOT/bin"; ":$TBROOT/sbin:$TBROOT/bin";
push(@INC,$TBSETUPLIB);
# Turn off line buffering. # Turn off line buffering.
$| = 1; $| = 1;
require exitonwarn; use lib "@prefix@/lib";
require libtbsetup; use libtbsetup;
require exitonwarn; # exitonwarn isn't really a module, so just require it
$dolog = 1; $dolog = 1;
......
...@@ -15,16 +15,16 @@ use DBI; ...@@ -15,16 +15,16 @@ use DBI;
$TESTMODE = @TESTMODE@; $TESTMODE = @TESTMODE@;
$TBDB = "@TBDBNAME@"; $TBDB = "@TBDBNAME@";
$TBROOT = "@prefix@"; $TBROOT = "@prefix@";
$TBSETUPLIB = "$TBROOT/lib";
$ENV{'PATH'} = "/usr/bin:$TBROOT/libexec:$TBROOT/libexec/ns2ir" . $ENV{'PATH'} = "/usr/bin:$TBROOT/libexec:$TBROOT/libexec/ns2ir" .
":$TBROOT/sbin:$TBROOT/bin"; ":$TBROOT/sbin:$TBROOT/bin";
push(@INC,$TBSETUPLIB);
# Turn off line buffering. # Turn off line buffering.
$| = 1; $| = 1;
require exitonwarn; use lib "@prefix@/lib";
require libtbsetup; use libtbsetup;
require exitonwarn; # exitonwarn isn't really a module, so just require it
$dolog = 1; $dolog = 1;
$force = 0; $force = 0;
......
...@@ -3,8 +3,8 @@ ...@@ -3,8 +3,8 @@
my $TB = "@prefix@"; my $TB = "@prefix@";
my $debug=0; my $debug=0;
push(@INC, "$TB/lib"); use lib "@prefix@/lib";
require libdb; use libdb;
if ( @ARGV < 4 ) { if ( @ARGV < 4 ) {
print STDERR print STDERR
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment