Run registered signal handlers also when a port read is interrupted?
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 38/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Stale
- Domain
- backend
Research direction
Start with the cited EINTR handling in c/new-io.c around line 494, then trace how its result reaches check-interrupt in s/io.ss around line 996. The issue proposes returning an interrupt result for EINTR so the Scheme event loop can process registered signal handlers. Done means reproducing the port-read behavior and confirming arbitrary signal handlers run when a blocking read is interrupted.
Written by the indexing model from the issue text.
Description
I am trying to use (register-signal-handler) on Chez Scheme 10.0.0 and Linux/x86_64
to install signal handlers for the POSIX signals SIGQUIT, SIGTSTP, SIGCHLD and possibly others,
and I noticed an inconsistent behavior:
the installed handlers are called immediately if a long or infinite loop is running,
but are not called immediately if Scheme code is waiting inside a port read.
In practice: after executing
(define (my-signal-handler int)
(let ((port (console-error-port)))
(format port "received signal: ~a\n" int)
(flush-output-port port))
;; a full implementation would call some custom logic.
;; for this example, keep it simple and always call (break)
(break))
(register-signal-handler 3 my-signal-handler) ; SIGQUIT on Linux/x86_64
(register-signal-handler 17 my-signal-handler) ; SIGCHLD on Linux/x86_64
(register-signal-handler 20 my-signal-handler) ; SIGTSTP on Linux/x86_64
a long or infinite loop can be interrupted any of:
- CTRL+C - generates
SIGINT - CTRL+Z - generates
SIGTSTP - CTRL+\ - generates
SIGQUIT
> (do () (#f))
CTRL+C
break>
> (do () (#f))
CTRL+Z
received signal: 20
break>
i.e. (my-signal-handler) is invoked from the infinite loop.
> (do () (#f))
CTRL+\
received signal: 3
break>
idem.
A port read instead behaves differently:
> (get-string-all (current-input-port))
CTRL+C
break>
> (get-string-all (current-input-port))
CTRL+Z ; no effect
> (get-string-all (current-input-port))
CTRL+\ ; no effect
Examining the source code, I noticed c/new-io.c:494
if (Sboolean_value(KEYBOARDINTERRUPTPENDING(tc))) {
return Sstring("interrupt");
}
and similar checks at lines 482 and 486 for keyboard interrupt i.e. CTRL+C on POSIX systems.
Wouldn't it be more useful to always return Sstring("interrupt") if errno == EINTR ?
In this way, the Scheme side s/io.ss:996
(define-syntax check-interrupt
(syntax-rules ()
[(_ e)
(let loop ()
(let ([x e])
(if (eq? x 'interrupt)
(begin ($event) (loop))
x)))]))
would see a value 'interrupt (there's a conversion "interrupt" -> 'interrupt in the meantime)
and always invoke ($event), which checks for all pending interrupts, expired timers etc.
Doing so would allow signal handlers installed by (register-signal-handler)
to run also when a blocking C call is interrupted by any signal,
while currently only long or infinite Scheme loops can be interrupted by an arbitrary signal.
- Dominant language
- Scheme
- Stars
- 7.4k
- Forks
- 1k
- Avg merge
- 1d 20h
- Merged PRs (30d)
- 19
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from cisco/ChezScheme
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
cisco/ChezScheme#1110 ·
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 30/100
cisco/ChezScheme#1111 ·
Maintainers usually reply within 1 day
-
Difficulty 5/5 Over a week Newbie friendliness 12/100
cisco/ChezScheme#1101 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
cisco/ChezScheme#1078 · 1 comment ·
Maintainers usually reply within 1 day
-
RFC: solution to clangd not finding "scheme.h"Possibly taken @reginaldalfret claimed this 20 days ago. Open
Difficulty 4/5 3-5 days Newbie friendliness 48/100
cisco/ChezScheme#1073 · 1 comment ·
Maintainers usually reply within 1 day
All issues in cisco/ChezScheme
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
Kludex/python-multipart#375 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Termix-SSH/Plugin-Hosts-Config#14 · 1 comment ·
Maintainers usually reply within 4 days
-
bug good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
quantum-php/framework#692 ·
Maintainers usually reply within 1 day
-
area:web kind:bug priority:p2 ready
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
Maintainers usually reply within 1 day
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
Maintainers usually reply within 11 days