diff options
author | normal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-07-12 23:23:25 +0000 |
---|---|---|
committer | normal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-07-12 23:23:25 +0000 |
commit | c6b85fcd0152b482b051bee5f7d5afbc975c9d85 (patch) | |
tree | c644d4a8fdd8200fe199deddd41fff10814308df /process.c | |
parent | cb5598a419fdbd5851da7ca818ad275266532fb2 (diff) | |
download | ruby-c6b85fcd0152b482b051bee5f7d5afbc975c9d85.tar.gz |
timer_thread: do not close pipes around fork
There's actually no need to close the pipes used by the
sleepy timer thread before forking, only to stop the timer
thread itself.
Instead, we only close the parent pipes in the child process,
either via close-on-exec flag or when reinitializing the timer
thread.
This change will be necessary when we allow
rb_wait_for_single_fd and rb_thread_fd_select to wait on the
timer_thread_pipe.normal[0] directly and eliminate timer thread.
I don't anticipate compatibility problems with this change
alone.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63960 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'process.c')
-rw-r--r-- | process.c | 22 |
1 files changed, 20 insertions, 2 deletions
@@ -287,12 +287,30 @@ static ID id_hertz; #define ALWAYS_NEED_ENVP 0 #endif +static void +assert_close_on_exec(int fd) +{ +#if VM_CHECK_MODE > 0 +#if defined(HAVE_FCNTL) && defined(F_GETFD) && defined(FD_CLOEXEC) + int flags = fcntl(fd, F_GETFD); + if (flags == -1) { + static const char m[] = "reserved FD closed unexpectedly?\n"; + write(2, m, sizeof(m) - 1); + return; + } + if (flags & FD_CLOEXEC) return; + rb_bug("reserved FD did not have close-on-exec set"); +#else + rb_bug("reserved FD without close-on-exec support"); +#endif /* FD_CLOEXEC */ +#endif /* VM_CHECK_MODE */ +} + static inline int close_unless_reserved(int fd) { - /* We should not have reserved FDs at this point */ if (rb_reserved_fd_p(fd)) { /* async-signal-safe */ - rb_async_bug_errno("BUG timer thread still running", 0 /* EDOOFUS */); + assert_close_on_exec(fd); return 0; } return close(fd); /* async-signal-safe */ |