chiark / gitweb /
git-daemon: tidy up a bit
[userv-utils.git] / git-daemon / git-daemon-service.pl
index 19b632713d43aecab250fe2b5b25bf8d824066fc..f848db8b8bf35e2f5bf1a2c5b7457f35ede2f5de 100755 (executable)
@@ -11,35 +11,30 @@ use warnings;
 
 use Sys::Syslog;
 
 
 use Sys::Syslog;
 
-our $check_repo = 1;
-our $check_export = 0;
-our ($service,$client,$dir,$repo);
+${$::{$_}} = $ENV{"USERV_U_$_"}
+       for grep s|^USERV_U_([a-z_]+)$|$1|, keys %ENV;
 
 
-${$main::{$_}} = $ENV{"USERV_U_$_"}
-    for grep s/^USERV_U_//, keys %ENV;
+our ($client,$service,$path,$host);
 
 openlog "userv-$service", 'pid', 'daemon';
 sub fail { syslog 'err', "$client @_"; exit }
 
 
 openlog "userv-$service", 'pid', 'daemon';
 sub fail { syslog 'err', "$client @_"; exit }
 
-$_ = our $uri;
+our ($check_repo,$check_export,$dir,$repo) = (1,0);
+our $uri = $_ = "git://$host/$path";
 for my $cf (@ARGV) { do $cf }
 
 for my $cf (@ARGV) { do $cf }
 
-fail "no repository configured for $uri" unless defined $repo;
-fail "no directory configured for $uri"  unless defined $dir;
-
 my $home = (getpwuid $<)[7];
 $dir = "$home/$dir" if $dir =~ m|^[^/]|
                     or $dir =~ s|^~/||;
 my $home = (getpwuid $<)[7];
 $dir = "$home/$dir" if $dir =~ m|^[^/]|
                     or $dir =~ s|^~/||;
-$dir = "$dir/$repo";
-
-fail "bad repository in $uri"
-    if $check_repo and $repo !~ /^[0-9A-Za-z._-]+[.]git$/;
-fail "repository not exported for $uri"
-    if $check_export and not -e "$dir/git-daemon-export-ok";
-syslog 'info', "$client $dir";
+fail "Bad filename $repo" if $check_repo
+               and $repo !~ m|^\w[\w.=+-]*\.git$|;
+$dir = "$dir/$repo" if defined $repo;
+$path = $check_export ? "$dir/git-daemon-export-ok" : $dir;
+fail "$! $path" unless -e $path;
+syslog 'notice', "$client $dir";
 
 my @cmd = ($service, '--strict', '--timeout=30', $dir);
 no warnings; # suppress errors to stderr
 
 my @cmd = ($service, '--strict', '--timeout=30', $dir);
 no warnings; # suppress errors to stderr
-exec @cmd or fail "exec @cmd: $!";
+exec @cmd or fail "exec $service: $!";
 
 # end
 
 # end