Use of this class is NOT recommended. Ruby itself has a great signal handling API and its implementation conflicts with this.
This class is currently disabled and the documentation is only provided to describe what it would look like.
A SignalFD is an IO object for accepting signals. It provides an alternative to Signal.trap that may be monitored using IO.select or Epoll.
SignalFD appears interact unpredictably with YARV (Ruby 1.9) signal handling and has been unreliable in our testing. Since Ruby has a decent signal handling interface anyways, this class is less useful than signalfd() in a C-only environment.
It is not supported at all.
Creates a new SignalFD object to watch given signals with flags.
signals is an Array of signal names or a single signal name that Signal.trap understands:
signals = [ :USR1, "USR2" ] signals = :USR1 signals = 15
Starting with Linux 2.6.27, flags may be a mask that consists of any of the following:
:CLOEXEC - set the close-on-exec flag on the new object
:NONBLOCK - set the non-blocking I/O flag on the new object
static VALUE s_new(int argc, VALUE *argv, VALUE klass)
{
VALUE vmask, vflags, rv;
sigset_t mask;
int flags;
int fd;
rb_scan_args(argc, argv, "02", &vmask, &vflags);
flags = rb_sp_get_flags(klass, vflags);
value2sigset(&mask, vmask);
fd = signalfd(-1, &mask, flags);
if (fd == -1) {
if (errno == EMFILE || errno == ENFILE || errno == ENOMEM) {
rb_gc();
fd = signalfd(-1, &mask, flags);
}
if (fd == -1)
rb_sys_fail("signalfd");
}
rv = INT2FIX(fd);
return rb_call_super(1, &rv);
}
Returns the next SigInfo object representing a received signal. If nonblock is specified and true, this may return nil
static VALUE sfd_take(int argc, VALUE *argv, VALUE self)
{
VALUE rv = ssi_alloc(cSigInfo);
struct signalfd_siginfo *ssi = DATA_PTR(rv);
ssize_t r;
int fd;
VALUE nonblock;
rb_scan_args(argc, argv, "01", &nonblock);
fd = rb_sp_fileno(self);
if (RTEST(nonblock))
rb_sp_set_nonblock(fd);
else
blocking_io_prepare(fd);
retry:
ssi->ssi_fd = fd;
r = (ssize_t)rb_sp_fd_region(sfd_read, ssi, fd);
if (r == -1) {
if (errno == EAGAIN && RTEST(nonblock))
return Qnil;
if (rb_sp_wait(rb_io_wait_readable, self, &fd))
goto retry;
rb_sys_fail("read(signalfd)");
}
if (r == 0)
rb_eof_error(); /* does this ever happen? */
return rv;
}
Updates the signal mask watched for by the given sfd. Takes the same arguments as SignalFD.new.
static VALUE update_bang(int argc, VALUE *argv, VALUE self)
{
VALUE vmask, vflags;
sigset_t mask;
int flags;
int fd = rb_sp_fileno(self);
int rc;
rb_scan_args(argc, argv, "02", &vmask, &vflags);
flags = NIL_P(vflags) ? cur_flags(fd) : rb_sp_get_flags(self, vflags);
value2sigset(&mask, vmask);
rc = signalfd(fd, &mask, flags);
if (rc == -1)
rb_sys_fail("signalfd");
return self;
}
Originally generated with the Darkfish Rdoc Generator 2, modified by wrongdoc.
We love to hear from you!