Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.openwrt.org/project/libubox.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2023-10-16 17:35:28 +0300
committerFelix Fietkau <nbd@nbd.name>2023-11-02 19:56:45 +0300
commit13d9b04fb09d39a7204ba1e9cc9c8403fa22efa8 (patch)
tree5a3882800b8507e2fbf08d4f6bc5a123cfc2b63b /examples
parent82fa6480de7a85d0ced0701ab7c8825e31b90770 (diff)
uloop: add support for user defined signal handlers
Reuse and extend the existing signal waker pipe mechanism to add user defined signal handling functionality to uloop. This commit introduces two new api functions `uloop_signal_add()` and `uloop_signal_remove()` along with a new structure type `uloop_signal` to allow adding and removing arbitrary signal handlers. Registered signal handlers are maintained in a linked list and matched by their signo member value which allows registering multiple handlers for the same signal numbers. Upon registering a new signal handler, the existing handler is saved in the `uloop_signal` structure. When removing the user defined signal handler, the original behavior is restored. The Lua binding has been updated as well to support the new signal handler mechanism. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'examples')
-rwxr-xr-xexamples/uloop-example.lua16
1 files changed, 16 insertions, 0 deletions
diff --git a/examples/uloop-example.lua b/examples/uloop-example.lua
index f3aef60..1b73aed 100755
--- a/examples/uloop-example.lua
+++ b/examples/uloop-example.lua
@@ -63,6 +63,22 @@ uloop.timer(
end, 2000
)
+-- SIGINT handler
+uloop.signal(function(signo)
+ print(string.format("Terminating on SIGINT (#%d)!", signo))
+
+ -- end uloop to terminate program
+ uloop.cancel()
+end, uloop.SIGINT)
+
+local sig
+sig = uloop.signal(function(signo)
+ print(string.format("Got SIGUSR2 (#%d)!", signo))
+
+ -- remove signal handler, next SIGUSR2 will terminate program
+ sig:delete()
+end, uloop.SIGUSR2)
+
-- Keep udp_ev reference, events will be gc'd, even if the callback is still referenced
-- .delete will manually untrack.
udp_ev = uloop.fd_add(udp, function(ufd, events)