Skip to content

Commit

Permalink
Showing 5 changed files with 71 additions and 50 deletions.
2 changes: 0 additions & 2 deletions spec/truffle/tags/core/kernel/spawn_tags.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
fails:Kernel#spawn returns immediately
fails:Kernel#spawn sets environment variables in the child environment
fails:Kernel#spawn unsets environment variables whose value is nil
fails:Kernel#spawn calls #to_hash to convert the environment
@@ -24,7 +23,6 @@ fails:Kernel#spawn with multiple arguments raises an ArgumentError if an argumen
fails:Kernel#spawn with a command array raises an ArgumentError if the Strings in the Array include a null byte
fails:Kernel#spawn when passed :chdir changes to the directory passed for :chdir
fails:Kernel#spawn when passed :chdir calls #to_path to convert the :chdir value
fails:Kernel.spawn returns immediately
fails:Kernel.spawn sets environment variables in the child environment
fails:Kernel.spawn unsets environment variables whose value is nil
fails:Kernel.spawn calls #to_hash to convert the environment
16 changes: 0 additions & 16 deletions spec/truffle/tags/core/process/kill_tags.txt

This file was deleted.

30 changes: 0 additions & 30 deletions truffle/src/main/java/org/jruby/truffle/core/ProcessNodes.java
Original file line number Diff line number Diff line change
@@ -26,10 +26,8 @@
import org.jruby.truffle.language.RubyGuards;
import org.jruby.truffle.language.RubyNode;
import org.jruby.truffle.language.control.RaiseException;
import org.jruby.truffle.platform.UnsafeGroup;
import org.jruby.truffle.platform.posix.ClockGetTime;
import org.jruby.truffle.platform.posix.TimeSpec;
import org.jruby.truffle.platform.signal.Signal;

@CoreClass("Process")
public abstract class ProcessNodes {
@@ -128,34 +126,6 @@ protected static boolean isMonotonicRaw(int clock_id) {

}

@CoreMethod(names = "kill", onSingleton = true, required = 2, unsafe = {UnsafeGroup.PROCESSES, UnsafeGroup.SIGNALS})
public abstract static class KillNode extends CoreMethodArrayArgumentsNode {

@TruffleBoundary
@Specialization(guards = "isRubySymbol(signalName)")
public int kill(DynamicObject signalName, int pid) {
int self = posix().getpid();

if (self == pid) {
return raise(Layouts.SYMBOL.getString(signalName));
} else {
throw new UnsupportedOperationException();
}
}

@TruffleBoundary
private int raise(String signalName) {
Signal signal = getContext().getNativePlatform().getSignalManager().createSignal(signalName);
try {
getContext().getNativePlatform().getSignalManager().raise(signal);
} catch (IllegalArgumentException e) {
throw new RaiseException(coreExceptions().argumentError(e.getMessage(), this));
}
return 1;
}

}

@CoreMethod(names = "pid", onSingleton = true)
public abstract static class PidNode extends CoreMethodArrayArgumentsNode {

Original file line number Diff line number Diff line change
@@ -26,6 +26,8 @@
import org.jruby.truffle.builtins.CoreClass;
import org.jruby.truffle.builtins.CoreMethod;
import org.jruby.truffle.builtins.CoreMethodArrayArgumentsNode;
import org.jruby.truffle.builtins.Primitive;
import org.jruby.truffle.builtins.PrimitiveArrayArgumentsNode;
import org.jruby.truffle.core.rope.CodeRange;
import org.jruby.truffle.core.rope.RopeNodes;
import org.jruby.truffle.core.rope.RopeNodesFactory;
@@ -38,9 +40,8 @@
import org.jruby.truffle.language.objects.AllocateObjectNode;
import org.jruby.truffle.language.objects.AllocateObjectNodeGen;
import org.jruby.truffle.platform.UnsafeGroup;

import org.jruby.truffle.platform.signal.Signal;
import java.nio.charset.StandardCharsets;

import static org.jruby.truffle.core.string.StringOperations.decodeUTF8;

@CoreClass("Truffle::POSIX")
@@ -907,4 +908,32 @@ public int close(int file) {

}

@CoreMethod(names = "kill", isModuleFunction = true, unsafe = { UnsafeGroup.PROCESSES, UnsafeGroup.SIGNALS }, required = 3)
public abstract static class KillNode extends CoreMethodArrayArgumentsNode {

@TruffleBoundary
@Specialization(guards = "isRubyString(signalName)")
public int kill(int pid, int signalNumber, DynamicObject signalName) {
int self = posix().getpid();

if (self == pid) {
Signal signal = getContext().getNativePlatform().getSignalManager().createSignal(StringOperations.getString(signalName));
return raise(signal);
} else {
return posix().kill(pid, signalNumber);
}
}

@TruffleBoundary
private int raise(Signal signal) {
try {
getContext().getNativePlatform().getSignalManager().raise(signal);
} catch (IllegalArgumentException e) {
throw new RaiseException(coreExceptions().argumentError(e.getMessage(), this));
}
return 1;
}

}

}
40 changes: 40 additions & 0 deletions truffle/src/main/ruby/core/process.rb
Original file line number Diff line number Diff line change
@@ -172,6 +172,46 @@ def self.times
Struct::Tms.new(*cpu_times)
end

def self.kill(signal, *pids)
raise ArgumentError, "PID argument required" if pids.length == 0

use_process_group = false
signal = signal.to_s if signal.kind_of?(Symbol)

if signal.kind_of?(String)
if signal[0] == ?-
signal = signal[1..-1]
use_process_group = true
end

if signal[0..2] == "SIG"
signal = signal[3..-1]
end

signal = Signal::Names[signal]
end

raise ArgumentError unless signal.kind_of? Fixnum

if signal < 0
signal = -signal
use_process_group = true
end

signal_name = Signal::Numbers[signal]

pids.each do |pid|
pid = Rubinius::Type.coerce_to pid, Integer, :to_int

pid = -pid if use_process_group
result = Truffle::POSIX.kill(pid, signal, signal_name)

Errno.handle if result == -1
end

pids.length
end

def self.abort(msg=nil)
if msg
msg = StringValue(msg)

0 comments on commit 4a06018

Please sign in to comment.