Class: AgentJail::Runner
- Inherits:
-
Object
- Object
- AgentJail::Runner
- Defined in:
- lib/agent_jail/runner.rb
Overview
Orchestrates the fork + pipe + monitor pattern. Forks a child, applies a wall-clock timeout monitor thread, reads the result.
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(options, &block) ⇒ Runner
constructor
A new instance of Runner.
Constructor Details
#initialize(options, &block) ⇒ Runner
Returns a new instance of Runner.
7 8 9 10 11 12 13 14 15 |
# File 'lib/agent_jail/runner.rb', line 7 def initialize(, &block) cfg = AgentJail.configuration @timeout = .fetch(:timeout, cfg.default_timeout) @cpu_timeout = .fetch(:cpu_timeout, @timeout) @memory_mb = .fetch(:memory_mb, cfg.default_memory_mb) @fs_allow = .fetch(:fs_allow, cfg.default_fs_allow) @fs_read_allow = .fetch(:fs_read_allow, []) @block = block end |
Instance Method Details
#call ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/agent_jail/runner.rb', line 17 def call read, write = IO.pipe child_pid = fork do read.close Child.new( write: write, cpu_timeout: @cpu_timeout, memory_mb: @memory_mb, fs_allow: @fs_allow, fs_read_allow: @fs_read_allow, block: @block ).run exit!(0) end write.close raw, status = wait_for_child(read, child_pid) read.close parse_result(raw, status) end |