childprocess 0.4.1 → 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bc6b66871c56637224c64a8a7c6562d86e7a932c
4
- data.tar.gz: c792a3c348e1770cd1d62f8b2f351fe59d070458
3
+ metadata.gz: 63503076c91b015a05049ce4909a79dccffb1fc6
4
+ data.tar.gz: 06207a205990b72490b31ce3af1088b6a49c21c2
5
5
  SHA512:
6
- metadata.gz: f4a4b15be2ab0c554d85397965e620a4740da60dd39d743a69a47d5d46f924483e17a52889cabb404f65b0be93b659b13b585f0889b7fff366ab0802b5a6f809
7
- data.tar.gz: 70341756153abc0bfa838f4a135193e51032a681c6d98cda035727331a589ed9baf2eab32c9007e3d7dcd7a5e822a1ba8a204558052abe0291ed6b023da790ea
6
+ metadata.gz: 81e45d2d76bf9a7d79c3f2accdac8b769994942292ffc2a80d7b9809e06c6d4dd068bcd56c861e0440784287f4c3165030b994173a93369112fcad4ab862a1d2
7
+ data.tar.gz: 29132e001b36f540c75d66984721e23cbef19ff10124b95b53c59a33bec33170a10c9411dd2d96dd36e779d7ade95cf2089d8d0106f8484bee5c8c99937cea2c
@@ -18,7 +18,9 @@ module ChildProcess
18
18
  end
19
19
 
20
20
  @pid = fork {
21
- ::Process.setpgid 0, 0 # same process group as parent
21
+ # Children of the forked process will inherit its process group
22
+ # This is to make sure that all grandchildren dies when this Process instance is killed
23
+ ::Process.setpgid 0, 0 unless keep_pgid?
22
24
 
23
25
  if @cwd
24
26
  Dir.chdir(@cwd)
@@ -92,7 +92,7 @@ module ChildProcess
92
92
 
93
93
  def self.check(errno)
94
94
  if errno != 0
95
- raise Error, Lib.strerror(errno)
95
+ raise Error, Lib.strerror(FFI.errno)
96
96
  end
97
97
  end
98
98
 
@@ -159,6 +159,11 @@ module ChildProcess
159
159
  ptr.read_short
160
160
  end
161
161
 
162
+ def pgroup=(pid)
163
+ self.flags |= Platform::POSIX_SPAWN_SETPGROUP
164
+ Lib.check Lib.posix_spawnattr_setpgroup(@ptr, pid)
165
+ end
166
+
162
167
  def to_ptr
163
168
  @ptr
164
169
  end
@@ -33,7 +33,7 @@ module ChildProcess
33
33
  actions.add_close fileno_for(writer)
34
34
  end
35
35
 
36
- attrs.flags |= Platform::POSIX_SPAWN_SETPGROUP
36
+ attrs.pgroup = 0 unless keep_pgid?
37
37
  attrs.flags |= Platform::POSIX_SPAWN_USEVFORK if defined? Platform::POSIX_SPAWN_USEVFORK
38
38
 
39
39
  # wrap in helper classes in order to avoid GC'ed pointers
@@ -29,13 +29,13 @@ module ChildProcess
29
29
  return true if @exit_code
30
30
 
31
31
  assert_started
32
- pid, status = ::Process.waitpid2(@pid, ::Process::WNOHANG)
32
+ pid, status = ::Process.waitpid2(_pid, ::Process::WNOHANG | ::Process::WUNTRACED)
33
33
  pid = nil if pid == 0 # may happen on jruby
34
34
 
35
35
  log(:pid => pid, :status => status)
36
36
 
37
37
  if pid
38
- @exit_code = status.exitstatus || status.termsig
38
+ set_exit_code(status)
39
39
  end
40
40
 
41
41
  !!pid
@@ -47,11 +47,26 @@ module ChildProcess
47
47
  if exited?
48
48
  exit_code
49
49
  else
50
- _, status = ::Process.waitpid2 @pid
51
- @exit_code = status.exitstatus || status.termsig
50
+ _, status = ::Process.waitpid2 _pid
51
+ set_exit_code(status)
52
52
  end
53
53
  end
54
54
 
55
+ #
56
+ # Set this to true to avoid resetting the parent group id in the child
57
+ #
58
+ # This is a temporary workaround for https://github.com/jarib/childprocess/issues/69
59
+ # and will probably be removed in the future.
60
+ #
61
+
62
+ def keep_pgid=(bool)
63
+ @keep_pgid = bool
64
+ end
65
+
66
+ def keep_pgid?
67
+ !!@keep_pgid
68
+ end
69
+
55
70
  private
56
71
 
57
72
  def send_term
@@ -66,7 +81,19 @@ module ChildProcess
66
81
  assert_started
67
82
 
68
83
  log "sending #{sig}"
69
- ::Process.kill sig, -@pid
84
+ ::Process.kill sig, _pid
85
+ end
86
+
87
+ def set_exit_code(status)
88
+ @exit_code = status.exitstatus || status.termsig
89
+ end
90
+
91
+ def _pid
92
+ if keep_pgid?
93
+ @pid
94
+ else
95
+ -@pid # negative pid == process group
96
+ end
70
97
  end
71
98
 
72
99
  end # Process
@@ -1,3 +1,3 @@
1
1
  module ChildProcess
2
- VERSION = "0.4.1"
2
+ VERSION = "0.4.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: childprocess
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jari Bakken
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-13 00:00:00.000000000 Z
11
+ date: 2014-02-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec