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;
$| = 1;
# Load the Testbed support stuff.
push(@INC, "$TB/lib");
require libdb;
require libtestbed;
use lib "@prefix@/lib";
use libdb;
use libtestbed;
#
# We don't want to run this script unless its the real version.
......
......@@ -17,6 +17,7 @@ use Fcntl ':flock';
#
my $TB = "@prefix@";
my $TBOPS = "@TBOPSEMAIL@";
my $TESTMODE = "@TESTMODE@";
# Note no -n option. We redirect stdin from the new exports file below.
my $SSH = "$TB/bin/sshtb -l root fs.emulab.net";
......@@ -59,20 +60,26 @@ use libtestbed;
# 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.
#
open(LOCK, ">>$lockfile") || fatal("Couldn't open $lockfile\n");
$count = 0;
while (flock(LOCK, LOCK_EX|LOCK_NB) == 0) {
if (!$TESTMODE) {
open(LOCK, ">>$lockfile") || fatal("Couldn't open $lockfile\n");
$count = 0;
while (flock(LOCK, LOCK_EX|LOCK_NB) == 0) {
print "Another /etc/exports update in progress. Waiting a moment ...\n";
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);
}
}
#
# 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 "# DO NOT EDIT below this point. Auto generated entries!\n";
......@@ -220,16 +227,18 @@ close(MAP);
# Fire the new tail file over to the fileserver to finish. We cat the file
# right into it.
#
$UID = 0;
system("$SSH $PROG < $exportstail") == 0 or
if (!$TESTMODE) {
$UID = 0;
system("$SSH $PROG < $exportstail") == 0 or
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);
sub fatal {
......
#!/usr/bin/perl -w
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.
# tbs_initdbi(dbname) - Initializes a DBI connection to the testbed database
......
#!/usr/bin/perl -w
use English;
#
package libtestbed;
use Exporter;
@ISA = "Exporter";
@EXPORT =
qw ( SENDMAIL OPENMAIL );
# A library of useful stuff.
#
#
# Send an email message via sendmail -t.
#
# I am mimicking the PHP mail interface, only because I'm old and its
......
......@@ -50,9 +50,9 @@ $| = 1;
#
# Load the Testbed support stuff.
#
push(@INC, "$TB/lib");
require libtestbed;
require libdb;
use lib "@prefix@/lib";
use libdb;
use libtestbed;
#
# Check args.
......
......@@ -34,8 +34,8 @@ $| = 1;
#
# Load the Testbed support stuff.
#
push(@INC, "$TB/lib");
require libdb;
use lib "@prefix@/lib";
use libdb;
#
# Check args.
......
......@@ -41,9 +41,9 @@ my $MAXLOADS = 2;
#
# Load the Testbed support stuff.
#
push(@INC, "$TB/lib");
require libdb;
require libtestbed;
use lib "@prefix@/lib";
use libdb;
use libtestbed;
my $BOSSADDR = "boss.emulab.net";
my $USERADDR = "users.emulab.net";
......
......@@ -26,6 +26,7 @@ my $optlist = "";
my $TB = "@prefix@";
my $DBNAME = "@TBDBNAME@";
my $TBOPS = "@TBOPSEMAIL@";
my $TESTMODE = "@TESTMODE@";
my $TFTP = "/tftpboot";
#
......@@ -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,
# which means all the nodes are actually rebooting.
#
if (system("$nodereboot @nodes")) {
if (!$TESTMODE) {
if (system("$nodereboot @nodes")) {
die("Failed to reboot some nodes!");
}
}
print STDOUT "Waiting for testbed nodes to finish rebooting ...\n";
......
......@@ -44,11 +44,9 @@ $| = 1;
$ENV{'PATH'} = "/bin:/usr/bin:";
delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};
#
# Testbed Support library
#
push(@INC, "$TB/lib");
require libtestbed;
use lib "@prefix@/lib";
use libtestbed;
#
# Parse command arguments. Once we return from getopts, all that should be
......
......@@ -43,12 +43,10 @@ delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};
#
$| = 1;
#
# Load the Testbed support stuff.
#
push(@INC, "$TB/lib");
require libtestbed;
require libdb;
use lib "@prefix@/lib";
use libdb;
use libtestbed;
#
# Check args.
......
......@@ -26,8 +26,8 @@ my $TB = "@prefix@";
#
# Load the Testbed support stuff.
#
push(@INC, "$TB/lib");
require libdb;
use lib "@prefix@/lib";
use libdb;
my $osload = "$TB/bin/os_load";
my $nalloc = "$TB/bin/nalloc";
......
......@@ -17,8 +17,8 @@ sub usage() {
my $TB = "@prefix@";
# Load the Testbed support stuff.
push(@INC, "$TB/lib");
require libdb;
use lib "@prefix@/lib";
use libdb;
my $nalloc = "$TB/bin/nalloc";
my $debug = 0;
......
......@@ -58,11 +58,9 @@ $| = 1;
$ENV{'PATH'} = '/bin:/usr/bin';
delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};
#
# Testbed Support library
#
push(@INC, "$TB/lib");
require libtestbed;
use lib "@prefix@/lib";
use libtbsetup;
#
# Parse command arguments. Once we return from getopts, all that should
......
......@@ -12,16 +12,16 @@ use DBI;
# Set up paths
$TBDB = "@TBDBNAME@";
$TBROOT = "@prefix@";
$TBSETUPLIB = "$TBROOT/lib";
$ENV{'PATH'} = "/usr/bin:$TBROOT/libexec:$TBROOT/libexec/ns2ir" .
":$TBROOT/sbin:$TBROOT/bin";
push(@INC,$TBSETUPLIB);
# Turn off line buffering.
$| = 1;
require exitonwarn;
require libtbsetup;
use lib "@prefix@/lib";
use libtbsetup;
require exitonwarn; # exitonwarn isn't really a module, so just require it
$dolog = 1;
$force = 0;
......
......@@ -13,16 +13,16 @@ use DBI;
# Set up paths
$TBDB = "@TBDBNAME@";
$TBROOT = "@prefix@";
$TBSETUPLIB = "$TBROOT/lib";
$ENV{'PATH'} = "/usr/bin:$TBROOT/libexec:$TBROOT/libexec/ns2ir" .
":$TBROOT/sbin:$TBROOT/bin";
push(@INC,$TBSETUPLIB);
# Turn off line buffering.
$| = 1;
require exitonwarn;
require libtbsetup;
use lib "@prefix@/lib";
use libtbsetup;
require exitonwarn; # exitonwarn isn't really a module, so just require it
if ($#ARGV < 2 || $#ARGV > 3 ||
($#ARGV == 3 && $ARGV[0] ne "-nologfile")) {
......
......@@ -16,16 +16,16 @@ use DBI;
$TESTMODE = @TESTMODE@;
$TBDB = "@TBDBNAME@";
$TBROOT = "@prefix@";
$TBSETUPLIB = "$TBROOT/lib";
$ENV{'PATH'} = "/usr/bin:$TBROOT/libexec:$TBROOT/libexec/ns2ir" .
":$TBROOT/sbin:$TBROOT/bin";
push(@INC,$TBSETUPLIB);
# Turn off line buffering.
$| = 1;
require exitonwarn;
require libtbsetup;
use lib "@prefix@/lib";
use libtbsetup;
require exitonwarn; # exitonwarn isn't really a module, so just require it
$dolog = 1;
......
......@@ -15,16 +15,16 @@ use DBI;
$TESTMODE = @TESTMODE@;
$TBDB = "@TBDBNAME@";
$TBROOT = "@prefix@";
$TBSETUPLIB = "$TBROOT/lib";
$ENV{'PATH'} = "/usr/bin:$TBROOT/libexec:$TBROOT/libexec/ns2ir" .
":$TBROOT/sbin:$TBROOT/bin";
push(@INC,$TBSETUPLIB);
# Turn off line buffering.
$| = 1;
require exitonwarn;
require libtbsetup;
use lib "@prefix@/lib";
use libtbsetup;
require exitonwarn; # exitonwarn isn't really a module, so just require it
$dolog = 1;
$force = 0;
......
......@@ -3,8 +3,8 @@
my $TB = "@prefix@";
my $debug=0;
push(@INC, "$TB/lib");
require libdb;
use lib "@prefix@/lib";
use libdb;
if ( @ARGV < 4 ) {
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