* eval.c (ruby_cleanup): re-send signal. [ruby-dev:30516]
* eval_error.h (error_handle): no message when exiting by signal. * 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_f_kill): use NUM2PIDT instead of NUM2INT. * signal.c (rb_signal_exec, trap): handle SIGTERM. [ruby-dev:30505] * thread.c (rb_thread_signal_raise): now takes signal number instead of signal name. * thread.c (rb_thread_signal_exit): since rb_make_exception() calls #exception method, rb_class_new_instance() is not needed here. * yarvcore.h (struct rb_vm_struct), eval_jump.h (terminate_process): exit_code is no longer stored in VM. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12199 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
a73894337a
commit
3fc37d71c4
29
ChangeLog
29
ChangeLog
@ -1,3 +1,32 @@
|
|||||||
|
Fri Apr 20 02:37:48 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* eval.c (ruby_cleanup): re-send signal. [ruby-dev:30516]
|
||||||
|
|
||||||
|
* eval_error.h (error_handle): no message when exiting by signal.
|
||||||
|
|
||||||
|
* 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_f_kill): use NUM2PIDT instead of NUM2INT.
|
||||||
|
|
||||||
|
* signal.c (rb_signal_exec, trap): handle SIGTERM. [ruby-dev:30505]
|
||||||
|
|
||||||
|
* thread.c (rb_thread_signal_raise): now takes signal number instead
|
||||||
|
of signal name.
|
||||||
|
|
||||||
|
* thread.c (rb_thread_signal_exit): since rb_make_exception() calls
|
||||||
|
#exception method, rb_class_new_instance() is not needed here.
|
||||||
|
|
||||||
|
* yarvcore.h (struct rb_vm_struct), eval_jump.h (terminate_process):
|
||||||
|
exit_code is no longer stored in VM.
|
||||||
|
|
||||||
Thu Apr 19 18:37:49 2007 Koichi Sasada <ko1@atdot.net>
|
Thu Apr 19 18:37:49 2007 Koichi Sasada <ko1@atdot.net>
|
||||||
|
|
||||||
* eval.c, node.h, thread.c, yarvcore.[ch], eval_intern.h:
|
* eval.c, node.h, thread.c, yarvcore.[ch], eval_intern.h:
|
||||||
|
35
eval.c
35
eval.c
@ -153,40 +153,41 @@ ruby_finalize(void)
|
|||||||
int
|
int
|
||||||
ruby_cleanup(int ex)
|
ruby_cleanup(int ex)
|
||||||
{
|
{
|
||||||
int state;
|
int state, i;
|
||||||
volatile VALUE err = GET_THREAD()->errinfo;
|
volatile VALUE errs[2] = {GET_THREAD()->errinfo, 0};
|
||||||
rb_vm_t *vm = GET_THREAD()->vm;
|
rb_vm_t *vm = GET_THREAD()->vm;
|
||||||
|
|
||||||
/* th->errinfo contains a NODE while break'ing */
|
|
||||||
if (RTEST(err) && (TYPE(err) != T_NODE) &&
|
|
||||||
rb_obj_is_kind_of(err, rb_eSystemExit)) {
|
|
||||||
vm->exit_code = NUM2INT(rb_iv_get(err, "status"));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
vm->exit_code = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
GET_THREAD()->safe_level = 0;
|
GET_THREAD()->safe_level = 0;
|
||||||
Init_stack((void *)&state);
|
Init_stack((void *)&state);
|
||||||
PUSH_THREAD_TAG();
|
PUSH_THREAD_TAG();
|
||||||
if ((state = EXEC_TAG()) == 0) {
|
if ((state = EXEC_TAG()) == 0) {
|
||||||
if (GET_THREAD()->errinfo) {
|
|
||||||
err = GET_THREAD()->errinfo;
|
|
||||||
}
|
|
||||||
ruby_finalize_0();
|
ruby_finalize_0();
|
||||||
}
|
}
|
||||||
else if (ex == 0) {
|
else if (ex == 0) {
|
||||||
ex = state;
|
ex = state;
|
||||||
}
|
}
|
||||||
|
errs[1] = GET_THREAD()->errinfo;
|
||||||
rb_thread_terminate_all();
|
rb_thread_terminate_all();
|
||||||
GET_THREAD()->errinfo = err;
|
GET_THREAD()->errinfo = errs[0];
|
||||||
ex = error_handle(ex);
|
ex = error_handle(ex);
|
||||||
ruby_finalize_1();
|
ruby_finalize_1();
|
||||||
POP_THREAD_TAG();
|
POP_THREAD_TAG();
|
||||||
|
rb_thread_stop_timer_thread();
|
||||||
|
|
||||||
if (vm->exit_code) {
|
for (i = 2; i > 0; --i) {
|
||||||
return vm->exit_code;
|
VALUE err = errs[i];
|
||||||
|
|
||||||
|
/* th->errinfo contains a NODE while break'ing */
|
||||||
|
if (!RTEST(err) || (TYPE(err) == T_NODE)) continue;
|
||||||
|
|
||||||
|
if (rb_obj_is_kind_of(err, rb_eSystemExit)) {
|
||||||
|
return sysexit_status(err);
|
||||||
}
|
}
|
||||||
|
else if (rb_obj_is_kind_of(err, rb_eSignal)) {
|
||||||
|
ruby_default_signal(NUM2INT(rb_iv_get(err, "signo")));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return ex;
|
return ex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
11
eval_error.h
11
eval_error.h
@ -233,14 +233,19 @@ error_handle(int ex)
|
|||||||
warn_printf(": unexpected throw\n");
|
warn_printf(": unexpected throw\n");
|
||||||
break;
|
break;
|
||||||
case TAG_RAISE:
|
case TAG_RAISE:
|
||||||
case TAG_FATAL:
|
case TAG_FATAL: {
|
||||||
if (rb_obj_is_kind_of(GET_THREAD()->errinfo, rb_eSystemExit)) {
|
VALUE errinfo = GET_THREAD()->errinfo;
|
||||||
status = sysexit_status(GET_THREAD()->errinfo);
|
if (rb_obj_is_kind_of(errinfo, rb_eSystemExit)) {
|
||||||
|
status = sysexit_status(errinfo);
|
||||||
|
}
|
||||||
|
else if (rb_obj_is_instance_of(errinfo, rb_eSignal)) {
|
||||||
|
/* no message when exiting by signal */
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
error_print();
|
error_print();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
rb_bug("Unknown longjmp status %d", ex);
|
rb_bug("Unknown longjmp status %d", ex);
|
||||||
break;
|
break;
|
||||||
|
@ -143,7 +143,6 @@ terminate_process(int status, const char *mesg, long mlen)
|
|||||||
args[0] = INT2NUM(status);
|
args[0] = INT2NUM(status);
|
||||||
args[1] = rb_str_new(mesg, mlen);
|
args[1] = rb_str_new(mesg, mlen);
|
||||||
|
|
||||||
vm->exit_code = status;
|
|
||||||
rb_exc_raise(rb_class_new_instance(2, args, rb_eSystemExit));
|
rb_exc_raise(rb_class_new_instance(2, args, rb_eSystemExit));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
3
intern.h
3
intern.h
@ -274,7 +274,7 @@ VALUE rb_thread_run(VALUE);
|
|||||||
VALUE rb_thread_kill(VALUE);
|
VALUE rb_thread_kill(VALUE);
|
||||||
VALUE rb_thread_create(VALUE (*)(ANYARGS), void*);
|
VALUE rb_thread_create(VALUE (*)(ANYARGS), void*);
|
||||||
void rb_thread_trap_eval(VALUE, int, int);
|
void rb_thread_trap_eval(VALUE, int, int);
|
||||||
void rb_thread_signal_raise(void *, const char*); /* should pass literal */
|
void rb_thread_signal_raise(void *, int);
|
||||||
void rb_thread_signal_exit(void *);
|
void rb_thread_signal_exit(void *);
|
||||||
int rb_thread_select(int, fd_set *, fd_set *, fd_set *, struct timeval *);
|
int rb_thread_select(int, fd_set *, fd_set *, fd_set *, struct timeval *);
|
||||||
void rb_thread_wait_for(struct timeval);
|
void rb_thread_wait_for(struct timeval);
|
||||||
@ -471,6 +471,7 @@ void posix_signal(int, RETSIGTYPE (*)(int));
|
|||||||
void rb_trap_exit(void);
|
void rb_trap_exit(void);
|
||||||
void rb_trap_exec(void);
|
void rb_trap_exec(void);
|
||||||
const char *ruby_signal_name(int);
|
const char *ruby_signal_name(int);
|
||||||
|
void ruby_default_signal(int);
|
||||||
/* sprintf.c */
|
/* sprintf.c */
|
||||||
VALUE rb_f_sprintf(int, const VALUE*);
|
VALUE rb_f_sprintf(int, const VALUE*);
|
||||||
PRINTF_ARGS(VALUE rb_sprintf(const char*, ...), 1, 2);
|
PRINTF_ARGS(VALUE rb_sprintf(const char*, ...), 1, 2);
|
||||||
|
110
signal.c
110
signal.c
@ -14,6 +14,8 @@
|
|||||||
|
|
||||||
#include "ruby.h"
|
#include "ruby.h"
|
||||||
#include "rubysig.h"
|
#include "rubysig.h"
|
||||||
|
#include "node.h"
|
||||||
|
#include "yarvcore.h"
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
@ -196,6 +198,84 @@ ruby_signal_name(int no)
|
|||||||
return signo2signm(no);
|
return signo2signm(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(int argc, VALUE *argv, VALUE self)
|
||||||
|
{
|
||||||
|
int argnum = 1;
|
||||||
|
VALUE sig = Qnil;
|
||||||
|
int signo;
|
||||||
|
const char *signm;
|
||||||
|
|
||||||
|
if (argc > 0) {
|
||||||
|
sig = rb_check_to_integer(argv[0], "to_int");
|
||||||
|
if (!NIL_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 = NUM2INT(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) {
|
||||||
|
sig = rb_sprintf("SIG%s", signm);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
sig = rb_sprintf("SIG%u", signo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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(int argc, VALUE *argv, VALUE self)
|
||||||
|
{
|
||||||
|
VALUE args[2];
|
||||||
|
|
||||||
|
rb_scan_args(argc, argv, "01", &args[1]);
|
||||||
|
args[0] = INT2FIX(SIGINT);
|
||||||
|
return rb_call_super(argc + 1, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ruby_default_signal(int sig)
|
||||||
|
{
|
||||||
|
#ifndef MACOS_UNUSE_SIGNAL
|
||||||
|
signal(sig, SIG_DFL);
|
||||||
|
raise(sig);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* call-seq:
|
* call-seq:
|
||||||
* Process.kill(signal, pid, ...) => fixnum
|
* Process.kill(signal, pid, ...) => fixnum
|
||||||
@ -223,6 +303,9 @@ ruby_signal_name(int no)
|
|||||||
VALUE
|
VALUE
|
||||||
rb_f_kill(int argc, VALUE *argv)
|
rb_f_kill(int argc, VALUE *argv)
|
||||||
{
|
{
|
||||||
|
#ifndef HAS_KILLPG
|
||||||
|
#define killpg(pg, sig) kill(-(pg), sig)
|
||||||
|
#endif
|
||||||
int negative = 0;
|
int negative = 0;
|
||||||
int sig;
|
int sig;
|
||||||
int i;
|
int i;
|
||||||
@ -275,22 +358,17 @@ rb_f_kill(int argc, VALUE *argv)
|
|||||||
if (sig < 0) {
|
if (sig < 0) {
|
||||||
sig = -sig;
|
sig = -sig;
|
||||||
for (i=1; i<argc; i++) {
|
for (i=1; i<argc; i++) {
|
||||||
int pid = NUM2INT(argv[i]);
|
if (killpg(NUM2PIDT(argv[i]), sig) < 0)
|
||||||
#ifdef HAS_KILLPG
|
|
||||||
if (killpg(pid, sig) < 0)
|
|
||||||
#else
|
|
||||||
if (kill(-pid, sig) < 0)
|
|
||||||
#endif
|
|
||||||
rb_sys_fail(0);
|
rb_sys_fail(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
for (i=1; i<argc; i++) {
|
for (i=1; i<argc; i++) {
|
||||||
Check_Type(argv[i], T_FIXNUM);
|
if (kill(NUM2PIDT(argv[i]), sig) < 0)
|
||||||
if (kill(FIX2INT(argv[i]), sig) < 0)
|
|
||||||
rb_sys_fail(0);
|
rb_sys_fail(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
rb_thread_polling();
|
||||||
return INT2FIX(i-1);
|
return INT2FIX(i-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -369,9 +447,6 @@ ruby_nativethread_signal(int signum, sighandler_t handler)
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <node.h>
|
|
||||||
#include "yarvcore.h"
|
|
||||||
|
|
||||||
static RETSIGTYPE
|
static RETSIGTYPE
|
||||||
sighandler(int sig)
|
sighandler(int sig)
|
||||||
{
|
{
|
||||||
@ -498,6 +573,9 @@ rb_signal_exec(rb_thread_t *th, int sig)
|
|||||||
#ifdef SIGQUIT
|
#ifdef SIGQUIT
|
||||||
case SIGQUIT:
|
case SIGQUIT:
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef SIGTERM
|
||||||
|
case SIGTERM:
|
||||||
|
#endif
|
||||||
#ifdef SIGALRM
|
#ifdef SIGALRM
|
||||||
case SIGALRM:
|
case SIGALRM:
|
||||||
#endif
|
#endif
|
||||||
@ -507,7 +585,7 @@ rb_signal_exec(rb_thread_t *th, int sig)
|
|||||||
#ifdef SIGUSR2
|
#ifdef SIGUSR2
|
||||||
case SIGUSR2:
|
case SIGUSR2:
|
||||||
#endif
|
#endif
|
||||||
rb_thread_signal_raise(th, signo2signm(sig));
|
rb_thread_signal_raise(th, sig);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -638,6 +716,9 @@ trap(struct trap_arg *arg)
|
|||||||
#ifdef SIGQUIT
|
#ifdef SIGQUIT
|
||||||
case SIGQUIT:
|
case SIGQUIT:
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef SIGTERM
|
||||||
|
case SIGTERM:
|
||||||
|
#endif
|
||||||
#ifdef SIGALRM
|
#ifdef SIGALRM
|
||||||
case SIGALRM:
|
case SIGALRM:
|
||||||
#endif
|
#endif
|
||||||
@ -898,6 +979,11 @@ Init_signal(void)
|
|||||||
rb_define_module_function(mSignal, "trap", sig_trap, -1);
|
rb_define_module_function(mSignal, "trap", sig_trap, -1);
|
||||||
rb_define_module_function(mSignal, "list", sig_list, 0);
|
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);
|
install_sighandler(SIGINT, sighandler);
|
||||||
#ifdef SIGHUP
|
#ifdef SIGHUP
|
||||||
install_sighandler(SIGHUP, sighandler);
|
install_sighandler(SIGHUP, sighandler);
|
||||||
|
24
thread.c
24
thread.c
@ -751,31 +751,25 @@ rb_thread_raise(int argc, VALUE *argv, rb_thread_t *th)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
rb_thread_signal_raise(void *thptr, const char *sig)
|
rb_thread_signal_raise(void *thptr, int sig)
|
||||||
{
|
{
|
||||||
VALUE argv[1];
|
VALUE argv[2];
|
||||||
char buf[BUFSIZ];
|
|
||||||
rb_thread_t *th = thptr;
|
rb_thread_t *th = thptr;
|
||||||
|
|
||||||
if (sig == 0) {
|
argv[0] = rb_eSignal;
|
||||||
return; /* should not happen */
|
argv[1] = INT2FIX(sig);
|
||||||
}
|
rb_thread_raise(2, argv, th->vm->main_thread);
|
||||||
snprintf(buf, BUFSIZ, "SIG%s", sig);
|
|
||||||
argv[0] = rb_exc_new3(rb_eSignal, rb_str_new2(buf));
|
|
||||||
rb_thread_raise(1, argv, th->vm->main_thread);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
rb_thread_signal_exit(void *thptr)
|
rb_thread_signal_exit(void *thptr)
|
||||||
{
|
{
|
||||||
VALUE argv[1];
|
VALUE argv[2];
|
||||||
VALUE args[2];
|
|
||||||
rb_thread_t *th = thptr;
|
rb_thread_t *th = thptr;
|
||||||
|
|
||||||
args[0] = INT2NUM(EXIT_SUCCESS);
|
argv[0] = rb_eSystemExit;
|
||||||
args[1] = rb_str_new2("exit");
|
argv[1] = rb_str_new2("exit");
|
||||||
argv[0] = rb_class_new_instance(2, args, rb_eSystemExit);
|
rb_thread_raise(2, argv, th->vm->main_thread);
|
||||||
rb_thread_raise(1, argv, th->vm->main_thread);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#define RUBY_VERSION "1.9.0"
|
#define RUBY_VERSION "1.9.0"
|
||||||
#define RUBY_RELEASE_DATE "2007-04-19"
|
#define RUBY_RELEASE_DATE "2007-04-20"
|
||||||
#define RUBY_VERSION_CODE 190
|
#define RUBY_VERSION_CODE 190
|
||||||
#define RUBY_RELEASE_CODE 20070419
|
#define RUBY_RELEASE_CODE 20070420
|
||||||
#define RUBY_PATCHLEVEL 0
|
#define RUBY_PATCHLEVEL 0
|
||||||
|
|
||||||
#define RUBY_VERSION_MAJOR 1
|
#define RUBY_VERSION_MAJOR 1
|
||||||
@ -9,7 +9,7 @@
|
|||||||
#define RUBY_VERSION_TEENY 0
|
#define RUBY_VERSION_TEENY 0
|
||||||
#define RUBY_RELEASE_YEAR 2007
|
#define RUBY_RELEASE_YEAR 2007
|
||||||
#define RUBY_RELEASE_MONTH 4
|
#define RUBY_RELEASE_MONTH 4
|
||||||
#define RUBY_RELEASE_DAY 19
|
#define RUBY_RELEASE_DAY 20
|
||||||
|
|
||||||
RUBY_EXTERN const char ruby_version[];
|
RUBY_EXTERN const char ruby_version[];
|
||||||
RUBY_EXTERN const char ruby_release_date[];
|
RUBY_EXTERN const char ruby_release_date[];
|
||||||
|
@ -345,7 +345,6 @@ typedef struct rb_vm_struct {
|
|||||||
|
|
||||||
int thread_abort_on_exception;
|
int thread_abort_on_exception;
|
||||||
unsigned long trace_flag;
|
unsigned long trace_flag;
|
||||||
int exit_code;
|
|
||||||
|
|
||||||
/* object management */
|
/* object management */
|
||||||
VALUE mark_object_ary;
|
VALUE mark_object_ary;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user