Project

General

Profile

Misc #14907 » 0001-process.c-close_others-defaults-to-false.patch

normalperson (Eric Wong), 08/06/2018 07:13 PM

View differences:

ext/socket/basicsocket.c
VALUE sock = rsock_init_sock(rb_obj_alloc(klass), NUM2INT(fd));
GetOpenFile(sock, fptr);
rb_maygvl_fd_fix_cloexec(fptr->fd);
return sock;
}
io.c
#else
if (fstat(fd, &st) == -1) rb_sys_fail(0);
#endif
rb_maygvl_fd_fix_cloexec(fd);
rb_update_max_fd(fd);
#if defined(HAVE_FCNTL) && defined(F_GETFL)
ofmode = rb_io_oflags_fmode(oflags);
process.c
}
#ifdef HAVE_WORKING_FORK
if (!eargp->close_others_given || eargp->close_others_do) {
if (eargp->close_others_do) {
rb_close_before_exec(3, eargp->close_others_maxhint, eargp->redirect_fds); /* async-signal-safe */
}
#endif
......
* integer : the file descriptor of specified the integer
* io : the file descriptor specified as io.fileno
* file descriptor inheritance: close non-redirected non-standard fds (3, 4, 5, ...) or not
* :close_others => true : don't inherit
* :close_others => false : inherit
* current directory:
* :chdir => str
*
......
* pid = spawn(command, :close_others=>true) # close 3,4,5,... (default)
* pid = spawn(command, :close_others=>false) # don't close 3,4,5,...
*
* :close_others is true by default for spawn and IO.popen.
* :close_others is false by default for spawn and IO.popen.
*
* Note that fds which close-on-exec flag is already set are closed
* regardless of :close_others option.
test/ruby/test_io.rb
}
end
def test_for_fd_close_on_exec
IO.pipe do |r, w|
w.close_on_exec = false
w2 = IO.new(w.fileno, autoclose: false)
assert_predicate w, :close_on_exec?
assert_predicate w2, :close_on_exec?
end
end if have_close_on_exec?
def test_ioctl_linux
# Alpha, mips, sparc and ppc have an another ioctl request number scheme.
# So, hardcoded 0x80045200 may fail.
test/ruby/test_process.rb
}
end
def test_close_others_default_false
IO.pipe do |r,w|
w.close_on_exec = false
src = "IO.new(#{w.fileno}).puts(:hi)"
assert_equal true, system(*%W(#{RUBY} --disable=gems -e #{src}))
assert_equal "hi\n", r.gets
end
end
def test_execopts_redirect_self
begin
with_pipe {|r, w|
test/socket/test_basicsocket.rb
s = BasicSocket.for_fd(sock.fileno)
assert_instance_of BasicSocket, s
s.autoclose = false
sock.close_on_exec = false
s2 = BasicSocket.for_fd(sock.fileno)
s2.autoclose = false
assert_predicate s2, :close_on_exec?
assert_predicate sock, :close_on_exec?
sock.close
end
end
-
(2-2/2)