SystemCallError: Unknown error - mkdir failed #4402

Open
frankwong15 opened this Issue Dec 20, 2016 · 4 comments

Projects

None yet

3 participants

@frankwong15

Environment

jruby 9.1.6.0 (2.3.1) 2016-11-09 0150a76 Java HotSpot(TM) 64-Bit Server VM 25.111-b14 on 1.8.0_111-b14 +jit [linux-x86_64]

Linux frank-nb 4.4.0-53-generic #74-Ubuntu SMP Fri Dec 2 15:59:10 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux

Sample code below:
https://gist.github.com/frankwong15/24b36c82be497fbd8b7d61598efcb16e

Expected Behavior

JRuby has access to /tmp according to security policy and it should be able to create folder under /tmp.

Actual Behavior

JRuby raises SystemCallError because it tries to create folder / which it has no access.

SystemCallError: Unknown error - mkdir failed
mkdir at org/jruby/RubyDir.java:449
fu_mkdir at /home/frank/.rvm/rubies/jruby-9.1.6.0/lib/ruby/stdlib/fileutils.rb:253
block in mkdir_p at /home/frank/.rvm/rubies/jruby-9.1.6.0/lib/ruby/stdlib/fileutils.rb:227
reverse_each at org/jruby/RubyArray.java:1818
block in mkdir_p at /home/frank/.rvm/rubies/jruby-9.1.6.0/lib/ruby/stdlib/fileutils.rb:225
mkdir_p at /home/frank/.rvm/rubies/jruby-9.1.6.0/lib/ruby/stdlib/fileutils.rb:211

at -e:1

@frankwong15 frankwong15 added a commit to frankwong15/jruby that referenced this issue Dec 20, 2016
@frankwong15 frankwong15 Fix #4402. Do not create file from root folder 07c26f4
@frankwong15

I patched fileutils.rb. Instead of creating the following folders

/
/tmp
/tmp/hello
/tmp/hello/world

It only creates

/tmp/hello
/tmp/hello/world
@headius
Member
headius commented Jan 6, 2017

This is an interesting case. I assume it doesn't fail if you have no security manager installed?

Your patch to skip already-existing dirs seems simple enough. I'll try it and run some tests here to see what impact it has.

Normally we don't patch the stdlib, since it is intended to match CRuby. In this case, if the patch makes sense and doesn't hurt CRuby, I'll just commit there too.

@headius
Member
headius commented Jan 6, 2017

The patch does not appear to impact tests at all, so it seems good. I'd like our friend @nobu to weigh in (along with anyone else from ruby-core that might be interested).

@nobu
nobu commented Jan 7, 2017

I'm curious what "Unknown error" is, and why it isn't rescued.
The first half seems OK, but I hesitate in the last half as there can be a race condition.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment