Class Uttk::Strategies::CmdBase
In: lib/uttk/strategies/CmdBase.rb
Parent: IOBased

Methods

Included Modules

Abstract

Attributes

my_exit  [R]  Attributes
my_status  [R]  Attributes
pid  [R]  Attributes

Public Class methods

Constructor

[Source]

# File lib/uttk/strategies/CmdBase.rb, line 18
      def initialize ( *a, &b )
        super
        @my_exit, @pid, @my_status = nil, nil, nil
      end

Public Instance methods

[Source]

# File lib/uttk/strategies/CmdBase.rb, line 107
      def epilogue
        waitpid
        super
      end

Protected Instance methods

[Source]

# File lib/uttk/strategies/CmdBase.rb, line 68
      def abort_hook
        unless @pid.nil?
          begin
            Process.kill('-KILL', -@pid)
            waitpid
          rescue Errno::ESRCH
            @log.already_killed = @pid
          end
        end
        @my_exit = 134 # Common status returned by sh on a SIGABRT
        super
      end

[Source]

# File lib/uttk/strategies/CmdBase.rb, line 63
      def father_hook
      end

[Source]

# File lib/uttk/strategies/CmdBase.rb, line 92
      def mk_command
        cmd = @command.to_s.dup
        cmd += ' %a' if cmd !~ /%a/ and @args
        cmd.gsub!(/%a/, @args.to_s) if @args
        if cmd =~ /%i/ and @input and @input.my
          cmd.gsub!(/%i/, @input.my.to_s)
          @input_in_args = true
        else
          @input_in_args = false
        end
        cmd
      end

Methods

[Source]

# File lib/uttk/strategies/CmdBase.rb, line 28
      def run_impl
        begin
          cmd = mk_command
          cmd.gsub!("\n", ' ')

          @log[:running] = cmd

          @pid = Kernel.fork do
            unless @input.nil? or @input_in_args
              STDIN.reopen(@input.my.open('r'))
            end
            STDOUT.reopen(@output.my.open('w')) unless @output.nil?
            STDERR.reopen(@error.my.open('w')) unless @error.nil?
            Dir.chdir(@dir.to_s) if @dir
            begin
              son_hook
              exec(cmd)
            rescue Exception => ex
              @log.exception_raised_during_exec = ex
              exit! 127
            end
          end
          father_hook
          waitpid
          fail('exception raised during exec') if @my_exit == 127
        end
      end

[Source]

# File lib/uttk/strategies/CmdBase.rb, line 58
      def son_hook
      end

[Source]

# File lib/uttk/strategies/CmdBase.rb, line 83
      def waitpid
        return if @pid.nil? or not @my_status.nil?
        Process.waitpid(@pid)
        @my_status = $?
        @my_exit = @my_status.exitstatus
      end

[Validate]