logging die and warn messages

- change a few important die()s to _die()s
  - setup SIGs for both die and warn so any others will get caught
redis
Sitaram Chamarty 2012-04-16 17:14:03 +05:30
parent 67327ebfb4
commit 581e79d745
6 changed files with 11 additions and 7 deletions

View File

@ -25,9 +25,9 @@ my $repo = shift;
my $on = ( shift eq 'on' );
if ( $repo eq '@all' ) {
die "you are not authorized\n" if $ENV{GL_USER} and not is_admin();
_die "you are not authorized" if $ENV{GL_USER} and not is_admin();
} else {
die "you are not authorized\n" if $ENV{GL_USER} and not owns($repo);
_die "you are not authorized" if $ENV{GL_USER} and not owns($repo);
}
my $msg = join( " ", @ARGV );

View File

@ -64,6 +64,7 @@ sub dbg {
}
sub _warn {
gl_log( 'warn', @_ );
if ( $ENV{D} and $ENV{D} >= 3 ) {
cluck "WARNING: ", @_, "\n";
} elsif ( defined( $ENV{D} ) ) {
@ -72,6 +73,7 @@ sub _warn {
warn "WARNING: ", @_, "\n";
}
}
$SIG{__WARN__} = \&_warn;
sub _die {
gl_log( 'die', @_ );
@ -83,6 +85,7 @@ sub _die {
die "FATAL: " . join( ",", @_ ) . "\n";
}
}
$SIG{__DIE__} = \&_die;
sub usage {
_warn(shift) if @_;

View File

@ -25,6 +25,8 @@ package Gitolite::Easy;
%rc
say
say2
_die
_warn
_print
usage
);

View File

@ -62,14 +62,14 @@ sub check_vrefs {
} else {
my ( $dummy, $pgm, @args ) = split '/', $vref;
$pgm = "$ENV{GL_BINDIR}/VREF/$pgm";
-x $pgm or die "$vref: helper program missing or unexecutable\n";
-x $pgm or _die "$vref: helper program missing or unexecutable";
open( my $fh, "-|", $pgm, @_, $vref, @args ) or die "$vref: can't spawn helper program: $!\n";
open( my $fh, "-|", $pgm, @_, $vref, @args ) or _die "$vref: can't spawn helper program: $!";
while (<$fh>) {
my ( $ref, $deny_message ) = split( ' ', $_, 2 );
check_vref( $aa, $ref, $deny_message );
}
close($fh) or die $!
close($fh) or _die $!
? "Error closing sort pipe: $!"
: "$vref: helper program exit status $?";
}

View File

@ -138,7 +138,7 @@ sub setup_gladmin {
tsh_try("git config --get user.name") or tsh_run( "git config user.name '$ENV{USER} on '" . `hostname` );
tsh_try("git diff --cached --quiet")
or tsh_try("git commit -am 'gl-setup $argv'")
or die "setup failed to commit to the admin repo";
or _die "setup failed to commit to the admin repo";
delete $ENV{GIT_WORK_TREE};
}

View File

@ -34,7 +34,6 @@ my $old_ak = slurp($akfile);
my @non_gl = grep { not /^# gito.*start/ .. /^# gito.*end/ } slurp($akfile);
chomp(@non_gl);
my %seen = map { $_ => 'a non-gitolite key' } ( fp(@non_gl) );
# die 1;
# pubkey files
chomp( my @pubkeys = `find keydir -type f -name "*.pub" | sort` );