- == not implemented
- other methods not impled, but perhaps not necessary
- We have obviously not used Process much up to now, but I added commented-out method defs for everything C Ruby supports
- need unit tests for Process::Status (likely to be incorporated into rubicon)
- ant test OOMs for me, could be this patch or environmental
On 6/26/06,
Charles O Nutter <[EMAIL PROTECTED]> wrote:
I think I found my issue...running under linux, the shell substitutes its own $? when the -e bit is double-quoted.
[EMAIL PROTECTED]:~/testrails/test4$ ruby -e 'fork { exit 99 }; Process.wait; p $?.class'
Process::Status
[EMAIL PROTECTED]:~/testrails/test4$ ruby -e "fork { exit 99 }; Process.wait; p $?.class"
Fixnum
So the second one ultimately executes "for { exit 99 }; Process.wait; p 0.class", which obviously prints Fixnum.
So at least now we understand my issue...we just need to make our process execution return a Process::Status instead of a Fixnum.On 6/26/06, Thomas E Enebo <[EMAIL PROTECTED]> wrote:On Mon, 26 Jun 2006, Charles O Nutter defenestrated me:
>
> The plugin script fails (as perhaps do others) because we do not
> return a Process::Status object when executing an external process; we
> return a Fixnum.
> Process::Status defines a success? method which Rails is using. That
> blows up with a NoMethodError, which Rails of course swallows.
> The fix is to make $? a Process::Status object (we do not have the
> class or any of its methods defined as yet).
> Oddly enough, there seems to be a 1.8.4 bug in that ruby -e scripts
> set $? to a Fixnum. I'm going to ask them about it.
[enebo ~/]$ ruby -e '`ls`; p $?.class'
-e:1: warning: Insecure world writable dir /home/enebo, mode 040777
Process::Status
Could that only be on linux? It appears to work on winderz
-Tom
--
+ http://www.tc.umn.edu/~enebo +---- mailto:[EMAIL PROTECTED] ----+
| Thomas E Enebo, Protagonist | "Luck favors the prepared |
| | mind." -Louis Pasteur |
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Jruby-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jruby-devel
--
Charles Oliver Nutter @ headius.blogspot.com
JRuby Developer @ www.jruby.org
Application Architect @ www.ventera.com
--
Charles Oliver Nutter @ headius.blogspot.com
JRuby Developer @ www.jruby.org
Application Architect @ www.ventera.com
Index: org/jruby/RubyKernel.java
===================================================================
RCS file: /cvsroot/jruby/jruby/src/org/jruby/RubyKernel.java,v
retrieving revision 1.53
diff -u -r1.53 RubyKernel.java
--- org/jruby/RubyKernel.java 24 May 2006 01:34:03 -0000 1.53
+++ org/jruby/RubyKernel.java 26 Jun 2006 23:19:52 -0000
@@ -703,7 +703,7 @@
int resultCode = runInShell(runtime, new IRubyObject[] {aString}, output);
- recv.getRuntime().getGlobalVariables().set("$?", runtime.newFixnum(resultCode));
+ recv.getRuntime().getGlobalVariables().set("$?", RubyProcess.RubyStatus.newProcessStatus(runtime, resultCode));
return recv.getRuntime().newString(output.toString());
}
@@ -961,7 +961,7 @@
IRuby runtime = recv.getRuntime();
ByteArrayOutputStream output = new ByteArrayOutputStream();
int resultCode = runInShell(runtime, args, output);
- recv.getRuntime().getGlobalVariables().set("$?", runtime.newFixnum(resultCode));
+ recv.getRuntime().getGlobalVariables().set("$?", RubyProcess.RubyStatus.newProcessStatus(runtime, resultCode));
return runtime.newBoolean(resultCode == 0);
}
}
Index: org/jruby/RubyProcess.java
===================================================================
RCS file: /cvsroot/jruby/jruby/src/org/jruby/RubyProcess.java,v
retrieving revision 1.6
diff -u -r1.6 RubyProcess.java
--- org/jruby/RubyProcess.java 26 Oct 2005 05:34:13 -0000 1.6
+++ org/jruby/RubyProcess.java 26 Jun 2006 23:19:53 -0000
@@ -28,6 +28,9 @@
***** END LICENSE BLOCK *****/
package org.jruby;
+import org.jruby.runtime.CallbackFactory;
+import org.jruby.runtime.builtin.IRubyObject;
+
/**
*
@@ -36,8 +39,111 @@
public class RubyProcess {
public static RubyModule createProcessModule(IRuby runtime) {
- RubyModule module = runtime.defineModule("Process");
+ RubyModule process = runtime.defineModule("Process");
+
+ RubyModule process_status = process.defineClassUnder("Status", runtime.getObject());
+
+ CallbackFactory processCallbackFactory = runtime.callbackFactory(RubyProcess.class);
+ CallbackFactory process_statusCallbackFactory = runtime.callbackFactory(RubyProcess.RubyStatus.class);
+
+// process.defineModuleFunction("fork", processCallbackFactory.getSingletonMethod("fork"));
+// process.defineModuleFunction("exit!", processCallbackFactory.getOptSingletonMethod("exit_bang"));
+// process.defineModuleFunction("exit", processCallbackFactory.getOptSingletonMethod("exit"));
+// process.defineModuleFunction("abort", processCallbackFactory.getOptSingletonMethod("abort"));
+// process.defineModuleFunction("kill", processCallbackFactory.getOptSingletonMethod("kill"));
+// process.defineModuleFunction("wait", processCallbackFactory.getOptSingletonMethod("wait"));
+// process.defineModuleFunction("wait2", processCallbackFactory.getOptSingletonMethod("wait2"));
+// process.defineModuleFunction("waitpid", processCallbackFactory.getOptSingletonMethod("waitpid"));
+// process.defineModuleFunction("waitpid2", processCallbackFactory.getOptSingletonMethod("waitpid2"));
+// process.defineModuleFunction("waitall", processCallbackFactory.getSingletonMethod("waitall"));
+// process.defineModuleFunction("detach", processCallbackFactory.getSingletonMethod("detach", IRubyObject.class));
+// process.defineModuleFunction("pid", processCallbackFactory.getSingletonMethod("pid"));
+// process.defineModuleFunction("ppid", processCallbackFactory.getSingletonMethod("ppid"));
+//
+// process.defineModuleFunction("getpgrp", processCallbackFactory.getSingletonMethod("getprgrp"));
+// process.defineModuleFunction("setpgrp", processCallbackFactory.getSingletonMethod("setpgrp"));
+// process.defineModuleFunction("getpgid", processCallbackFactory.getSingletonMethod("getpgid", IRubyObject.class));
+// process.defineModuleFunction("setpgid", processCallbackFactory.getSingletonMethod("setpgid", IRubyObject.class, IRubyObject.class));
+//
+// process.defineModuleFunction("setsid", processCallbackFactory.getSingletonMethod("setsid"));
+//
+// process.defineModuleFunction("getpriority", processCallbackFactory.getSingletonMethod("getpriority", IRubyObject.class, IRubyObject.class));
+// process.defineModuleFunction("setpriority", processCallbackFactory.getSingletonMethod("setpriority", IRubyObject.class, IRubyObject.class, IRubyObject.class));
- return module;
+// #ifdef HAVE_GETPRIORITY
+// rb_define_const(rb_mProcess, "PRIO_PROCESS", INT2FIX(PRIO_PROCESS));
+// rb_define_const(rb_mProcess, "PRIO_PGRP", INT2FIX(PRIO_PGRP));
+// rb_define_const(rb_mProcess, "PRIO_USER", INT2FIX(PRIO_USER));
+// #endif
+
+// process.defineModuleFunction("uid", processCallbackFactory.getSingletonMethod("uid"));
+// process.defineModuleFunction("uid=", processCallbackFactory.getSingletonMethod("uid_set", IRubyObject.class));
+// process.defineModuleFunction("gid", processCallbackFactory.getSingletonMethod("gid"));
+// process.defineModuleFunction("gid=", processCallbackFactory.getSingletonMethod("gid_set", IRubyObject.class));
+// process.defineModuleFunction("euid", processCallbackFactory.getSingletonMethod("euid"));
+// process.defineModuleFunction("euid=", processCallbackFactory.getSingletonMethod("euid_set", IRubyObject.class));
+// process.defineModuleFunction("egid", processCallbackFactory.getSingletonMethod("egid"));
+// process.defineModuleFunction("egid=", processCallbackFactory.getSingletonMethod("egid_set", IRubyObject.class));
+// process.defineModuleFunction("initgroups", processCallbackFactory.getSingletonMethod("initgroups", IRubyObject.class, IRubyObject.class));
+// process.defineModuleFunction("groups", processCallbackFactory.getSingletonMethod("groups"));
+// process.defineModuleFunction("groups=", processCallbackFactory.getSingletonMethod("groups_set", IRubyObject.class));
+// process.defineModuleFunction("maxgroups", processCallbackFactory.getSingletonMethod("maxgroups"));
+// process.defineModuleFunction("maxgroups=", processCallbackFactory.getSingletonMethod("maxgroups_set", IRubyObject.class));
+// process.defineModuleFunction("times", processCallbackFactory.getSingletonMethod("groups"));
+
+ // Process::Status methods
+// process_status.defineMethod("==", process_statusCallbackFactory.getMethod("op_eq"));
+// process_status.defineMethod("&", process_statusCallbackFactory.getMethod("op_and"));
+// process_status.defineMethod(">>", process_statusCallbackFactory.getMethod("rightshift_op"));
+ process_status.defineMethod("to_i", process_statusCallbackFactory.getMethod("to_i"));
+// process_status.defineMethod("to_int", process_statusCallbackFactory.getMethod("to_int"));
+ process_status.defineMethod("to_s", process_statusCallbackFactory.getMethod("to_s"));
+ process_status.defineMethod("inspect", process_statusCallbackFactory.getMethod("inspect"));
+// process_status.defineMethod("pid", process_statusCallbackFactory.getMethod("pid"));
+// process_status.defineMethod("stopped?", process_statusCallbackFactory.getMethod("stopped_p"));
+// process_status.defineMethod("stopsig", process_statusCallbackFactory.getMethod("stopsig"));
+// process_status.defineMethod("signaled?", process_statusCallbackFactory.getMethod("signaled_p"));
+// process_status.defineMethod("termsig", process_statusCallbackFactory.getMethod("termsig"));
+// process_status.defineMethod("exited?", process_statusCallbackFactory.getMethod("exited_p"));
+ process_status.defineMethod("exitstatus", process_statusCallbackFactory.getMethod("exitstatus"));
+ process_status.defineMethod("success?", process_statusCallbackFactory.getMethod("success_p"));
+// process_status.defineMethod("coredump?", process_statusCallbackFactory.getMethod("coredump_p"));
+
+ return process;
+ }
+
+ public static class RubyStatus extends RubyObject {
+ private long status = 0L;
+
+ private static final long EXIT_SUCCESS = 0L;
+ public RubyStatus(IRuby runtime, RubyClass metaClass, long status) {
+ super(runtime, metaClass);
+
+ this.status = status;
+ }
+
+ public static RubyStatus newProcessStatus(IRuby runtime, long status) {
+ return new RubyStatus(runtime, runtime.getModule("Process").getClass("Status"), status);
+ }
+
+ public IRubyObject exitstatus() {
+ return getRuntime().newFixnum(status);
+ }
+
+ public IRubyObject to_i() {
+ return exitstatus();
+ }
+
+ public IRubyObject to_s() {
+ return getRuntime().newString(String.valueOf(status));
+ }
+
+ public IRubyObject inspect() {
+ return to_s();
+ }
+
+ public IRubyObject success_p() {
+ return getRuntime().newBoolean(status == EXIT_SUCCESS);
+ }
}
}
Index: org/jruby/runtime/CallbackFactory.java
===================================================================
RCS file: /cvsroot/jruby/jruby/src/org/jruby/runtime/CallbackFactory.java,v
retrieving revision 1.12
diff -u -r1.12 CallbackFactory.java
--- org/jruby/runtime/CallbackFactory.java 13 Jul 2005 16:49:31 -0000 1.12
+++ org/jruby/runtime/CallbackFactory.java 26 Jun 2006 23:19:53 -0000
@@ -89,6 +89,13 @@
**/
public abstract Callback getSingletonMethod(String method, Class arg1, Class arg2);
+ /**
+ * gets a singleton (class) method with 3 arguments.
+ * @param method name of the method
+ * @return a CallBack object corresponding to the appropriate method
+ **/
+ public abstract Callback getSingletonMethod(String method, Class arg1, Class arg2, Class arg3);
+
public abstract Callback getBlockMethod(String method);
/**
Index: org/jruby/runtime/callback/ReflectionCallbackFactory.java
===================================================================
RCS file: /cvsroot/jruby/jruby/src/org/jruby/runtime/callback/ReflectionCallbackFactory.java,v
retrieving revision 1.5
diff -u -r1.5 ReflectionCallbackFactory.java
--- org/jruby/runtime/callback/ReflectionCallbackFactory.java 13 Jul 2005 16:49:31 -0000 1.5
+++ org/jruby/runtime/callback/ReflectionCallbackFactory.java 26 Jun 2006 23:19:53 -0000
@@ -64,6 +64,10 @@
return new ReflectionCallback(type, method, new Class[] { arg1, arg2 }, false, true, Arity.fixed(2));
}
+ public Callback getSingletonMethod(String method, Class arg1, Class arg2, Class arg3) {
+ return new ReflectionCallback(type, method, new Class[] { arg1, arg2, arg3 }, false, true, Arity.fixed(3));
+ }
+
public Callback getBlockMethod(String method) {
return new ReflectionCallback(
type,
Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________ Jruby-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/jruby-devel
