Class: Pione::Util::CGIExecutor
- Inherits:
-
Object
- Object
- Pione::Util::CGIExecutor
- Defined in:
- lib/pione/util/cgi.rb
Overview
CGIExecutor is a execution helper for CGI programs.
Instance Method Summary collapse
-
#exec ⇒ Object
Execute the CGI program.
-
#initialize(cgi_path, cgi_info, chdir, timeout) ⇒ CGIExecutor
constructor
A new instance of CGIExecutor.
Constructor Details
#initialize(cgi_path, cgi_info, chdir, timeout) ⇒ CGIExecutor
Returns a new instance of CGIExecutor.
144 145 146 147 148 149 150 151 152 153 |
# File 'lib/pione/util/cgi.rb', line 144 def initialize(cgi_path, cgi_info, chdir, timeout) @cgi_path = cgi_path @cgi_info = cgi_info @chdir = chdir @timeout = timeout @umask = 077 @cgi_stdin = Temppath.create @cgi_stdout = Temppath.create @pid = nil end |
Instance Method Details
#exec ⇒ Object
Execute the CGI program.
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
# File 'lib/pione/util/cgi.rb', line 156 def exec unless @cgi_path.exist? raise CGIError.not_exist(@cgi_path) end env = @cgi_info.create_env = args = @cgi_info.create_arguments Timeout.timeout(@timeout) do @pid = Kernel.spawn(env, @cgi_path.to_s, *args, ) Process.waitpid(@pid) if @cgi_stdout.exist? return analyze_response(Location[@cgi_stdout].read) else raise CGIError.response_not_found end end rescue Timeout::Error if @pid begin Process.kill(15, @pid) rescue ensure CGIError.timeouted end end rescue Errno::EACCES => e CGIError.cannot_execute_cgi(@cgi_path) end |