diff options
author | kosaki <kosaki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-10-17 21:09:10 +0000 |
---|---|---|
committer | kosaki <kosaki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-10-17 21:09:10 +0000 |
commit | bc8687acd62584bf2ba9a951289f3f25a4de7229 (patch) | |
tree | dfe6baf6db8c28f6514d1b795b9c8eca308ee462 /file.c | |
parent | 9ec8d4ef30273fb96216a898de2af319479a2a5c (diff) | |
download | ruby-bc8687acd62584bf2ba9a951289f3f25a4de7229.tar.gz |
* ruby.c (open_load_file): reset O_NONBLOCK after open.
Even if S_ISREG() is true, the file may be file on FUSE filesystem
or something. We can't assume O_NONBLOCK is safe.
Moreover, we should wait if the path is point to FIFO. That's
FIFO semantics. GVL should be transparent from ruby script.
Thus, just reopen without O_NONBLOCK for filling the requirements.
[Bug #11060][Bug #11559]
* ruby.c (loadopen_func): new for the above.
* file.c (ruby_is_fd_loadable): new. for checks loadable file type
of not.
* file.c (rb_file_load_ok): use ruby_is_fd_loadble()
* internal.h: add ruby_is_fd_loadble()
* common.mk: now, ruby.o depend on thread.h.
* test/ruby/test_require.rb
(TestRequire#test_loading_fifo_threading_success): new test.
This test successful case that loading from FIFO.
* test/ruby/test_require.rb
(TestRequire#test_loading_fifo_threading_raise): rename from
test_loading_fifo_threading. You souldn't rescue an exception
if you test raise or not.
Moreover, this case should be caught IOError because load(FIFO)
should be blocked until given any input.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52151 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'file.c')
-rw-r--r-- | file.c | 33 |
1 files changed, 25 insertions, 8 deletions
@@ -5670,11 +5670,35 @@ rb_path_check(const char *path) return 1; } +int +ruby_is_fd_loadable(int fd) +{ +#ifdef _WIN32 + return 1; +#else + struct stat st; + + if (fstat(fd, &st) < 0) + return 0; + + if (S_ISREG(st.st_mode)) + return 1; + if (S_ISFIFO(st.st_mode)) + return 1; + + return 0; +#endif +} + #ifndef _WIN32 int rb_file_load_ok(const char *path) { int ret = 1; + /* + open(2) may block if path is FIFO and it's empty. Let's use O_NONBLOCK. + FIXME: Why O_NDELAY is checked? + */ int mode = (O_RDONLY | #if defined O_NONBLOCK O_NONBLOCK | @@ -5685,14 +5709,7 @@ rb_file_load_ok(const char *path) int fd = rb_cloexec_open(path, mode, 0); if (fd == -1) return 0; rb_update_max_fd(fd); -#if !defined DOSISH - { - struct stat st; - if (fstat(fd, &st) || S_ISDIR(st.st_mode)) { - ret = 0; - } - } -#endif + ret = ruby_is_fd_loadable(fd); (void)close(fd); return ret; } |