Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 79 additions & 22 deletions core/src/main/java/org/jruby/RubyProcess.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import org.jruby.anno.JRubyMethod;
import org.jruby.anno.JRubyModule;
import jnr.posix.POSIX;
import org.jruby.common.IRubyWarnings;
import org.jruby.javasupport.Java;
import org.jruby.javasupport.JavaUtil;
import org.jruby.platform.Platform;
Expand Down Expand Up @@ -139,6 +140,13 @@ public static RubyModule createProcessModule(Ruby runtime) {
process.defineConstant("Tms", tmsStruct);
runtime.setTmsStruct(tmsStruct);

if (!runtime.getPosix().isNative()) {
// cannot support pid waits
process.searchMethod("wait").getRealMethod().setNotImplemented(true);
process.searchMethod("waitpid").getRealMethod().setNotImplemented(true);
process.searchMethod("waitall").getRealMethod().setNotImplemented(true);
}

return process;
}

Expand Down Expand Up @@ -895,16 +903,20 @@ public static IRubyObject groups_set(IRubyObject recv, IRubyObject arg) {
throw recv.getRuntime().newNotImplementedError("Process#groups not yet implemented");
}

@Deprecated
public static IRubyObject waitpid(IRubyObject recv, IRubyObject[] args) {
return waitpid(recv.getRuntime(), args);
}
@JRubyMethod(name = "waitpid", rest = true, module = true, visibility = PRIVATE)
public static IRubyObject waitpid(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
return waitpid(context.runtime, args);
return waitpid(context, args);
}

public static IRubyObject waitpid(Ruby runtime, IRubyObject[] args) {
public static IRubyObject waitpid(ThreadContext context, IRubyObject[] args) {
Ruby runtime = context.runtime;
POSIX posix = runtime.getPosix();

if (!posix.isNative()) {
warnWaitUnsupported(runtime);
return context.nil;
}

long pid = -1;
int flags = 0;
if (args.length > 0) {
Expand All @@ -914,7 +926,7 @@ public static IRubyObject waitpid(Ruby runtime, IRubyObject[] args) {
flags = (int)args[1].convertToInteger().getLongValue();
}

pid = waitpid(runtime, pid, flags);
pid = waitpid(context, pid, flags);

checkErrno(runtime, pid, ECHILD);

Expand All @@ -926,10 +938,11 @@ public static IRubyObject waitpid(Ruby runtime, IRubyObject[] args) {
}

// MRI: rb_waitpid
public static long waitpid(Ruby runtime, long pid, int flags) {
public static long waitpid(ThreadContext context, long pid, int flags) {
Ruby runtime = context.runtime;

int[] status = new int[1];
POSIX posix = runtime.getPosix();
ThreadContext context = runtime.getCurrentContext();

posix.errno(0);

Expand Down Expand Up @@ -1018,23 +1031,25 @@ public int handle(Ruby runtime, int result) {
}
};

@Deprecated
public static IRubyObject wait(IRubyObject recv, IRubyObject[] args) {
return wait(recv.getRuntime(), args);
}
@JRubyMethod(name = "wait", rest = true, module = true, visibility = PRIVATE)
public static IRubyObject wait(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
return wait(context.runtime, args);
}

public static IRubyObject wait(Ruby runtime, IRubyObject[] args) {
public static IRubyObject wait(ThreadContext context, IRubyObject[] args) {
Ruby runtime = context.runtime;
POSIX posix = runtime.getPosix();

if (!posix.isNative()) {
warnWaitUnsupported(runtime);
return context.nil;
}

if (args.length > 0) {
return waitpid(runtime, args);
}

int[] status = new int[1];
POSIX posix = runtime.getPosix();
ThreadContext context = runtime.getCurrentContext();

posix.errno(0);

Expand All @@ -1046,17 +1061,21 @@ public static IRubyObject wait(Ruby runtime, IRubyObject[] args) {
return runtime.newFixnum(pid);
}


@Deprecated
public static IRubyObject waitall(IRubyObject recv) {
return waitall(recv.getRuntime());
}
@JRubyMethod(name = "waitall", module = true, visibility = PRIVATE)
public static IRubyObject waitall(ThreadContext context, IRubyObject recv) {
return waitall(context.runtime);
}
public static IRubyObject waitall(Ruby runtime) {

public static IRubyObject waitall(ThreadContext context) {
Ruby runtime = context.runtime;

POSIX posix = runtime.getPosix();

if (!posix.isNative()) {
warnWaitUnsupported(runtime);
return context.nil;
}

RubyArray results = runtime.newArray();

int[] status = new int[1];
Expand All @@ -1073,6 +1092,10 @@ public static IRubyObject waitall(Ruby runtime) {
return results;
}

private static void warnWaitUnsupported(Ruby runtime) {
runtime.getWarnings().warnOnce(IRubyWarnings.ID.PROCESS_WAIT_UNAVAILABLE, "process wait functions unavailable without native support");
}

@Deprecated
public static IRubyObject setsid(IRubyObject recv) {
return setsid(recv.getRuntime());
Expand Down Expand Up @@ -1722,4 +1745,38 @@ private static void raiseErrnoIfSet(Ruby runtime, NonNativeErrno nonNative) {
public static IRubyObject waitpid2(IRubyObject recv, IRubyObject[] args) {
return waitpid2(recv.getRuntime(), args);
}

@Deprecated
public static IRubyObject waitall(IRubyObject recv) {
return waitall(recv.getRuntime().getCurrentContext());
}

@Deprecated
public static IRubyObject waitall(Ruby runtime) {
return waitall(runtime.getCurrentContext());
}

@Deprecated
public static IRubyObject wait(IRubyObject recv, IRubyObject[] args) {
return wait(recv.getRuntime(), args);
}

@Deprecated
public static IRubyObject wait(Ruby runtime, IRubyObject[] args) {
return wait(runtime.getCurrentContext(), args);
}
@Deprecated
public static IRubyObject waitpid(IRubyObject recv, IRubyObject[] args) {
return waitpid(recv.getRuntime(), args);
}

@Deprecated
public static IRubyObject waitpid(Ruby runtime, IRubyObject[] args) {
return waitpid(runtime.getCurrentContext(), args);
}

@Deprecated
public static long waitpid(Ruby runtime, long pid, int flags) {
return waitpid(runtime.getCurrentContext(), pid, flags);
}
}
3 changes: 2 additions & 1 deletion core/src/main/java/org/jruby/common/IRubyWarnings.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ enum ID {
GC_STRESS_UNIMPLEMENTED,
GC_ENABLE_UNIMPLEMENTED,
GC_DISABLE_UNIMPLEMENTED,
RATIONAL_OUT_OF_RANGE,;
RATIONAL_OUT_OF_RANGE,
PROCESS_WAIT_UNAVAILABLE;

public String getID() {
return name();
Expand Down