diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-07-16 09:04:37 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-07-16 09:04:37 +0000 |
commit | 1b2af065a2b8beb5500676833e1ac9e7f7c54881 (patch) | |
tree | 137b4e3bd128173c63319e45ec118c23b0a4bf9e /signal.c | |
parent | 5198897802c8e171a6f9f80bdae9a8a80b70d0ef (diff) | |
download | ruby-1b2af065a2b8beb5500676833e1ac9e7f7c54881.tar.gz |
* signal.c (signal_exec, trap_handler): trap accepts a string as
command. [ruby-dev:35533]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18084 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'signal.c')
-rw-r--r-- | signal.c | 20 |
1 files changed, 9 insertions, 11 deletions
@@ -391,6 +391,7 @@ rb_f_kill(int argc, VALUE *argv) static struct { VALUE cmd; + int safe; } trap_list[NSIG]; static rb_atomic_t trap_pending_list[NSIG]; #if 0 @@ -578,6 +579,11 @@ signal_exec(VALUE cmd, int sig) { rb_proc_t *proc; VALUE signum = INT2FIX(sig); + + if (TYPE(cmd) == T_STRING) { + rb_eval_cmd(cmd, rb_ary_new3(1, signum), trap_list[sig].safe); + return; + } GetProcPtr(cmd, proc); vm_invoke_proc(GET_THREAD(), proc, proc->block.self, 1, &signum, 0); } @@ -713,15 +719,10 @@ default_handler(int sig) return func; } -static RETSIGTYPE -wrong_trap(int sig) -{ -} - static sighandler_t trap_handler(VALUE *cmd, int sig) { - sighandler_t func = wrong_trap; + sighandler_t func = sighandler; VALUE command; if (NIL_P(*cmd)) { @@ -731,6 +732,7 @@ trap_handler(VALUE *cmd, int sig) command = rb_check_string_type(*cmd); if (!NIL_P(command)) { SafeStringValue(command); /* taint check */ + *cmd = command; switch (RSTRING_LEN(command)) { case 0: goto sig_ign; @@ -763,19 +765,14 @@ sig_dfl: break; case 4: if (strncmp(RSTRING_PTR(command), "EXIT", 4) == 0) { - func = sighandler; *cmd = Qundef; } break; } - if (func == wrong_trap) { - rb_raise(rb_eArgError, "wrong trap - %s", RSTRING_PTR(command)); - } } else { rb_proc_t *proc; GetProcPtr(*cmd, proc); - func = sighandler; } } @@ -835,6 +832,7 @@ trap(struct trap_arg *arg) } trap_list[sig].cmd = command; + trap_list[sig].safe = rb_safe_level(); /* enable at least specified signal. */ #if USE_TRAP_MASK #ifdef HAVE_SIGPROCMASK |