mirror of
https://github.com/janet-lang/janet
synced 2025-02-01 17:59:10 +00:00
Update sigaction to help address #1262.
Update example to have 4 cases - case 3 was previously broken but should now work.
This commit is contained in:
parent
d9605c2856
commit
21eab7e9cc
@ -1,11 +1,41 @@
|
|||||||
(defn action []
|
###
|
||||||
(print "cleanup")
|
### Usage: janet examples/sigaction.janet 1|2|3|4 &
|
||||||
|
###
|
||||||
|
### Then at shell: kill -s SIGTERM $!
|
||||||
|
###
|
||||||
|
|
||||||
|
(defn action
|
||||||
|
[]
|
||||||
|
(print "Handled SIGTERM!")
|
||||||
|
(flush)
|
||||||
(os/exit 1))
|
(os/exit 1))
|
||||||
|
|
||||||
(defn main [_]
|
(defn main1
|
||||||
# Set the interrupt-interpreter argument to `true` to allow
|
[]
|
||||||
# interrupting the busy loop `(forever)`. By default, will not
|
|
||||||
# interrupt the interpreter.
|
|
||||||
(os/sigaction :term action true)
|
(os/sigaction :term action true)
|
||||||
(os/sigaction :int action true)
|
|
||||||
(forever))
|
(forever))
|
||||||
|
|
||||||
|
(defn main2
|
||||||
|
[]
|
||||||
|
(os/sigaction :term action)
|
||||||
|
(forever))
|
||||||
|
|
||||||
|
(defn main3
|
||||||
|
[]
|
||||||
|
(os/sigaction :term action true)
|
||||||
|
(forever (ev/sleep math/inf)))
|
||||||
|
|
||||||
|
(defn main4
|
||||||
|
[]
|
||||||
|
(os/sigaction :term action)
|
||||||
|
(forever (ev/sleep math/inf)))
|
||||||
|
|
||||||
|
(defn main
|
||||||
|
[& args]
|
||||||
|
(def which (scan-number (get args 1 "1")))
|
||||||
|
(case which
|
||||||
|
1 (main1) # should work
|
||||||
|
2 (main2) # will not work
|
||||||
|
3 (main3) # should work
|
||||||
|
4 (main4) # should work
|
||||||
|
(error "bad main")))
|
||||||
|
@ -827,6 +827,7 @@ static void janet_signal_callback(JanetEVGenericMessage msg) {
|
|||||||
JanetFiber *fiber = janet_fiber(handler, 64, 0, NULL);
|
JanetFiber *fiber = janet_fiber(handler, 64, 0, NULL);
|
||||||
janet_schedule(fiber, janet_wrap_nil());
|
janet_schedule(fiber, janet_wrap_nil());
|
||||||
if (msg.argi) {
|
if (msg.argi) {
|
||||||
|
janet_vm.auto_suspend = 0; /* Undo interrupt if it wasn't needed. */
|
||||||
janet_ev_dec_refcount();
|
janet_ev_dec_refcount();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user