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

Add :chdir support for exec #987

Closed
wants to merge 6 commits into from
Closed

Add :chdir support for exec #987

wants to merge 6 commits into from

Conversation

BanzaiMan
Copy link
Member

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

@BanzaiMan
Copy link
Member Author

$ 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]
/
25966
"/Users/asari/Development/src/jruby"
$ 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]
/

@@ -1761,6 +1761,7 @@ public void setRootFiber(IRubyObject fiber) {
}

public void setCurrentDirectory(String dir) {
System.setProperty("user.dir", dir);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

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

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

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

@nirvdrum
Copy link
Contributor

nirvdrum commented Mar 6, 2016

Is this still valid?

@BanzaiMan
Copy link
Member Author

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 March 6, 2016 03:23
@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
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants