chiark / gitweb /
git-daemon: Log timeout errors and polish code a bit.
authorTony Finch <dot@dotat.at>
Fri, 26 Mar 2010 18:23:24 +0000 (18:23 +0000)
committerIan Jackson <ian@liberator.relativity.greenend.org.uk>
Sat, 22 May 2010 14:54:40 +0000 (15:54 +0100)
git-daemon/git-daemon.pl

index 4f8a7747cb72aa24d96023dffc8a8e65698eeb91..aabef66a6cb7d1692fd7a7d3f38004b8c54746b5 100755 (executable)
@@ -44,7 +44,7 @@ sub fail {
 sub xread {
     my $length = shift;
     my $buffer = "";
-    # simply die if the client takes too long
+    local $SIG{ALRM} = sub { fail "timeout" };
     alarm 30;
     while ($length > length $buffer) {
         my $ret = sysread STDIN, $buffer, $length, length $buffer;
@@ -59,9 +59,7 @@ sub xread {
 
 my $len_hex = xread 4;
 fail "non-hexadecimal packet length" unless $len_hex =~ m{^[0-9a-zA-Z]{4}$};
-my $len = hex $len_hex;
-
-my $line = xread $len;
+my $line = xread hex $len_hex;
 unless ($line =~ m{^git-upload-pack (?:~($TILDE)/)?($REPO[.]git)\0host=($HOSTNAME)\0$}) {
     $line =~ s/[^ -~]+/ /g;
     fail "could not parse \"$line\""
@@ -71,12 +69,10 @@ my $url = $tilde ? "git://$host/~$tilde/$repo" : "git://$host/$repo";
 
 my $user = $vhost_user_from_tilde{$host} ? $tilde : $vhost_default_user{$host};
 fail "no user configuration for $url" unless defined $user;
-
 syslog 'info', "$peer $user $url";
 
 my @opts = ("-DCLIENT=$addr", "-DHOST=$host", "-DREPO=$repo");
 push @opts, "-DTILDE=$tilde" if defined $tilde;
-
 exec 'userv', @opts, $user, 'git-upload-pack'
     or fail "exec userv: $!";