From 3b32ef57ecb04c10f67ea6f424cf599aa2d07aef Mon Sep 17 00:00:00 2001 From: Tony Finch Date: Tue, 30 Mar 2010 20:56:41 +0000 Subject: [PATCH] git-daemon: no need for a special configuration variable namespace --- git-daemon/git-daemon-service.pl | 26 +++++++-------------- git-daemon/git-daemon.pl | 40 ++++++++++++-------------------- 2 files changed, 23 insertions(+), 43 deletions(-) diff --git a/git-daemon/git-daemon-service.pl b/git-daemon/git-daemon-service.pl index ec4b7e1..c62c9a2 100755 --- a/git-daemon/git-daemon-service.pl +++ b/git-daemon/git-daemon-service.pl @@ -11,28 +11,18 @@ use warnings; use Sys::Syslog; -my $service = $ENV{"USERV_SERVICE"}; -$service =~ s|^git-||; +our $check_repo = 1; +our $check_export = 0; +our ($service,$client,$dir,$repo); -${$cf::{$_}} = $ENV{"USERV_U_$_"} +${$main::{$_}} = $ENV{"USERV_U_$_"} for grep s/^USERV_U_//, keys %ENV; -openlog 'userv-git-daemon/$service', 'pid', 'daemon'; - -sub cf::fail { - syslog 'err', "$cf::client @_"; - exit; -} +openlog 'userv-$service', 'pid', 'daemon'; +sub fail { syslog 'err', "$client @_"; exit } -package cf; - -our $check_repo = 1; -our $check_export = 0; -our ($dir,$repo,$client); $_ = our $uri; -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; @@ -47,7 +37,7 @@ fail "bad repository in $uri" fail "repository not exported for $uri" if $check_export and not -e "$dir/git-daemon-export-ok"; -my @cmd = ('git', $service, '--strict', '--timeout=30', $dir); +my @cmd = ($service, '--strict', '--timeout=30', $dir); no warnings; # suppress errors to stderr exec @cmd or fail "exec @cmd: $!"; diff --git a/git-daemon/git-daemon.pl b/git-daemon/git-daemon.pl index 74942a0..68d8162 100755 --- a/git-daemon/git-daemon.pl +++ b/git-daemon/git-daemon.pl @@ -20,18 +20,12 @@ sub ntoa { $addr = inet_ntoa $addr; return ("[$addr]:$port",$addr,$port); } -{ - package cf; - our ($client,$client_addr,$client_port) = ::ntoa(getpeername(STDIN)); - our ($server,$server_addr,$server_port) = ::ntoa(getsockname(STDIN)); -} +our ($client,$client_addr,$client_port) = ::ntoa(getpeername(STDIN)); +our ($server,$server_addr,$server_port) = ::ntoa(getsockname(STDIN)); +our ($service,$path,$host,$uri,$user); openlog 'userv-git-daemon', 'pid', 'daemon'; - -sub fail { - syslog 'err', "$cf::client @_"; - exit; -} +sub fail { syslog 'err', "$client @_"; exit } sub xread { my $length = shift; @@ -51,26 +45,22 @@ sub xread { 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$}) { - package cf; - our ($service,$path,$host) = ($1,$2,$3); - $path =~ s|^/*||; - our $uri = $_ = "git://$host/$path"; -} else { +if ($line !~ m{^(git-[a-z-]+) /*([!-~]+)\0host=([!-~]+)\0$}) { $line =~ s|[^ -~]+| |g; fail "could not parse \"$line\"" } +($service,$path,$host) = ($1,$2,$3); +$_ = $uri = "git://$host/$path"; +for my $cf (@ARGV) { do $cf } -for my $cf (@ARGV) { - package cf; - our ($user,$dir,$repo); - do $cf; -} -fail "no user configured for $cf::uri" unless defined $cf::user; -syslog 'info', "$cf::client $cf::service $cf::uri"; +fail "no user configured for $uri" unless defined $user; +syslog 'info', "$client $service $uri"; + +my @opts = map "-D$_=${$main::{$_}}", + grep defined ${$main::{$_}} && /^[a-z]+$/, + sort keys %main::; -my @opts = map "-D$_=${$cf::{$_}}", grep defined ${$cf::{$_}}, sort keys %cf::; -my @cmd = ('userv', @opts, $cf::user, $cf::service); +my @cmd = ('userv', @opts, $user, $service); no warnings; # suppress errors to stderr exec @cmd or fail "exec @cmd: $!"; -- 2.30.2