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

Already on GitHub? Sign in to your account

Add :chdir support for `exec` #987

wants to merge 6 commits into


None yet
3 participants

BanzaiMan commented Sep 4, 2013

Rework the option processing, and add support for :chdir. Note that we are only dealing with fire-and-forget exec.


BanzaiMan commented Sep 5, 2013

$ jruby -ve 'pid = spawn("pwd", :chdir => "/"); p pid; Process.detach(pid); p Dir.pwd'
jruby 1.7.5.dev (1.9.3p392) 2013-09-04 1e4e808 on Java HotSpot(TM) 64-Bit Server VM 1.7.0_25-b15 [darwin-x86_64]
$ jruby -ve 'exec("pwd", chdir: "/")'                                                 
jruby 1.7.5.dev (1.9.3p392) 2013-09-04 1e4e808 on Java HotSpot(TM) 64-Bit Server VM 1.7.0_25-b15 [darwin-x86_64]

@BanzaiMan BanzaiMan commented on the diff Sep 5, 2013

@@ -1761,6 +1761,7 @@ public void setRootFiber(IRubyObject fiber) {
public void setCurrentDirectory(String dir) {
+ System.setProperty("user.dir", dir);

BanzaiMan Sep 5, 2013


It makes sense to set the system property here, but it may not be the best for multi-threaded runtimes.

In that case we need to set system property as appropriate.


enebo Sep 5, 2013


fwiw you might want to getPosix().chdir(dir). In non-native mode it will set this property and in native mode it will actually change chdir. I have never quite figured out how safe chdir is in a JVM process though...


enebo commented Sep 5, 2013

When I was looking at this:

You have an if (something)\ncontinue. Either make that one-liner or put curlies. I suspect IDE autoformatting..

                IRubyObject obj = (IRubyObject) opt;
                if (valid.contains(obj.toString())) {

These two lines are weird for multiple reasons which I am sure you will immediately realize and correct :)


enebo commented Sep 5, 2013

Sorry I should have asked the big question in that last comment. How much fear do you have with adding this support? I know one fear is the MVM scenario where changing one dir will affect all other dirs in other VM instances. Is there anything beyond that?


BanzaiMan commented Sep 7, 2013

More thoughts should be given to if and how this should be implemented. Punting past 1.7.5, for sure.


nirvdrum commented Mar 6, 2016

Is this still valid?


BanzaiMan commented Mar 6, 2016

It is probably still "valid" in the sense that this method needs to exist, but the implementation is faulty for the reasons that Tom raised.

Perhaps we can print a message about that.

In any case, this PR can be closed.

@BanzaiMan BanzaiMan closed this Mar 6, 2016

@BanzaiMan BanzaiMan deleted the gh-985 branch Mar 6, 2016

@enebo enebo modified the milestone: Non-Release May 25, 2016

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