dia 1.1 → 1.2.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. data/HACKING.md +7 -0
  2. data/NEWS.md +6 -1
  3. data/TODO.md +12 -0
  4. data/lib/dia.rb +1 -0
  5. data/lib/dia/sandbox.rb +25 -10
  6. metadata +7 -23
data/HACKING.md ADDED
@@ -0,0 +1,7 @@
1
+ ## Git policy
2
+
3
+ * "master" should always be in a _working state_, so no experimental code ..
4
+ * Pre releases should never be merged into "master", but should stay in experimental ..
5
+ * The experimental branch is the _one and only_ gateway to being merged into master ..
6
+ So, if you're working on a feature, branch off from experimental, merge back into experimental, and when deemed stable experimental
7
+ will be merged into master ..
data/NEWS.md CHANGED
@@ -1,9 +1,14 @@
1
1
  ## NEWS
2
+ ### 1.2.pre
3
+ * I've decided to use Dia::Sandbox instead of Dia::SandBox but it won't be removed until 1.3 .. (Deprecated for 1.2)
4
+ * I've decided to remove the explicit exit() call in a sandbox spawned with run\_with\_block .. (Introduced in 1.1 Final)
5
+ * Added Dia::Sandbox#terminate for terminating a sandbox.
6
+ * Process.detach(*sandbox pid*) is used in the parent process that spawns a sandbox to avoid collecting zombies ..
2
7
 
3
8
  ### 1.1 (final)
4
9
  * Dia::SandBox#run\_with\_block will exit the child process spawned by itself incase the user forgets to ..
5
10
 
6
- * Added some tests for Dia::SandBox.new#run\_with\_block ..
11
+ * Added some tests for Dia::Sandbox.new#run\_with\_block ..
7
12
  We ain't got full coverage but we're getting there.
8
13
 
9
14
  * A person reported that ffi 0.6.0 does not work with dia ..
data/TODO.md ADDED
@@ -0,0 +1,12 @@
1
+ ## TODO
2
+
3
+ ### 1.3
4
+ * Deprecate and remove Dia::SandBox in favor of Dia::Sandbox ..
5
+
6
+ ### 1.2
7
+
8
+ * Remove link to the experimental branch in the gem spec before release.
9
+
10
+ ### 1.2.pre
11
+
12
+ ..
data/lib/dia.rb CHANGED
@@ -5,6 +5,7 @@ require File.join(File.dirname(__FILE__), 'dia/commonapi.rb')
5
5
  require File.join(File.dirname(__FILE__), 'dia/sandbox.rb')
6
6
 
7
7
  module Dia
8
+ VERSION = '1.2.pre'
8
9
  class SandBoxException < StandardError; end
9
10
  end
10
11
 
data/lib/dia/sandbox.rb CHANGED
@@ -4,6 +4,9 @@ module Dia
4
4
 
5
5
  include Dia::CommonAPI
6
6
 
7
+ # We're going to deprecate Dia::SandBox in favor of Dia::Sandbox in the next release.
8
+ Dia::Sandbox = SandBox
9
+
7
10
  attr_accessor :app_path
8
11
  attr_accessor :profile
9
12
  attr_accessor :pid
@@ -28,16 +31,18 @@ module Dia
28
31
  @pid = fork do
29
32
  if ( ret = sandbox_init(@profile, 0x0001, error = FFI::MemoryPointer.new(:pointer)) ) != 0
30
33
  raise Dia::SandBoxException, "Couldn't sandbox #{@app_path}, sandbox_init returned #{ret} with error message: '#{error.get_pointer(0).read_string}'"
31
- else
32
- exec(@app_path)
33
34
  end
35
+ exec(@app_path)
34
36
  end
37
+
38
+ # parent ..
39
+ Process.detach(@pid)
35
40
  end
36
41
 
37
42
  # The run\_with\_block method will spawn a child process and run a supplied block of ruby code in a sandbox.
38
43
  #
39
- # It may raise any number of exceptions if the sandbox could be initiated ..
40
- # It depends on the restrictions of the sandbox and if the block actually violates a restriction imposed by
44
+ # It may raise any number of exceptions if the sandbox could be initiated ..
45
+ # It depends on the restrictions of the sandbox and if the block violates a restriction imposed by
41
46
  # the sandbox .. In any case, the parent process will not be affected and if you want to catch an exception you
42
47
  # should do so in your block.
43
48
  #
@@ -45,13 +50,23 @@ module Dia
45
50
  # @return [Fixnum] The Process ID(PID) that the sandboxed block of code is being run under.
46
51
  def run_with_block &blk
47
52
  @pid = fork do
48
- if ( ret = sandbox_init(@profile, 0x0001, error = FFI::MemoryPointer.new(:pointer)) ) != 0
49
- raise Dia::SandBoxException, "Couldn't sandbox #{@app_path}, sandbox_init returned #{ret} with error message: '#{error.get_pointer(0).read_string}'"
50
- else
51
- yield
52
- end
53
- exit
53
+ if ( ret = sandbox_init(@profile, 0x0001, error = FFI::MemoryPointer.new(:pointer)) ) != 0
54
+ raise Dia::SandBoxException, "Unable to initialize sandbox .. sandbox_init returned #{ret} with error message: '#{error.get_pointer(0).read_string}'"
55
+ end
56
+ yield
54
57
  end
58
+
59
+ # parent ..
60
+ Process.detach(@pid)
61
+ end
62
+
63
+ # The terminate method will send SIGKILL to a process running in a sandbox.
64
+ # By doing so, it effectively terminates the sandbox.
65
+ #
66
+ # @raise [SystemCallError] It may raise a number of subclasses of SystemCallError if a call to Process.kill was unsuccessful ..
67
+ # @return [Fixnum] It will return 1 when successful ..
68
+ def terminate
69
+ Process.kill('SIGKILL', @pid)
55
70
  end
56
71
 
57
72
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dia
3
3
  version: !ruby/object:Gem::Version
4
- version: "1.1"
4
+ version: 1.2.pre
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Gleeson
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-02-16 00:00:00 +00:00
12
+ date: 2010-02-19 00:00:00 +00:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -41,8 +41,10 @@ extensions: []
41
41
  extra_rdoc_files: []
42
42
 
43
43
  files:
44
+ - HACKING.md
44
45
  - NEWS.md
45
46
  - README.md
47
+ - TODO.md
46
48
  - lib/dia/commonapi.rb
47
49
  - lib/dia/profiles.rb
48
50
  - lib/dia/sandbox.rb
@@ -51,25 +53,7 @@ has_rdoc: true
51
53
  homepage:
52
54
  licenses: []
53
55
 
54
- post_install_message: |+
55
-
56
- ----------------------------------------------------------
57
- Thanks for taking the time to try out Dia 1.1 (Final)
58
-
59
- API docs:
60
- http://yardoc.org/docs/robgleeson-Dia
61
-
62
- NEWS & README:
63
- http://github.com/robgleeson/Dia/blob/master/NEWS.md
64
- http://github.com/robgleeson/Dia/blob/master/README.md
65
-
66
- IRC:
67
- irc.freenode.net / #flowof.info
68
-
69
- Bug tracker:
70
- http://github.com/robgleeson/dia/issues
71
- ----------------------------------------------------------
72
-
56
+ post_install_message: " ********************************************************************\n Thanks for installing Dia! (1.2.pre)\n \n Don't forget to check NEWS.md for what has changed in this release:\n http://github.com/robgleeson/Dia/blob/experimental/NEWS.md\n \n You can chat with us at irc.freenode.net / #flowof.info if you have\n any problems. Feel free to join us!\n ********************************************************************\n"
73
57
  rdoc_options: []
74
58
 
75
59
  require_paths:
@@ -82,9 +66,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
82
66
  version:
83
67
  required_rubygems_version: !ruby/object:Gem::Requirement
84
68
  requirements:
85
- - - ">="
69
+ - - ">"
86
70
  - !ruby/object:Gem::Version
87
- version: "0"
71
+ version: 1.3.1
88
72
  version:
89
73
  requirements: []
90
74