From b574a4d4a1f1d77fa0224b02774456107cdbc932 Mon Sep 17 00:00:00 2001 From: akr Date: Sat, 22 Oct 2011 09:58:15 +0000 Subject: * include/ruby/intern.h (rb_fd_set_cloexec): declared. * io.c (rb_fd_set_cloexec): new function. (ruby_dup): call rb_fd_set_cloexec to set close-on-exec flag. (rb_sysopen_internal): ditto. (rb_pipe): ditto. (io_reopen): ditto. (io_cntl): ditto. * process.c (rb_f_exec): change the default :close_others option to true. (rb_f_system): ditto. (move_fds_to_avoid_crash): call rb_fd_set_cloexec to set close-on-exec flag. (ruby_setsid): ditto. (rb_daemon): ditto. * thread_pthread.c (rb_thread_create_timer_thread): call rb_fd_set_cloexec to set close-on-exec flag. * ruby.c (load_file_internal): ditto. * file.c (rb_file_s_truncate): ditto. (file_load_ok): ditto. * random.c (fill_random_seed): ditto. * ext/pty/pty.c (chfunc): ditto. (get_device_once): ditto. * ext/openssl/ossl_bio.c (ossl_obj2bio): ditto. * ext/socket/init.c (rsock_socket): ditto. (rsock_s_accept_nonblock): ditto. (rsock_s_accept): ditto. * ext/socket/socket.c (rsock_sock_s_socketpair): ditto. * ext/socket/ancdata.c (discard_cmsg): ditto. (make_io_for_unix_rights): ditto. * ext/socket/unixsocket.c (unix_recv_io): ditto. * ext/io/console/console.c (console_dev): ditto. [ruby-core:38140] [Feature #5041] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33507 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- process.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'process.c') diff --git a/process.c b/process.c index a2cd4c6867..10020f6095 100644 --- a/process.c +++ b/process.c @@ -1870,7 +1870,7 @@ rb_f_exec(int argc, VALUE *argv) rb_exec_arg_init(argc, argv, TRUE, &earg); if (NIL_P(rb_ary_entry(earg.options, EXEC_OPTION_CLOSE_OTHERS))) - rb_exec_arg_addopt(&earg, ID2SYM(rb_intern("close_others")), Qfalse); + rb_exec_arg_addopt(&earg, ID2SYM(rb_intern("close_others")), Qtrue); rb_exec_arg_fixup(&earg); rb_exec_err(&earg, errmsg, sizeof(errmsg)); @@ -2511,7 +2511,7 @@ move_fds_to_avoid_crash(int *fdp, int n, VALUE fds) ret = fcntl(fdp[i], F_DUPFD, min); if (ret == -1) return -1; - rb_update_max_fd(ret); + rb_fd_set_cloexec(ret); close(fdp[i]); fdp[i] = ret; } @@ -3089,7 +3089,7 @@ rb_f_system(int argc, VALUE *argv) chfunc = signal(SIGCHLD, SIG_DFL); #endif - pid = rb_spawn_internal(argc, argv, FALSE, NULL, 0); + pid = rb_spawn_internal(argc, argv, TRUE, NULL, 0); #if defined(HAVE_FORK) || defined(HAVE_SPAWNV) if (pid > 0) { rb_syswait(pid); @@ -3164,8 +3164,7 @@ rb_f_system(int argc, VALUE *argv) * 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 => false : inherit fds (default for system and exec) - * :close_others => true : don't inherit (default for spawn and IO.popen) + * :close_others => true : don't inherit * * If a hash is given as +env+, the environment is * updated by +env+ before exec(2) in the child process. @@ -3560,7 +3559,7 @@ ruby_setsid(void) if (ret == -1) return -1; if ((fd = open("/dev/tty", O_RDWR)) >= 0) { - rb_update_max_fd(fd); + rb_fd_set_cloexec(fd); ioctl(fd, TIOCNOTTY, NULL); close(fd); } @@ -4851,7 +4850,7 @@ rb_daemon(int nochdir, int noclose) err = chdir("/"); if (!noclose && (n = open("/dev/null", O_RDWR, 0)) != -1) { - rb_update_max_fd(n); + rb_fd_set_cloexec(n); (void)dup2(n, 0); (void)dup2(n, 1); (void)dup2(n, 2); -- cgit v1.2.3