Permalink
Browse files

Implement IO#close_on_exec{=,?}

  • Loading branch information...
1 parent 186b8bb commit 2e506ff9c4ba9e44db080e04295144d3e0325d67 @jfirebaugh jfirebaugh committed Apr 10, 2012
Showing with 20 additions and 0 deletions.
  1. +4 −0 kernel/common/file.rb
  2. +13 −0 kernel/common/io19.rb
  3. +3 −0 rakelib/platform.rake
View
@@ -24,6 +24,10 @@ module Constants
# O_ACCMODE is /undocumented/ for fcntl() on some platforms
ACCMODE = Rubinius::Config['rbx.platform.fcntl.O_ACCMODE']
+ F_GETFD = Rubinius::Config['rbx.platform.fcntl.F_GETFD']
+ F_SETFD = Rubinius::Config['rbx.platform.fcntl.F_SETFD']
+ FD_CLOEXEC = Rubinius::Config['rbx.platform.fcntl.FD_CLOEXEC']
+
RDONLY = Rubinius::Config['rbx.platform.file.O_RDONLY']
WRONLY = Rubinius::Config['rbx.platform.file.O_WRONLY']
RDWR = Rubinius::Config['rbx.platform.file.O_RDWR']
View
@@ -537,6 +537,19 @@ def binmode?
!@binmode.nil?
end
+ def close_on_exec=(value)
+ if value
+ fcntl(F_SETFD, fcntl(F_GETFD) | FD_CLOEXEC)
+ else
+ fcntl(F_SETFD, fcntl(F_GETFD) & ~FD_CLOEXEC)
+ end
+ nil
+ end
+
+ def close_on_exec?
+ (fcntl(F_GETFD) & FD_CLOEXEC) != 0
+ end
+
def self.pipe(external_encoding=nil, internal_encoding=nil)
lhs = allocate
rhs = allocate
View
@@ -198,6 +198,9 @@ file 'runtime/platform.conf' => deps do |task|
F_GETFL
F_SETFL
O_ACCMODE
+ F_GETFD
+ F_SETFD
+ FD_CLOEXEC
]
fcntl_constants.each { |c| cg.const c }

0 comments on commit 2e506ff

Please sign in to comment.