summaryrefslogtreecommitdiffstats
path: root/script/git-daemon
diff options
context:
space:
mode:
authorDavid A. Cuadrado <krawek@gmail.com>2008-04-14 12:09:18 -0500
committerDavid A. Cuadrado <krawek@gmail.com>2008-04-14 12:09:18 -0500
commit00ae1324b8177354c314e5fb0fdc02da69cb2473 (patch)
tree4588319230cfd6217d3c109d7fd822f720ba3244 /script/git-daemon
parent9fea730da3f142c6cd00ed669efab9988d4338be (diff)
downloadgitorious-mainline-outdated-00ae1324b8177354c314e5fb0fdc02da69cb2473.zip
gitorious-mainline-outdated-00ae1324b8177354c314e5fb0fdc02da69cb2473.tar.gz
gitorious-mainline-outdated-00ae1324b8177354c314e5fb0fdc02da69cb2473.tar.bz2
check max connections
Signed-off-by: David A. Cuadrado <krawek@gmail.com>
Diffstat (limited to 'script/git-daemon')
-rwxr-xr-xscript/git-daemon14
1 files changed, 14 insertions, 0 deletions
diff --git a/script/git-daemon b/script/git-daemon
index f5d91c2..bb10a1f 100755
--- a/script/git-daemon
+++ b/script/git-daemon
@@ -12,6 +12,10 @@ Rails.configuration.log_level = :info # Disable debug
BASE_PATH = File.expand_path(GitoriousConfig['repository_base_path'])
+MAX_CHILDREN = 35
+$children_reaped = 0
+$children_active = 0
+
module Git
class Daemon
@@ -27,13 +31,23 @@ class Daemon
@geoip = GeoIP.new(File.join(RAILS_ROOT, "data", "GeoIP.dat"))
trap "CLD" do
pid = Process.wait
+ $children_reaped += 1
log(pid, "Disconnected. (status=#{$?.exitstatus})")
+
+ $children_reaped = $children_active = 0 if $children_reaped == $children_active
end
port = 9418
server = TCPServer.new('localhost', port)
service_regexp = /(\w{4})(git-[\w-]+)\s(.+)\x0host=([\w\.\-]+)/.freeze
while session = server.accept
+ $children_active += 1
+
+ if $children_active - $children_reaped > MAX_CHILDREN
+ session.close
+ next
+ end
+
line = session.recv(1000)
timeout = 30
if line =~ service_regexp