2015-12-16 00:07:31 -05:00
|
|
|
# frozen_string_literal: false
|
2003-07-23 12:51:36 -04:00
|
|
|
#
|
|
|
|
# cgi_runner.rb -- CGI launcher.
|
|
|
|
#
|
|
|
|
# Author: IPR -- Internet Programming with Ruby -- writers
|
|
|
|
# Copyright (c) 2000 TAKAHASHI Masayoshi, GOTOU YUUZOU
|
|
|
|
# Copyright (c) 2002 Internet Programming with Ruby writers. All rights
|
|
|
|
# reserved.
|
|
|
|
#
|
|
|
|
# $IPR: cgi_runner.rb,v 1.9 2002/09/25 11:33:15 gotoyuzo Exp $
|
|
|
|
|
|
|
|
def sysread(io, size)
|
|
|
|
buf = ""
|
|
|
|
while size > 0
|
|
|
|
tmp = io.sysread(size)
|
|
|
|
buf << tmp
|
2008-11-08 04:41:24 -05:00
|
|
|
size -= tmp.bytesize
|
2003-07-23 12:51:36 -04:00
|
|
|
end
|
|
|
|
return buf
|
|
|
|
end
|
|
|
|
|
|
|
|
STDIN.binmode
|
|
|
|
|
|
|
|
len = sysread(STDIN, 8).to_i
|
|
|
|
out = sysread(STDIN, len)
|
|
|
|
STDOUT.reopen(open(out, "w"))
|
|
|
|
|
|
|
|
len = sysread(STDIN, 8).to_i
|
|
|
|
err = sysread(STDIN, len)
|
|
|
|
STDERR.reopen(open(err, "w"))
|
|
|
|
|
|
|
|
len = sysread(STDIN, 8).to_i
|
|
|
|
dump = sysread(STDIN, len)
|
|
|
|
hash = Marshal.restore(dump)
|
|
|
|
ENV.keys.each{|name| ENV.delete(name) }
|
|
|
|
hash.each{|k, v| ENV[k] = v if v }
|
|
|
|
|
|
|
|
dir = File::dirname(ENV["SCRIPT_FILENAME"])
|
|
|
|
Dir::chdir dir
|
|
|
|
|
2010-11-08 15:59:01 -05:00
|
|
|
if ARGV[0]
|
2008-05-18 09:33:24 -04:00
|
|
|
argv = ARGV.dup
|
|
|
|
argv << ENV["SCRIPT_FILENAME"]
|
|
|
|
exec(*argv)
|
2003-07-23 12:51:36 -04:00
|
|
|
# NOTREACHED
|
|
|
|
end
|
|
|
|
exec ENV["SCRIPT_FILENAME"]
|