Class: Commands::Runners::Fork

Inherits:
Exec show all
Includes:
Concrete
Defined in:
lib/commands/runners/fork.rb

Direct Known Subclasses

Popen, System

Instance Attribute Summary

Attributes inherited from Runner

#command_data_factory

Instance Method Summary collapse

Methods included from Concrete

included

Methods inherited from Exec

#exec

Methods inherited from Runner

#initialize, #initialize_copy, #make_debug, #make_verbose, #raise_on_failures, #run

Methods included from Mockable

#make_mock

Methods included from Hooker

included

Methods included from Hookable

included

Methods included from Abstract

included

Constructor Details

This class inherits a constructor from Commands::Runners::Runner

Instance Method Details

#abort(data) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/commands/runners/fork.rb', line 44

def abort ( data )
  if data.pid
    begin
      hook_trigger :kill, data
      hook_trigger :waitpid, data
    rescue Errno::ESRCH
      hook_trigger :already_killed, data.pid
    end
  end
  super
end

#before_exec(command, data) ⇒ Object



69
70
71
# File 'lib/commands/runners/fork.rb', line 69

def before_exec ( command, data )
  TempPath.clean
end

#exception_raised_during_exec(anException) ⇒ Object



57
58
59
60
61
# File 'lib/commands/runners/fork.rb', line 57

def exception_raised_during_exec ( anException )
  STDERR.reopen(File.new(1))
  STDERR.puts anException
  exit! 127
end

#kill(data) ⇒ Object



64
65
66
# File 'lib/commands/runners/fork.rb', line 64

def kill ( data )
  Process.kill('-KILL', -data.pid)
end

#run_impl(aCommand, data) ⇒ Object

Methods



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/commands/runners/fork.rb', line 27

def run_impl ( aCommand, data )
  data.pid = Kernel.fork do
    begin
      TempPath.fork_init true
      hook_trigger :son, aCommand, data
      super
    rescue Exception => ex
      hook_trigger :exception_raised_during_exec, ex
    end
  end
  hook_trigger :waitpid, data
  if data.status.nil? or not data.status.exitstatus.zero?
    hook_trigger :failure, aCommand, data
  end
end