-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathruby-cgi.rb
More file actions
executable file
·76 lines (60 loc) · 1.55 KB
/
ruby-cgi.rb
File metadata and controls
executable file
·76 lines (60 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/ruby
###############
##########################
# FastCGI Ruby dispatcher
# (C) Derrick Pallas
#
# Authors: Derrick Pallas
# Website: http://derrick.pallas.us/ruby-cgi/
# License: Academic Free License 3.0
# Version: 2005-12-23a
#
require 'rubygems'
require "fcgi"
require "mmap"
maxscripts = 128
maxscripts.freeze
class Script
attr_accessor :map
attr_accessor :mod
attr_accessor :use
end
scripts = {}
mytime = File.stat(__FILE__).mtime
def getBinding(cgi,env)
return binding
end
FCGI.each_cgi do |cgi|
script = cgi.env_table['SCRIPT_FILENAME']
script.freeze
begin
if ( not scripts.key?script or scripts[script].mod < File.stat(script).mtime )
if scripts.key?script
scripts[script].map.munmap
else
scripts[script] = Script.new
end
scripts[script].mod = File.stat(script).mtime
scripts[script].map = Mmap.new script, "r"
end
scripts[script].use = Time.now
Dir.chdir( File.dirname(script) )
eval scripts[script].map, getBinding(cgi,cgi.env_table) if scripts[script].map
if scripts.length > maxscripts
begin
killme = scripts.min { |a,b| a[1].use <=> b[1].use } [0]
scripts[killme].map.munmap
scripts.delete(killme)
rescue Exception
end
end
rescue Exception => bang
puts "<hr><b>Exception:</b>", "<em>", CGI::escapeHTML(bang), "</em>\n"
end if (script && File.stat(script).readable?)
if (File.stat(__FILE__).mtime > mytime)
Process.kill 'SIGHUP', Process.pid
mytime = File.stat(__FILE__).mtime
end
end
# END
######