Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SystemCallError: Unknown error - mkdir failed #4402

Open
frankwong15 opened this issue Dec 20, 2016 · 6 comments
Open

SystemCallError: Unknown error - mkdir failed #4402

frankwong15 opened this issue Dec 20, 2016 · 6 comments

Comments

@frankwong15
Copy link
Contributor

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 added a commit to frankwong15/jruby that referenced this issue Dec 20, 2016
@frankwong15
Copy link
Contributor Author

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
Copy link
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
Copy link
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
Copy link

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.

@headius
Copy link
Member

headius commented Jan 24, 2017

@nobu I guess the race would be if some other thread is doing a mkdir at the same time? But wouldn't the outcome simply be that one thread creates the directory and another fails to create it but succeeds in the iteration? I guess there's also an issue if one thread wants to use different permissions...the second thread would fail to create the dir, then see it's there, and proceed as if the modes were fine.

@frankwong15 Perhaps it's fine to just let it fail and omit the second part of the patch, as @nobu suggests?

@frankwong15
Copy link
Contributor Author

It is fine for me. First part of the patch is enough for my use case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants