History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: JRUBY-822
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Nick Sieger
Reporter: Antti Karanta
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
JRuby

jruby fails to report process exit status correctly

Created: 16/Apr/07 06:06 AM   Updated: 22/Dec/07 06:29 AM
Component/s: None
Affects Version/s: JRuby 0.9.8, JRuby 1.0.0RC1, JRuby 0.9.9, JRuby 1.0.0RC2
Fix Version/s: JRuby 1.0.0RC3

Time Tracking:
Not Specified

Environment: jruby from trunk 16. April, java 1.5.0_11, win xp sp 2


 Description  « Hide
JRuby seems to give 0 as process exit status even if it wasn't. Try this:

C:\>jruby -e "system('ruby -e \"exit(2)\"');print $?>>8"
0

This is a jruby issue, since

C:\>ruby -e "system('ruby -e \"exit(2)\"');print $?>>8"
2

As a minor detail, jruby seems to be a little smarter when finding stuff to execute:

C:\>ruby -e "system('jruby -e \"exit(2)\"');print $?>>8"
-e:1: undefined method `>>' for nil:NilClass (NoMethodError)

i.e. "jruby" executable could not be found. However:

C:\>ruby -e "system('jruby.bat -e \"exit(2)\"');print $?>>8"
2

And jruby seems to be smart enough to find the .bat file even w/out the suffix:

C:\>jruby -e "system('jruby -e \"exit(2)\"');print $?>>8"
0



 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
Charles Oliver Nutter - 16/Apr/07 01:50 PM
I assume the latter "smartness" isn't something you think we should make un-smart. Actually this is probably Java being smart for us, so I'm not sure we could dumb it down if we wanted to.

The process exit stuff should be fixed for sure though.


Antti Karanta - 17/Apr/07 12:06 AM
> I assume the latter "smartness" isn't something you think we should make un-smart.

Definitely not, I just wanted to point out that it behaves a little different than mri. I think this should be documented somewhere, but I don't know what a proper place would be. Is there a document on the differences between mri and jruby? I know, in an ideal world, we'd have no need for such document...


Charles Oliver Nutter - 17/Apr/07 12:18 AM
You'd be my hero if you started such a page (or updated one that might be there?) on the JRuby wiki. Just google "jrubywiki" and you'll find it. I agree this is a good item to put there, and we should make an effort to have a complete list by JRuby 1.0.

Antti Karanta - 17/Apr/07 12:54 AM
You already said I'd be your hero if I fixed the bugs I reported when I joined JRuby mailing list (and I did). = ) So now I guess I'm doubly your hero:

http://headius.com/jrubywiki/index.php/Differences_between_mri_and_jruby

It is linked to from the main wiki page. Now the page contains this process launching thing and missing continuations, but I guess there will be more.


Charles Oliver Nutter - 16/May/07 04:47 PM
Not going to be in RC2, and in danger of falling off 1.0. Assigning to Nick, since he's been closest to the process-launching code. It could be something simple.

Albert Strasheim - 19/May/07 03:13 PM
I did some digging to figure out what's going on here.

The following program gives a better idea of why things go for (I just use Python to generate the exit code ):

puts system('python -c "import sys; sys.exit(2)"')
puts $?
puts $?>>8

CRuby on Windows and Linux prints:

false
512
2

JRuby on Windows and Linux prints:

false
2
0

The value put into $? is the return value of waitFor() called on a Process returned from ShellLauncher.run(IRubyObject[]). This Process can either be a ScriptThreadProcess or whatever is returned by Runtime.getRuntime().exec(...). From the OpenJDK sources I can see that this is a java.lang.ProcessImpl on Windows and a java.lang.UNIXProcess on Solaris and Linux.

On Windows, ProcessImpl's waitFor ends up calling the Win32 API function GetExitCodeProcess. On Solaris/Linux, they do all kinds of interesting things with the return value of waitpid, depending on whether the exit code indicates that the process was terminated by a signal.

In conclusion, it looks like some shifting and/or other mangling of the exit code needs to be done by JRuby before it puts it into $? (at least when using Java's Process implementation; not sure what has to happen for ScriptThreadProcess).


Nick Sieger - 21/May/07 01:46 PM
So would it be sufficient to simply << 8 the exit code before assigning to $??

Albert Strasheim - 21/May/07 02:40 PM
I'd say "probably". It might be worth doing a quick investigation to figure out how MRI came up with that number – do they only shift it (why?) or are there other things afoot.

Albert Strasheim - 22/May/07 05:27 AM
Test script:
#!/usr/bin/env python
import os
import signal
os.kill(os.getpid(), signal.SIGHUP)

JRuby:

[albert@dogbert ~]$ jruby -e 'system("./signal.py"); puts $?'
129

MRI:

[albert@dogbert ~]$ ruby -e 'system("./signal.py"); puts $?'
1

SIGHUP is signal number 1.

I could be wrong, but it looks like JRuby is also missing a few Process::Status pieces like signaled? and stopsig.


Charles Oliver Nutter - 22/May/07 08:41 AM
Albert: Could you file a separate bug for the missing process methods? Some we can't support, but it would be good to at least have a bug out there for them.

Nick Sieger - 31/May/07 04:21 PM
Unfortunately I don't think we're going to be able to emulate the signaled? behavior. For now, the to_i and to_s methods will return exitstatus << 8, which matches MRI, except for when the process is signaled.

Antti Karanta - 01/Jun/07 01:25 AM
I just took the latest from svn and there's something broken:

C:\programs\jruby>ruby -e "system('ruby -e \"exit(2)\"');print $?>>8"
2
C:\programs\jruby>jruby -e "system('ruby -e \"exit(2)\"');print $?>>8"
\"');print $?>>8") was unexpected at this time.

Since it works w/ mri (the first line) I don't think it's a win command prompt issue.


Charles Oliver Nutter - 01/Jun/07 02:17 AM
Looks like it's a problem with how Java in Windows handles parentheses in CLI parameters?