Hi,

I wonna to receive siginfo struct available in Linux for real-time signals. More specifically, I wonna recieve file descriptor number for SIG_IO events.

After diggin Perl sources I realized I can't recieve this neither in normal Perlish way thru $SIG{signo} handler nor thru POSIX sigaction. This is because Perl declare Perl_sighandler(int) but not like void (*sa_sigaction)(int, siginfo_t *, void *). So small XS was written (skeleton of this XS posted below).

Question : is this safe ? Can my signal handler ruins something ? Can any problems be if my handler fire than Perl for example runs malloc ? And the most important question : is there are any better way to retrieve siginfo in signal handler ?
Question2 : can I safe (relatevely safe :) ) make simple Perl callback in signal handler ? (of course this callback will as small as possible like Perl signal handlers before "Perl safe signals".
//... static int FD_set[MAX_FD], FD_q[MAX_FD]; // Static structures here to not make malloc at all :) static int pos = 1; static int sig; void Handler(int sig, siginfo_t *si, void *whatisthis) { // work like Edge Triggered if (FD_set[si->si_fd]) {; return; } FD_set[si->si_fd] = pos; FD_q[pos] = si->si_fd; pos++; } MODULE = RtSig PACKAGE = RtSig int SetSigaction(arg) int arg CODE: struct sigaction act; sig = arg; act.sa_flags = SA_SIGINFO|SA_RESTART; act.sa_sigaction = Handler; sigfillset(&act.sa_mask); if (sigaction(sig, &act, 0) == 0) { RETVAL = 1; } else { XSRETURN_UNDEF; } OUTPUT: RETVAL void Poll() INIT: int i; sigset_t mask, old_mask; PPCODE: sigemptyset(&mask); sigaddset(&mask, sig); sigprocmask(SIG_BLOCK, &mask, &old_mask); for (i=1; i < pos; i++) { XPUSHs(sv_2mortal(newSVnv(FD_q[i]))); FD_set[FD_q[i]] = 0; FD_q[i] = 0; } pos = 1; sigprocmask(SIG_SETMASK, &old_mask, 0);

In reply to receive siginfo for real time signals. by asdfgroup

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.