auth/update-hook/pm: make &log() a common function

This commit is contained in:
Sitaram Chamarty 2010-01-31 23:10:12 +05:30 committed by Sitaram Chamarty
parent 90fed77927
commit 0b960cfae2
3 changed files with 14 additions and 14 deletions

View file

@ -42,6 +42,12 @@ sub wrap_open {
return $fh; return $fh;
} }
sub log_it {
open my $log_fh, ">>", $ENV{GL_LOG} or die "open log failed: $!\n";
print $log_fh @_;
close $log_fh or die "close log failed: $!\n";
}
# ---------------------------------------------------------------------------- # ----------------------------------------------------------------------------
# where is the rc file hiding? # where is the rc file hiding?
# ---------------------------------------------------------------------------- # ----------------------------------------------------------------------------

View file

@ -38,8 +38,7 @@ require "$bindir/gitolite.pm";
&where_is_rc(); &where_is_rc();
die "parse $ENV{GL_RC} failed: " . ($! or $@) unless do $ENV{GL_RC}; die "parse $ENV{GL_RC} failed: " . ($! or $@) unless do $ENV{GL_RC};
# we need to pass GL_ADMINDIR and the bindir to the child hooks (well only the # we need to pass GL_ADMINDIR and the bindir to the child hooks
# admin repo's post-update hook but still...)
$ENV{GL_ADMINDIR} = $GL_ADMINDIR; $ENV{GL_ADMINDIR} = $GL_ADMINDIR;
$ENV{GL_BINDIR} = $bindir; $ENV{GL_BINDIR} = $bindir;
@ -149,12 +148,7 @@ $GL_LOGT =~ s/%m/$m/g;
$GL_LOGT =~ s/%d/$d/g; $GL_LOGT =~ s/%d/$d/g;
$ENV{GL_LOG} = $GL_LOGT; $ENV{GL_LOG} = $GL_LOGT;
# if log failure isn't important enough to block access, get rid of all the &log_it("$ENV{GL_TS}\t$ENV{SSH_ORIGINAL_COMMAND}\t$user\n");
# error checking
open my $log_fh, ">>", $ENV{GL_LOG}
or die "open log failed: $!\n";
print $log_fh "$ENV{GL_TS}\t$ENV{SSH_ORIGINAL_COMMAND}\t$user\n";
close $log_fh or die "close log failed: $!\n";
# ---------------------------------------------------------------------------- # ----------------------------------------------------------------------------
# over to git now # over to git now

View file

@ -33,6 +33,10 @@ die "parse $ENV{GL_RC} failed: " . ($! or $@) unless do $ENV{GL_RC};
# then "do" the compiled config file, whose name we now know # then "do" the compiled config file, whose name we now know
die "parse $GL_CONF_COMPILED failed: " . ($! or $@) unless do $GL_CONF_COMPILED; die "parse $GL_CONF_COMPILED failed: " . ($! or $@) unless do $GL_CONF_COMPILED;
# we've started to need some common subs in what used to be a small, cute,
# little script that barely spanned a few lines :(
require "$ENV{GL_BINDIR}/gitolite.pm";
# ---------------------------------------------------------------------------- # ----------------------------------------------------------------------------
# start... # start...
# ---------------------------------------------------------------------------- # ----------------------------------------------------------------------------
@ -118,11 +122,7 @@ check_ref($_) for @refs;
# if we returned at all, all the checks succeeded, so we log the action and exit 0 # if we returned at all, all the checks succeeded, so we log the action and exit 0
# logging note: if log failure isn't important enough to block pushes, get rid &log_it("$ENV{GL_TS} $perm\t" .
# of all the error checking
open my $log_fh, ">>", $ENV{GL_LOG} or die "open log failed: $!\n";
print $log_fh "$ENV{GL_TS} $perm\t" .
substr($oldsha, 0, 14) . "\t" . substr($newsha, 0, 14) . substr($oldsha, 0, 14) . "\t" . substr($newsha, 0, 14) .
"\t$ENV{GL_REPO}\t$ref\t$ENV{GL_USER}\t$log_refex\n"; "\t$ENV{GL_REPO}\t$ref\t$ENV{GL_USER}\t$log_refex\n");
close $log_fh or die "close log failed: $!\n";
exit 0; exit 0;