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 /uloop.h
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 'uloop.h')
-rw-r--r--uloop.h15
1 files changed, 15 insertions, 0 deletions
diff --git a/uloop.h b/uloop.h
index b3f268c..5edeb70 100644
--- a/uloop.h
+++ b/uloop.h
@@ -36,11 +36,13 @@ struct uloop_fd;
struct uloop_timeout;
struct uloop_process;
struct uloop_interval;
+struct uloop_signal;
typedef void (*uloop_fd_handler)(struct uloop_fd *u, unsigned int events);
typedef void (*uloop_timeout_handler)(struct uloop_timeout *t);
typedef void (*uloop_process_handler)(struct uloop_process *c, int ret);
typedef void (*uloop_interval_handler)(struct uloop_interval *t);
+typedef void (*uloop_signal_handler)(struct uloop_signal *s);
#define ULOOP_READ (1 << 0)
#define ULOOP_WRITE (1 << 1)
@@ -99,6 +101,16 @@ struct uloop_interval
} private;
};
+struct uloop_signal
+{
+ struct list_head list;
+ struct sigaction orig;
+ bool pending;
+
+ uloop_signal_handler cb;
+ int signo;
+};
+
extern bool uloop_cancelled;
extern bool uloop_handle_sigchld;
extern uloop_fd_handler uloop_fd_set_cb;
@@ -120,6 +132,9 @@ int uloop_interval_set(struct uloop_interval *timer, unsigned int msecs);
int uloop_interval_cancel(struct uloop_interval *timer);
int64_t uloop_interval_remaining(struct uloop_interval *timer);
+int uloop_signal_add(struct uloop_signal *s);
+int uloop_signal_delete(struct uloop_signal *s);
+
bool uloop_cancelling(void);
static inline void uloop_end(void)