Re: Interrupt handlers are not called

Robert Ransom <[email protected]> Sat, 7 Nov 2009 21:41:03 -0800
Newsgroups gmane.lisp.scheme.scheme48
Message-ID <20091107214103.09f6654e@neutron>
On Fri, 6 Nov 2009 15:03:31 -0500
Roderic Morris <[email protected]> wrote:

> I'm trying to use the interrupts package's set-interrupt-handler! to
> catch interrupts of type os-signal. The handler I set seems to never
> be called though. If i send a sigchld to the scheme48 process, nothing
> happens, and if i send something more exotic like sigpwr on linux, it
> actually dies.
> 
> Interrupt handlers seem to work as expected in the scheme48 bundled
> with scsh 0.6.7 (or else they changed it to work). It may be the case
> that the package's usage has changed, but there doesn't seem to be any
> documentation for it, so I can't tell. Should something like this
> work?
> 
> (set-interrupt-handler! (enum interrupt os-signal)
>                         (lambda (type enabled-interrupts)
>                           (display type) (newline)
>                           (display enabled-interrupts) (newline)))
> 
> -Roderic
> 

I just pulled from the repository, and saw your patches.  I'm sorry
about my RTFS response; I thought you were actually trying to use
set-interrupt-handler! yourself.

Some more useful information, in case you haven't found the problem
already:

- The interrupt system can't be completely broken, because keyboard
  interrupts work.  (Try evaluating (do () (#f)) or (let loop ()
  (loop)) at the REPL prompt, then pressing C-c (then you will need to
  use the reset command, not pop, to break out of the loop).)

- If you need to see a message when os-signal interrupts occur, put
  calls to debug-message (from structure debug-messages, possibly
  available from primitives as well) in os-signal-handler and rebuild
  scheme48.image.  Test this with SIGINT (if c/posix/proc.c doesn't
  catch this, c/unix/event.c will, so the process won't die), after
  calling add-signal-queue-signal!.

  I would avoid calling display and newline from an interrupt handler
  if possible, but I don't know whether or not they would cause a
  problem.

- Scheme 48 will not produce os-signal interrupts for a signal until
  the C function posix_request_interrupts (in c/posix/proc.c, and
  apparently called by request-interrupts! in scheme/posix/signal.scm)
  has been called for that signal.  This should be done (at most once
  per signal) by maybe-request-os-signal!.

- The VM code for the interrupt system is in
  scheme/vm/interp/interrupt.scm; examine the os-signal-ring code there
  if you are sure the posix/proc.c signal handler is set up properly,
  but the signal interrupts seem to be getting lost between the C
  signal handler and Scheme.

Robert Ransom