Permalink
Browse files

kernel/core/signal is no more platform dependent

* Now publishing platform.conf with rbx.platform.signal.* (only using the ones
 defined in MRI's "signal.c")
* Signal::Names is now published with those values on @after_loaded@
* New method: Signal.list => Signal::Names
* Added EXIT=>0 and CLD=CHLD exceptions (see "signal.c" in MRI)
* Updated the corresponding specs for more details (on FIXME, please help !)
  • Loading branch information...
1 parent bdbd712 commit b3a6461af30f2c144b4ee65e8539c51291e0156b @zimbatm zimbatm committed Jan 16, 2008
Showing with 160 additions and 34 deletions.
  1. +57 −0 Rakefile
  2. +18 −25 kernel/core/signal.rb
  3. +1 −0 kernel/loader.rb
  4. +84 −9 spec/ruby/1.8/core/signal/list_spec.rb
View
@@ -909,6 +909,55 @@ file 'runtime/platform.conf' => %w[Rakefile rakelib/struct_generator.rb] do |tas
RLIM_SAVED_MAX
RLIM_SAVED_CUR
}
+
+ # The constants come from MRI's signal.c. This means that some of them might
+ # be missing.
+ signal_constants = %w{
+ SIGHUP
+ SIGINT
+ SIGQUIT
+ SIGILL
+ SIGTRAP
+ SIGIOT
+ SIGABRT
+ SIGEMT
+ SIGFPE
+ SIGKILL
+ SIGBUS
+ SIGSEGV
+ SIGSYS
+ SIGPIPE
+ SIGALRM
+ SIGTERM
+ SIGURG
+ SIGSTOP
+ SIGTSTP
+ SIGCONT
+ SIGCHLD
+ SIGCLD
+ SIGCHLD
+ SIGTTIN
+ SIGTTOU
+ SIGIO
+ SIGXCPU
+ SIGXFSZ
+ SIGVTALRM
+ SIGPROF
+ SIGWINCH
+ SIGUSR1
+ SIGUSR2
+ SIGLOST
+ SIGMSG
+ SIGPWR
+ SIGPOLL
+ SIGDANGER
+ SIGMIGRATE
+ SIGPRE
+ SIGGRANT
+ SIGRETRACT
+ SIGSOUND
+ SIGINFO
+ }
cg = ConstGenerator.new
cg.include "stdio.h"
@@ -919,12 +968,14 @@ file 'runtime/platform.conf' => %w[Rakefile rakelib/struct_generator.rb] do |tas
cg.include "sys/stat.h"
cg.include "sys/resource.h"
cg.include "netinet/tcp.h"
+ cg.include "signal.h"
file_constants.each { |c| cg.const c }
io_constants.each { |c| cg.const c }
socket_constants.each { |c| cg.const c }
process_constants.each { |c| cg.const c }
long_process_constants.each { |c| cg.const(c, "%llu") }
+ signal_constants.each { |c| cg.const c }
cg.calculate
@@ -959,6 +1010,12 @@ file 'runtime/platform.conf' => %w[Rakefile rakelib/struct_generator.rb] do |tas
next if const.converted_value.nil?
f.puts "rbx.platform.process.#{name} = #{const.converted_value}"
end
+
+ signal_constants.each do |name|
+ const = cg.constants[name]
+ next if const.converted_value.nil?
+ f.puts "rbx.platform.signal.#{name} = #{const.converted_value}"
+ end
end
end
View
@@ -1,30 +1,7 @@
# depends on: module.rb
module Signal
-
- Names = {
- "HUP" => 1,
- "INT" => 2,
- "QUIT" => 3,
- "ABRT" => 6,
- "POLL" => 7,
- "EMT" => 7,
- "FPE" => 8,
- "SYS" => 12,
- "PIPE" => 13,
- "ALRM" => 14,
- "TERM" => 15,
- "URG" => 16,
- "STOP" => 17,
- "TSTP" => 18,
- "CONT" => 19,
- "CHLD" => 20,
- "IO" => 23,
- "PROF" => 27,
- "INFO" => 29,
- "USR1" => 30,
- "USR2" => 31
- }
+ Names = {"EXIT" => 0}
@handlers = {}
@@ -70,5 +47,21 @@ def self.trap(sig, prc=nil, pass_ctx=false, &block)
def self.action(sig, prc=nil, &block)
trap(sig, prc, true, &block)
end
-
+
+ def self.list
+ Names.dup
+ end
+
+ def self.after_loaded
+ Rubinius::RUBY_CONFIG.keys.each do |key|
+ if key[0, 20] == 'rbx.platform.signal.'
+ Names[ key[23, 100] ] = Rubinius::RUBY_CONFIG[key]
+ end
+ end
+ # special case of signal.c
+ if Names["CHLD"]
+ Names["CLD"] = Names["CHLD"]
+ end
+ end
+
end
View
@@ -11,6 +11,7 @@
FileTest.after_loaded
Thread.after_loaded
Struct.after_loaded
+ Signal.after_loaded
Object.after_loaded
ENV = EnvironmentVariables.new
@@ -1,16 +1,91 @@
require File.dirname(__FILE__) + '/../../spec_helper'
describe "Signal.list" do
+ RUBY18_SIGNALS = %w{
+ EXIT
+ HUP
+ INT
+ QUIT
+ ILL
+ TRAP
+ IOT
+ ABRT
+ EMT
+ FPE
+ KILL
+ BUS
+ SEGV
+ SYS
+ PIPE
+ ALRM
+ TERM
+ URG
+ STOP
+ TSTP
+ CONT
+ CHLD
+ CLD
+ TTIN
+ TTOU
+ IO
+ XCPU
+ XFSZ
+ VTALRM
+ PROF
+ WINCH
+ USR1
+ USR2
+ LOST
+ MSG
+ PWR
+ POLL
+ DANGER
+ MIGRATE
+ PRE
+ GRANT
+ RETRACT
+ SOUND
+ INFO
+ }
+
+ LINUX_SIGNALS = {"PWR"=>30, "USR1"=>10, "BUS"=>7, "USR2"=>12, "TERM"=>15,
+ "SEGV"=>11, "KILL"=>9, "EXIT"=>0, "POLL"=>29, "STOP"=>19, "SYS"=>31,
+ "TRAP"=>5, "IOT"=>6, "HUP"=>1, "INT"=>2, "WINCH"=>28, "XCPU"=>24,
+ "TTIN"=>21, "CLD"=>17, "TSTP"=>20, "FPE"=>8, "IO"=>29, "TTOU"=>22,
+ "PROF"=>27, "CHLD"=>17, "CONT"=>18, "PIPE"=>13, "ABRT"=>6, "VTALRM"=>26,
+ "QUIT"=>3, "ILL"=>4, "XFSZ"=>25, "URG"=>23, "ALRM"=>14}
+
+ DARWIN_SIGNALS = {"USR1"=>30, "BUS"=>10, "USR2"=>31, "TERM"=>15, "SEGV"=>11,
+ "KILL"=>9, "EMT"=>7, "EXIT"=>0, "STOP"=>17, "SYS"=>12, "TRAP"=>5,
+ "INFO"=>29, "IOT"=>6, "HUP"=>1, "INT"=>2, "WINCH"=>28, "XCPU"=>24,
+ "TTIN"=>21, "CLD"=>20, "TSTP"=>18, "FPE"=>8, "IO"=>23, "TTOU"=>22,
+ "PROF"=>27, "CHLD"=>20, "CONT"=>19, "PIPE"=>13, "ABRT"=>6, "VTALRM"=>26,
+ "QUIT"=>3, "ILL"=>4, "XFSZ"=>25, "URG"=>16, "ALRM"=>14}
+
it "returns a hash of signal names mapped to the corresponding signal numbers" do
- list = Signal.list
- keys = list.keys.sort
- values = keys.map {|key| list[key]}
+ # FIXME: values may change trough the arches too
+ platform_is :linux do
+ Signal.list.should == LINUX_SIGNALS
+ end
+ platform_is :darwin do
+ Signal.list.should == DARWIN_SIGNALS
+ end
+ platform_is_not :linux, :darwin do
+ raise "FIXME, please add platform support"
+ end
+ end
+
+ it "doesn't contain other signals than in 1.8" do
+ (Signal.list.keys - RUBY18_SIGNALS).should == []
+ end
+
+ if Signal.list["CHLD"]
+ it "should redefine CLD with CHLD if defined" do
+ Signal.list["CLD"].should == Signal.list["CHLD"]
+ end
+ end
- keys.should == ["ABRT", "ALRM", "BUS", "CHLD", "CLD", "CONT", "EMT", "EXIT",
- "FPE", "HUP", "ILL", "INFO", "INT", "IO", "IOT", "KILL", "PIPE", "PROF",
- "QUIT", "SEGV", "STOP", "SYS", "TERM", "TRAP", "TSTP", "TTIN", "TTOU", "URG",
- "USR1", "USR2", "VTALRM", "WINCH", "XCPU", "XFSZ"]
- values.should == [6, 14, 10, 20, 20, 19, 7, 0, 8, 1, 4, 29, 2, 23, 6, 9, 13, 27,
- 3, 11, 17, 12, 15, 5, 18, 21, 22, 16, 30, 31, 26, 28, 24, 25]
+ it "should contain the EXIT key with a value of zero" do
+ Signal.list["EXIT"].should == 0
end
end

0 comments on commit b3a6461

Please sign in to comment.