diff options
author | des <des@FreeBSD.org> | 2003-07-28 09:42:42 +0000 |
---|---|---|
committer | des <des@FreeBSD.org> | 2003-07-28 09:42:42 +0000 |
commit | 7d45a427497eddad72d26ad7be9fc8adcb1cdccc (patch) | |
tree | 0a671d282540706e301155d9ee284f1fc64586f9 /tools | |
parent | 6416064bd673071db7aee16cb9b737f8ca527e5b (diff) | |
download | FreeBSD-src-7d45a427497eddad72d26ad7be9fc8adcb1cdccc.zip FreeBSD-src-7d45a427497eddad72d26ad7be9fc8adcb1cdccc.tar.gz |
- add a -d option which dumps the configuration and exits
- initialize single-valued configuration variables to '' rather than undef
- allow empty values in configuration files
- take care to untaint $etcdir
Diffstat (limited to 'tools')
-rw-r--r-- | tools/tools/tinderbox/tbmaster.pl | 33 |
1 files changed, 28 insertions, 5 deletions
diff --git a/tools/tools/tinderbox/tbmaster.pl b/tools/tools/tinderbox/tbmaster.pl index 0473a2e..174677e 100644 --- a/tools/tools/tinderbox/tbmaster.pl +++ b/tools/tools/tinderbox/tbmaster.pl @@ -40,20 +40,21 @@ my $COPYRIGHT = "Copyright (c) 2003 Dag-Erling Smørgrav. " . "All rights reserved."; my $config; # Name of current config +my $dump; # Dump configuration and exit my $etcdir; # Configuration directory my %CONFIG = ( - 'COMMENT' => undef, + 'COMMENT' => '', 'BRANCHES' => [ 'CURRENT' ], 'PLATFORMS' => [ 'i386' ], - 'DATE' => undef, + 'DATE' => '', 'SANDBOX' => '/tmp/tinderbox', 'LOGDIR' => '%%SANDBOX%%/logs', 'TARGETS' => [ 'update', 'world' ], 'OPTIONS' => [], 'ENV' => [], - 'SENDER' => undef, - 'RECIPIENT' => undef, + 'SENDER' => '', + 'RECIPIENT' => '', 'SUBJECT' => 'Tinderbox failure on %%arch%%/%%machine%%', 'TINDERBOX' => '%%HOME%%/tinderbox', ); @@ -96,6 +97,8 @@ sub readconf($) { die("$fn: syntax error on line $n\n") unless ($line =~ m/^(\w+)\s*=\s*(.*)$/); my ($key, $val) = (uc($1), $2); + $val = '' + unless defined($val); die("$fn: unknown keyword on line $n\n") unless (exists($CONFIG{$key})); if (ref($CONFIG{$key})) { @@ -303,7 +306,7 @@ MAIN:{ $config = `uname -n`; chomp($config); $config =~ s/^(\w+)(\..*)?/$1/; - if ($ENV{'HOME'} =~ m|^((?:/[\w\.-]+)+)/*$|) { + if ($ENV{'HOME'} =~ m/^((?:\/[\w\.-]+)+)\/*$/) { $CONFIG{'HOME'} = $1; $etcdir = "$1/etc"; $ENV{'PATH'} = "$1/bin:$ENV{'PATH'}" @@ -314,6 +317,7 @@ MAIN:{ {Getopt::Long::Configure("auto_abbrev", "bundling");} GetOptions( "c|config=s" => \$config, + "d|dump" => \$dump, "e|etcdir=s" => \$etcdir, ) or usage(); if (@ARGV) { @@ -321,6 +325,10 @@ MAIN:{ } if (defined($etcdir)) { + if ($etcdir !~ m/^([\w\/\.-]+)$/) { + die("invalid etcdir\n"); + } + $etcdir = $1; chdir($etcdir) or die("$etcdir: $!\n"); } @@ -330,6 +338,21 @@ MAIN:{ $CONFIG{'CONFIG'} = $config; $CONFIG{'ETCDIR'} = $etcdir; + if ($dump) { + foreach my $key (sort(keys(%CONFIG))) { + printf("%-12s = ", lc($key)); + if (!defined($CONFIG{$key})) { + print("(undef)"); + } elsif (ref($CONFIG{$key})) { + print(join(", ", @{$CONFIG{$key}})); + } else { + print($CONFIG{$key}); + } + print("\n"); + } + exit(0); + } + if (!length(expand('TINDERBOX')) || !-x expand('TINDERBOX')) { die("Where is the tinderbox script?\n"); } |