Class: Dia::Application

Inherits:
Object
  • Object
show all
Includes:
SharedFeatures
Defined in:
lib/dia/application.rb

Overview

The Application class provides an interface for executing an application in a sandbox.

Instance Attribute Summary

Attributes included from SharedFeatures

#pid

Instance Method Summary collapse

Methods included from SharedFeatures

#exit_status, #running?, #terminate

Constructor Details

#initialize(profile, app) ⇒ Application

Returns a new instance of Application.

Raises:

  • (ArgumentError)

    It isn’t possible to launch an application with the Profiles::NO_OS_SERVICES profile, and an ArgumentError will be raised if you try to.



16
17
18
19
20
21
22
# File 'lib/dia/application.rb', line 16

def initialize(profile, app)
  @profile = profile
  @app     = app
  raise(ArgumentError, "It is not possible to launch an application with the " \
                       "Dia::Profiles::NO_OS_SERVICES profile at this time") \
                        if @profile == Dia::Profiles::NO_OS_SERVICES
end

Instance Method Details

#runFixnum

This method will spawn a child process, and execute an application in a sandbox.

Raises:



31
32
33
34
35
36
37
38
39
# File 'lib/dia/application.rb', line 31

def run
  @pid = fork do 
    initialize_sandbox
    exec(@app)
  end

  _, @exit_status = Process.wait2(@pid)
  @pid
end

#run_nonblockFixnum

An identical but non-blocking form of #run.



43
44
45
46
47
48
49
50
51
# File 'lib/dia/application.rb', line 43

def run_nonblock
  @pid = fork do
    initialize_sandbox
    exec(@app)
  end

  @exit_status = Process.detach(@pid)
  @pid
end