When a process quits in response to a signal it handles, it should to so
be re-sending the signal to itself. This especially important for SIGINT,
as is explained in [1].

uloop currently hides the reason for quitting uloop_run(). Fix this by
returning the signal that caused the loop to quit (or 0 when uloop_end()
was used), so a program using loop an comply with [1].

[1] https://www.cons.org/cracauer/sigint.html

Signed-off-by: Matthias Schiffer <mschif...@universe-factory.net>
---
v2: keep uloop_cancelled in addition to uloop_status to make libubus happy

 uloop.c | 9 +++++++--
 uloop.h | 2 +-
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/uloop.c b/uloop.c
index cd3de85..89c49a3 100644
--- a/uloop.c
+++ b/uloop.c
@@ -58,6 +58,7 @@ static struct list_head processes = LIST_HEAD_INIT(processes);
 
 static int poll_fd = -1;
 bool uloop_cancelled = false;
+static int uloop_status = 0;
 static bool do_sigchld = false;
 
 static struct uloop_fd_event cur_fds[ULOOP_MAX_EVENTS];
@@ -330,6 +331,7 @@ static void uloop_handle_processes(void)
 
 static void uloop_handle_sigint(int signo)
 {
+       uloop_status = signo;
        uloop_cancelled = true;
 }
 
@@ -443,7 +445,7 @@ static void uloop_clear_processes(void)
                uloop_process_delete(p);
 }
 
-void uloop_run(void)
+int uloop_run(void)
 {
        static int recursive_calls = 0;
        struct timeval tv;
@@ -455,8 +457,9 @@ void uloop_run(void)
        if (!recursive_calls++)
                uloop_setup_signals(true);
 
+       uloop_status = 0;
        uloop_cancelled = false;
-       while(!uloop_cancelled)
+       while (!uloop_cancelled)
        {
                uloop_gettime(&tv);
                uloop_process_timeouts(&tv);
@@ -473,6 +476,8 @@ void uloop_run(void)
 
        if (!--recursive_calls)
                uloop_setup_signals(false);
+
+       return uloop_status;
 }
 
 void uloop_done(void)
diff --git a/uloop.h b/uloop.h
index 7564514..2f1eb4c 100644
--- a/uloop.h
+++ b/uloop.h
@@ -103,7 +103,7 @@ static inline void uloop_end(void)
 }
 
 int uloop_init(void);
-void uloop_run(void);
+int uloop_run(void);
 void uloop_done(void);
 
 #endif
-- 
2.9.0


_______________________________________________
Lede-dev mailing list
Lede-dev@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/lede-dev

Reply via email to