Permalink
Browse files

signal can be specified by string or symbol.

  • Loading branch information...
tsahara committed Dec 18, 2013
1 parent 137b025 commit 2a7d896a87f4a3dae105911e678a1052a122128a
Showing with 156 additions and 2 deletions.
  1. +20 −0 src/gen.rb
  2. +32 −2 src/process.c
  3. +78 −0 src/signals.cstub
  4. +26 −0 src/signals.def
View
@@ -0,0 +1,20 @@
#!/usr/bin/env ruby
Dir.chdir(File.dirname($0))
f = File.open("signals.cstub", "w")
IO.readlines("signals.def").each { |name|
name.sub(/^#.*/, "")
name.strip!
next if name.empty?
raise "invalid signal name: #{name}" unless name =~ /^SIG(.+)/
sym = $1
f.write <<CODE
#ifdef #{name}
{ "#{sym}", #{name} },
#endif
CODE
}
View
@@ -25,17 +25,47 @@
static mrb_value mrb_f_exit_common(mrb_state *mrb, int bang);
static struct {
const char *name;
int no;
} signals[] = {
#include "signals.cstub"
{ NULL, 0 }
};
#include <err.h>
mrb_value
mrb_f_kill(mrb_state *mrb, mrb_value klass)
{
mrb_int pid;
mrb_value *argv, sigo;
int argc, sent, signo = 0;
int argc, i, sent, signo = 0;
size_t namelen;
const char *name;
mrb_get_args(mrb, "oi*", &sigo, &pid, &argv, &argc);
if (mrb_fixnum_p(sigo)) {
signo = mrb_fixnum(sigo);
} else if (mrb_string_p(sigo) || mrb_symbol_p(sigo)) {
if (mrb_string_p(sigo)) {
name = RSTRING_PTR(sigo);
namelen = (size_t)RSTRING_LEN(sigo);
} else {
name = mrb_sym2name_len(mrb, mrb_symbol(sigo), &namelen);
}
if (namelen >= 3 && strncmp(name, "SIG", 3) == 0) {
name += 3;
namelen -= 3;
}
for (i = 0; signals[i].name != NULL; i++) {
if (strncmp(name, signals[i].name, namelen) == 0 && strlen(signals[i].name) == namelen) {
signo = signals[i].no;
break;
}
}
if (signals[i].name == NULL) {
mrb_raisef(mrb, E_ARGUMENT_ERROR, "unsupported name `SIG%S'", mrb_str_new(mrb, name, namelen));
}
} else {
mrb_raisef(mrb, E_TYPE_ERROR, "bad signal type %s",
mrb_obj_classname(mrb, sigo));
View
@@ -0,0 +1,78 @@
#ifdef SIGABRT
{ "ABRT", SIGABRT },
#endif
#ifdef SIGALRM
{ "ALRM", SIGALRM },
#endif
#ifdef SIGBUS
{ "BUS", SIGBUS },
#endif
#ifdef SIGCHLD
{ "CHLD", SIGCHLD },
#endif
#ifdef SIGCONT
{ "CONT", SIGCONT },
#endif
#ifdef SIGFPE
{ "FPE", SIGFPE },
#endif
#ifdef SIGHUP
{ "HUP", SIGHUP },
#endif
#ifdef SIGILL
{ "ILL", SIGILL },
#endif
#ifdef SIGINT
{ "INT", SIGINT },
#endif
#ifdef SIGKILL
{ "KILL", SIGKILL },
#endif
#ifdef SIGPIPE
{ "PIPE", SIGPIPE },
#endif
#ifdef SIGPROF
{ "PROF", SIGPROF },
#endif
#ifdef SIGQUIT
{ "QUIT", SIGQUIT },
#endif
#ifdef SIGSEGV
{ "SEGV", SIGSEGV },
#endif
#ifdef SIGSTOP
{ "STOP", SIGSTOP },
#endif
#ifdef SIGSYS
{ "SYS", SIGSYS },
#endif
#ifdef SIGTERM
{ "TERM", SIGTERM },
#endif
#ifdef SIGTRAP
{ "TRAP", SIGTRAP },
#endif
#ifdef SIGTSTP
{ "TSTP", SIGTSTP },
#endif
#ifdef SIGTTIN
{ "TTIN", SIGTTIN },
#endif
#ifdef SIGTTOU
{ "TTOU", SIGTTOU },
#endif
#ifdef SIGURG
{ "URG", SIGURG },
#endif
#ifdef SIGUSR1
{ "USR1", SIGUSR1 },
#endif
#ifdef SIGUSR2
{ "USR2", SIGUSR2 },
#endif
#ifdef SIGXCPU
{ "XCPU", SIGXCPU },
#endif
#ifdef SIGXFSZ
{ "XFSZ", SIGXFSZ },
#endif
View
@@ -0,0 +1,26 @@
SIGABRT
SIGALRM
SIGBUS
SIGCHLD
SIGCONT
SIGFPE
SIGHUP
SIGILL
SIGINT
SIGKILL
SIGPIPE
SIGPROF
SIGQUIT
SIGSEGV
SIGSTOP
SIGSYS
SIGTERM
SIGTRAP
SIGTSTP
SIGTTIN
SIGTTOU
SIGURG
SIGUSR1
SIGUSR2
SIGXCPU
SIGXFSZ

0 comments on commit 2a7d896

Please sign in to comment.