subprocess 1.1.0 → 1.2.0

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.
@@ -360,9 +360,10 @@ module Subprocess
360
360
  # Meanwhile, in the parent process...
361
361
 
362
362
  # First, let's close some things we shouldn't have access to
363
- [@child_stdin, @child_stdout, @child_stderr, control_w].each do |fd|
364
- fd.close unless fd.nil?
365
- end
363
+ @child_stdin.close if our_fd?(opts[:stdin])
364
+ @child_stdout.close if our_fd?(opts[:stdout])
365
+ @child_stderr.close if our_fd?(opts[:stderr])
366
+ control_w.close
366
367
 
367
368
  # Any errors during the spawn process? We'll get past this point when the
368
369
  # child execs and the OS closes control_w because of the FD_CLOEXEC
@@ -516,17 +517,14 @@ module Subprocess
516
517
  # descriptor should appear to the child and to this process, respectively.
517
518
  # "mine" is only non-nil in the case of a pipe (in fact, we just return a
518
519
  # list of length one, since ruby will unpack nils from missing list items).
519
- #
520
- # If you pass either an IO or an Integer (i.e., a raw file descriptor), a
521
- # private copy of it will be made using `#dup`.
522
520
  def parse_fd(fd, mode)
523
521
  fds = case fd
524
522
  when PIPE
525
523
  IO.pipe
526
524
  when IO
527
- [fd.dup]
525
+ [fd]
528
526
  when Integer
529
- [IO.new(fd, mode).dup]
527
+ [IO.new(fd, mode)]
530
528
  when String
531
529
  [File.open(fd, mode)]
532
530
  when nil
@@ -538,6 +536,17 @@ module Subprocess
538
536
  mode == 'r' ? fds : fds.reverse
539
537
  end
540
538
 
539
+ # The pair to parse_fd, returns whether or not the file descriptor was
540
+ # opened by us (and therefore should be closed by us).
541
+ def our_fd?(fd)
542
+ case fd
543
+ when PIPE, String
544
+ true
545
+ else
546
+ false
547
+ end
548
+ end
549
+
541
550
  def mark_fd_cloexec(fd)
542
551
  io = IO.new(fd)
543
552
  io.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC)
@@ -1,3 +1,3 @@
1
1
  module Subprocess
2
- VERSION = '1.1.0'
2
+ VERSION = '1.2.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: subprocess
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ authors:
13
13
  autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
- date: 2014-04-30 00:00:00.000000000 Z
16
+ date: 2014-05-01 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: minitest