+static void uloop_install_handler(int signum, void (*handler)(int), struct sigaction* old, bool add)
+{
+ struct sigaction s;
+ struct sigaction *act;
+
+ act = NULL;
+ sigaction(signum, NULL, &s);
+
+ if (add) {
+ if (s.sa_handler == SIG_DFL) { /* Do not override existing custom signal handlers */
+ memcpy(old, &s, sizeof(struct sigaction));
+ s.sa_handler = handler;
+ s.sa_flags = 0;
+ act = &s;
+ }
+ }
+ else if (s.sa_handler == handler) { /* Do not restore if someone modified our handler */
+ act = old;
+ }
+
+ if (act != NULL)
+ sigaction(signum, act, NULL);
+}
+
+static void uloop_ignore_signal(int signum, bool ignore)