summaryrefslogtreecommitdiff
path: root/git-daemon/git-daemon.pl
diff options
context:
space:
mode:
Diffstat (limited to 'git-daemon/git-daemon.pl')
-rwxr-xr-xgit-daemon/git-daemon.pl52
1 files changed, 24 insertions, 28 deletions
diff --git a/git-daemon/git-daemon.pl b/git-daemon/git-daemon.pl
index 68d8162..91dd727 100755
--- a/git-daemon/git-daemon.pl
+++ b/git-daemon/git-daemon.pl
@@ -15,53 +15,49 @@ use Sys::Syslog;
sub ntoa {
my $sockaddr = shift;
- return ('[?.?.?.?]:?') unless defined $sockaddr;
+ return ('(local)') unless defined $sockaddr;
my ($port,$addr) = sockaddr_in $sockaddr;
$addr = inet_ntoa $addr;
return ("[$addr]:$port",$addr,$port);
}
-our ($client,$client_addr,$client_port) = ::ntoa(getpeername(STDIN));
-our ($server,$server_addr,$server_port) = ::ntoa(getsockname(STDIN));
-our ($service,$path,$host,$uri,$user);
+our ($client,$client_addr,$client_port) = ntoa getpeername STDIN;
+our ($server,$server_addr,$server_port) = ntoa getsockname STDIN;
+our ($service,$path,$host,$user);
openlog 'userv-git-daemon', 'pid', 'daemon';
sub fail { syslog 'err', "$client @_"; exit }
+$SIG{ALRM} = sub { fail "timeout" };
+alarm 30;
+
sub xread {
- my $length = shift;
- my $buffer = "";
- local $SIG{ALRM} = sub { fail "timeout" };
- alarm 30;
- while ($length > length $buffer) {
- my $ret = sysread STDIN, $buffer, $length, length $buffer;
- fail "short read: expected $length bytes, got " . length $buffer
+ my $length = shift; $_ = "";
+ while ($length > length) {
+ my $ret = sysread STDIN, $_, $length, length;
+ fail "Expected $length bytes, got ".length
if defined $ret and $ret == 0;
fail "read: $!" if not defined $ret and $! != EINTR and $! != EAGAIN;
}
- alarm 0;
- return $buffer;
}
-
-my $len_hex = xread 4;
-fail "non-hex packet length" unless $len_hex =~ m{^[0-9a-fA-F]{4}$};
-my $line = xread hex $len_hex;
-if ($line !~ m{^(git-[a-z-]+) /*([!-~]+)\0host=([!-~]+)\0$}) {
- $line =~ s|[^ -~]+| |g;
- fail "could not parse \"$line\""
+xread 4;
+fail "Bad hex in packet length" unless m|^[0-9a-fA-F]{4}$|;
+xread hex;
+unless (($service,$path,$host) =
+ m|^(git-[a-z-]+) /*([!-~]+)\0host=([!-~]+)\0$|) {
+ s|[^ -~]+| |g;
+ fail "Could not parse \"$_\""
}
-($service,$path,$host) = ($1,$2,$3);
-$_ = $uri = "git://$host/$path";
+our $uri = $_ = "git://$host/$path";
for my $cf (@ARGV) { do $cf }
-fail "no user configured for $uri" unless defined $user;
-syslog 'info', "$client $service $uri";
+fail "No user for $uri" unless defined $user;
+syslog 'notice', "$client $service $uri";
-my @opts = map "-D$_=${$main::{$_}}",
- grep defined ${$main::{$_}} && /^[a-z]+$/,
- sort keys %main::;
+my @opts = map "-D$_=${$::{$_}}",
+ grep defined ${$::{$_}} && /^[a-z_]+$/, keys %::;
my @cmd = ('userv', @opts, $user, $service);
no warnings; # suppress errors to stderr
-exec @cmd or fail "exec @cmd: $!";
+exec @cmd or fail "exec userv: $!";
# end