summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-03-11 08:31:53 +0000
committerknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-03-11 08:31:53 +0000
commit58226f400e2f41777b95940eb2202dd9db11d3f3 (patch)
tree364e1850f37744c35ca145d28e34c1ca9d2cf6cc
parentf2ba46eefaacbd786e0cd4bff8ed904008c15291 (diff)
* eval.c (error_handle): no message when exiting by signal.
* eval.c (ruby_cleanup): re-send signal. [ruby-dev:30516] * eval.c (rb_thread_interrupt): instantiate SignalException. * eval.c (rb_thread_signal_raise): now takes signal number instead of signal name. * intern.h (rb_thread_signal_raise, ruby_default_signal): prototypes. * signal.c (esignal_init): takes a signal number and an optional signal name. * signal.c (interrupt_init): pass SIGINT always. * signal.c (ruby_default_signal): invoke system default signal handler. * signal.c (rb_signal_exec, trap): handle SIGTERM. [ruby-dev:30505] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8_6@12027 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog23
-rw-r--r--eval.c28
-rw-r--r--intern.h3
-rw-r--r--signal.c102
-rw-r--r--version.h6
5 files changed, 147 insertions, 15 deletions
diff --git a/ChangeLog b/ChangeLog
index be6d140..2addec2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,26 @@
+Sun Mar 11 17:30:53 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * eval.c (error_handle): no message when exiting by signal.
+
+ * eval.c (ruby_cleanup): re-send signal. [ruby-dev:30516]
+
+ * eval.c (rb_thread_interrupt): instantiate SignalException.
+
+ * eval.c (rb_thread_signal_raise): now takes signal number instead
+ of signal name.
+
+ * intern.h (rb_thread_signal_raise, ruby_default_signal): prototypes.
+
+ * signal.c (esignal_init): takes a signal number and an optional
+ signal name.
+
+ * signal.c (interrupt_init): pass SIGINT always.
+
+ * signal.c (ruby_default_signal): invoke system default signal
+ handler.
+
+ * signal.c (rb_signal_exec, trap): handle SIGTERM. [ruby-dev:30505]
+
Tue Mar 6 19:03:42 2007 Akinori MUSHA <knu@iDaemons.org>
* ext/digest/lib/md5.rb (MD5::new, MD5::md5): Do not modify
diff --git a/eval.c b/eval.c
index a5b4e84..014f3f7 100644
--- a/eval.c
+++ b/eval.c
@@ -1492,6 +1492,9 @@ error_handle(ex)
if (rb_obj_is_kind_of(ruby_errinfo, rb_eSystemExit)) {
status = sysexit_status(ruby_errinfo);
}
+ else if (rb_obj_is_instance_of(ruby_errinfo, rb_eSignal)) {
+ /* no message when exiting by signal */
+ }
else {
error_print();
}
@@ -1579,9 +1582,15 @@ ruby_cleanup(ex)
ruby_finalize_1();
POP_TAG();
- if (err && rb_obj_is_kind_of(err, rb_eSystemExit)) {
- VALUE st = rb_iv_get(err, "status");
- return NUM2INT(st);
+ if (err) {
+ if (rb_obj_is_kind_of(err, rb_eSystemExit)) {
+ VALUE st = rb_iv_get(err, "status");
+ return NUM2INT(st);
+ }
+ else if (rb_obj_is_kind_of(err, rb_eSignal)) {
+ VALUE sig = rb_iv_get(err, "signo");
+ ruby_default_signal(NUM2INT(sig));
+ }
}
return ex;
}
@@ -10155,7 +10164,6 @@ static VALUE th_raise_exception;
static NODE *th_raise_node;
static VALUE th_cmd;
static int th_sig, th_safe;
-static char *th_signm;
#define RESTORE_NORMAL 1
#define RESTORE_FATAL 2
@@ -10261,7 +10269,7 @@ rb_thread_switch(n)
rb_raise_jump(th_raise_exception);
break;
case RESTORE_SIGNAL:
- rb_raise(rb_eSignal, "SIG%s", th_signm);
+ rb_thread_signal_raise(th_sig);
break;
case RESTORE_EXIT:
ruby_errinfo = th_raise_exception;
@@ -12262,13 +12270,15 @@ rb_thread_interrupt()
void
rb_thread_signal_raise(sig)
- char *sig;
+ int sig;
{
- if (sig == 0) return; /* should not happen */
rb_thread_critical = 0;
if (curr_thread == main_thread) {
+ VALUE argv[1];
+
rb_thread_ready(curr_thread);
- rb_raise(rb_eSignal, "SIG%s", sig);
+ argv[0] = INT2FIX(sig);
+ rb_exc_raise(rb_class_new_instance(1, argv, rb_eSignal));
}
rb_thread_ready(main_thread);
if (!rb_thread_dead(curr_thread)) {
@@ -12276,7 +12286,7 @@ rb_thread_signal_raise(sig)
return;
}
}
- th_signm = sig;
+ th_sig = sig;
curr_thread = main_thread;
rb_thread_restore_context(curr_thread, RESTORE_SIGNAL);
}
diff --git a/intern.h b/intern.h
index 620a055..65c9163 100644
--- a/intern.h
+++ b/intern.h
@@ -211,7 +211,7 @@ VALUE rb_thread_kill _((VALUE));
VALUE rb_thread_create _((VALUE (*)(ANYARGS), void*));
void rb_thread_interrupt _((void));
void rb_thread_trap_eval _((VALUE, int, int));
-void rb_thread_signal_raise _((char*));
+void rb_thread_signal_raise _((int));
void rb_thread_signal_exit _((void));
int rb_thread_select _((int, fd_set *, fd_set *, fd_set *, struct timeval *));
void rb_thread_wait_for _((struct timeval));
@@ -394,6 +394,7 @@ void posix_signal _((int, RETSIGTYPE (*)(int)));
void rb_trap_exit _((void));
void rb_trap_exec _((void));
const char *ruby_signal_name _((int));
+void ruby_default_signal _((int));
/* sprintf.c */
VALUE rb_f_sprintf _((int, VALUE*));
/* string.c */
diff --git a/signal.c b/signal.c
index 6c12ccb..0f1171b 100644
--- a/signal.c
+++ b/signal.c
@@ -170,7 +170,7 @@ static struct signals {
static int
signm2signo(nm)
- char *nm;
+ const char *nm;
{
struct signals *sigs;
@@ -200,6 +200,93 @@ ruby_signal_name(no)
}
/*
+ * call-seq:
+ * SignalException.new(sig) => signal_exception
+ *
+ * Construct a new SignalException object. +sig+ should be a known
+ * signal name, or a signal number.
+ */
+
+static VALUE
+esignal_init(argc, argv, self)
+ int argc;
+ VALUE *argv;
+ VALUE self;
+{
+ int argnum = 1;
+ VALUE sig = Qnil;
+ int signo;
+ const char *signm;
+ char tmpnm[(sizeof(int)*CHAR_BIT)/3+4];
+
+ if (argc > 0) {
+ sig = argv[0];
+ if (FIXNUM_P(sig)) argnum = 2;
+ }
+ if (argc < 1 || argnum < argc) {
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for %d)",
+ argc, argnum);
+ }
+ if (argnum == 2) {
+ signo = FIX2INT(sig);
+ if (signo < 0 || signo > NSIG) {
+ rb_raise(rb_eArgError, "invalid signal number (%d)", signo);
+ }
+ if (argc > 1) {
+ sig = argv[1];
+ }
+ else {
+ signm = signo2signm(signo);
+ if (signm) {
+ snprintf(tmpnm, sizeof(tmpnm), "SIG%s", signm);
+ }
+ else {
+ snprintf(tmpnm, sizeof(tmpnm), "SIG%u", signo);
+ }
+ sig = rb_str_new2(signm = tmpnm);
+ }
+ }
+ else {
+ signm = SYMBOL_P(sig) ? rb_id2name(SYM2ID(sig)) : StringValuePtr(sig);
+ if (strncmp(signm, "SIG", 3) == 0) signm += 3;
+ signo = signm2signo(signm);
+ if (!signo) {
+ rb_raise(rb_eArgError, "unsupported name `SIG%s'", signm);
+ }
+ if (SYMBOL_P(sig)) {
+ sig = rb_str_new2(signm);
+ }
+ }
+ rb_call_super(1, &sig);
+ rb_iv_set(self, "signo", INT2NUM(signo));
+
+ return self;
+}
+
+static VALUE
+interrupt_init(self, mesg)
+ VALUE self, mesg;
+{
+ VALUE argv[2];
+
+ argv[0] = INT2FIX(SIGINT);
+ argv[1] = mesg;
+ return rb_call_super(2, argv);
+}
+
+void
+ruby_default_signal(sig)
+ int sig;
+{
+#ifndef MACOS_UNUSE_SIGNAL
+ extern rb_pid_t getpid _((void));
+
+ signal(sig, SIG_DFL);
+ kill(getpid(), sig);
+#endif
+}
+
+/*
* call-seq:
* Process.kill(signal, pid, ...) => fixnum
*
@@ -413,6 +500,9 @@ signal_exec(sig)
#ifdef SIGQUIT
case SIGQUIT:
#endif
+#ifdef SIGTERM
+ case SIGTERM:
+#endif
#ifdef SIGALRM
case SIGALRM:
#endif
@@ -422,7 +512,7 @@ signal_exec(sig)
#ifdef SIGUSR2
case SIGUSR2:
#endif
- rb_thread_signal_raise(signo2signm(sig));
+ rb_thread_signal_raise(sig);
break;
}
}
@@ -680,6 +770,9 @@ trap(arg)
#ifdef SIGQUIT
case SIGQUIT:
#endif
+#ifdef SIGTERM
+ case SIGTERM:
+#endif
#ifdef SIGALRM
case SIGALRM:
#endif
@@ -975,6 +1068,11 @@ Init_signal()
rb_define_module_function(mSignal, "trap", sig_trap, -1);
rb_define_module_function(mSignal, "list", sig_list, 0);
+ rb_define_method(rb_eSignal, "initialize", esignal_init, -1);
+ rb_attr(rb_eSignal, rb_intern("signo"), 1, 0, 0);
+ rb_alias(rb_eSignal, rb_intern("signm"), rb_intern("message"));
+ rb_define_method(rb_eInterrupt, "initialize", interrupt_init, 1);
+
install_sighandler(SIGINT, sighandler);
#ifdef SIGHUP
install_sighandler(SIGHUP, sighandler);
diff --git a/version.h b/version.h
index 721f260..f17e134 100644
--- a/version.h
+++ b/version.h
@@ -1,7 +1,7 @@
#define RUBY_VERSION "1.8.6"
-#define RUBY_RELEASE_DATE "2007-03-06"
+#define RUBY_RELEASE_DATE "2007-03-11"
#define RUBY_VERSION_CODE 186
-#define RUBY_RELEASE_CODE 20070306
+#define RUBY_RELEASE_CODE 20070311
#define RUBY_PATCHLEVEL 0
#define RUBY_VERSION_MAJOR 1
@@ -9,7 +9,7 @@
#define RUBY_VERSION_TEENY 6
#define RUBY_RELEASE_YEAR 2007
#define RUBY_RELEASE_MONTH 3
-#define RUBY_RELEASE_DAY 6
+#define RUBY_RELEASE_DAY 11
#ifdef RUBY_EXTERN
RUBY_EXTERN const char ruby_version[];