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
28 28
    VALUE sock = rsock_init_sock(rb_obj_alloc(klass), NUM2INT(fd));
29 29

  
30 30
    GetOpenFile(sock, fptr);
31
    rb_maygvl_fd_fix_cloexec(fptr->fd);
31 32

  
32 33
    return sock;
33 34
}
io.c
8171 8171
#else
8172 8172
    if (fstat(fd, &st) == -1) rb_sys_fail(0);
8173 8173
#endif
8174
    rb_maygvl_fd_fix_cloexec(fd);
8174 8175
    rb_update_max_fd(fd);
8175 8176
#if defined(HAVE_FCNTL) && defined(F_GETFL)
8176 8177
    ofmode = rb_io_oflags_fmode(oflags);
process.c
3374 3374
    }
3375 3375

  
3376 3376
#ifdef HAVE_WORKING_FORK
3377
    if (!eargp->close_others_given || eargp->close_others_do) {
3377
    if (eargp->close_others_do) {
3378 3378
        rb_close_before_exec(3, eargp->close_others_maxhint, eargp->redirect_fds); /* async-signal-safe */
3379 3379
    }
3380 3380
#endif
......
4446 4446
 *          integer : the file descriptor of specified the integer
4447 4447
 *          io      : the file descriptor specified as io.fileno
4448 4448
 *      file descriptor inheritance: close non-redirected non-standard fds (3, 4, 5, ...) or not
4449
 *        :close_others => true  : don't inherit
4449
 *        :close_others => false  : inherit
4450 4450
 *      current directory:
4451 4451
 *        :chdir => str
4452 4452
 *
......
4605 4605
 *    pid = spawn(command, :close_others=>true)  # close 3,4,5,... (default)
4606 4606
 *    pid = spawn(command, :close_others=>false) # don't close 3,4,5,...
4607 4607
 *
4608
 *  :close_others is true by default for spawn and IO.popen.
4608
 *  :close_others is false by default for spawn and IO.popen.
4609 4609
 *
4610 4610
 *  Note that fds which close-on-exec flag is already set are closed
4611 4611
 *  regardless of :close_others option.
test/ruby/test_io.rb
3128 3128
    }
3129 3129
  end
3130 3130

  
3131
  def test_for_fd_close_on_exec
3132
    IO.pipe do |r, w|
3133
      w.close_on_exec = false
3134
      w2 = IO.new(w.fileno, autoclose: false)
3135
      assert_predicate w, :close_on_exec?
3136
      assert_predicate w2, :close_on_exec?
3137
    end
3138
  end if have_close_on_exec?
3139

  
3131 3140
  def test_ioctl_linux
3132 3141
    # Alpha, mips, sparc and ppc have an another ioctl request number scheme.
3133 3142
    # So, hardcoded 0x80045200 may fail.
test/ruby/test_process.rb
1009 1009
    }
1010 1010
  end
1011 1011

  
1012
  def test_close_others_default_false
1013
    IO.pipe do |r,w|
1014
      w.close_on_exec = false
1015
      src = "IO.new(#{w.fileno}).puts(:hi)"
1016
      assert_equal true, system(*%W(#{RUBY} --disable=gems -e #{src}))
1017
      assert_equal "hi\n", r.gets
1018
    end
1019
  end
1020

  
1012 1021
  def test_execopts_redirect_self
1013 1022
    begin
1014 1023
      with_pipe {|r, w|
test/socket/test_basicsocket.rb
150 150
      s = BasicSocket.for_fd(sock.fileno)
151 151
      assert_instance_of BasicSocket, s
152 152
      s.autoclose = false
153

  
154
      sock.close_on_exec = false
155
      s2 = BasicSocket.for_fd(sock.fileno)
156
      s2.autoclose = false
157
      assert_predicate s2, :close_on_exec?
158
      assert_predicate sock, :close_on_exec?
159

  
153 160
      sock.close
154 161
    end
155 162
  end
156
-