From patchwork Mon Jun 20 07:59:46 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthias Schiffer X-Patchwork-Id: 637856 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2001:1868:205::9]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3rY3H90Qj7z9t1F for ; Mon, 20 Jun 2016 18:02:13 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1bEu89-0002Ym-HR; Mon, 20 Jun 2016 08:00:25 +0000 Received: from chaos.universe-factory.net ([2a02:2918:505:100::22]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1bEu86-0001IH-Fr for lede-dev@lists.infradead.org; Mon, 20 Jun 2016 08:00:23 +0000 Received: from localhost.localdomain (unknown [IPv6:fd1b:c28a:2fd6::2]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by chaos.universe-factory.net (Postfix) with ESMTPSA id DF2131829E8; Mon, 20 Jun 2016 09:59:57 +0200 (CEST) From: Matthias Schiffer To: openwrt-devel@lists.openwrt.org, lede-dev@lists.infradead.org Date: Mon, 20 Jun 2016 09:59:46 +0200 Message-Id: <22d591176c7b3512ceabddf439a6d6ab682288d1.1466409587.git.mschiffer@universe-factory.net> X-Mailer: git-send-email 2.9.0 In-Reply-To: References: In-Reply-To: References: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160620_010022_705410_E335C901 X-CRM114-Status: GOOD ( 13.30 ) X-Spam-Score: -3.3 (---) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-3.3 points) pts rule name description ---- ---------------------- -------------------------------------------------- -1.4 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Subject: [LEDE-DEV] [PATCH libubox 2/3] loop: make uloop_run() return the cancelling signal X-BeenThere: lede-dev@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "Lede-dev" Errors-To: lede-dev-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org 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]. uloop_cancelled is renamed to uloop_status, so accidentially running a process compiled with one uloop_cancelled definition against the other is not possible. [1] https://www.cons.org/cracauer/sigint.html Signed-off-by: Matthias Schiffer Acked-by: Jo-Philipp Wich --- uloop.c | 14 ++++++++------ uloop.h | 6 +++--- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/uloop.c b/uloop.c index cd3de85..fa3544d 100644 --- a/uloop.c +++ b/uloop.c @@ -57,7 +57,7 @@ static struct list_head timeouts = LIST_HEAD_INIT(timeouts); static struct list_head processes = LIST_HEAD_INIT(processes); static int poll_fd = -1; -bool uloop_cancelled = false; +int uloop_status = -1; static bool do_sigchld = false; static struct uloop_fd_event cur_fds[ULOOP_MAX_EVENTS]; @@ -330,7 +330,7 @@ static void uloop_handle_processes(void) static void uloop_handle_sigint(int signo) { - uloop_cancelled = true; + uloop_status = signo; } static void uloop_sigchld(int signo) @@ -443,7 +443,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 +455,8 @@ void uloop_run(void) if (!recursive_calls++) uloop_setup_signals(true); - uloop_cancelled = false; - while(!uloop_cancelled) + uloop_status = -1; + while (uloop_status < 0) { uloop_gettime(&tv); uloop_process_timeouts(&tv); @@ -464,7 +464,7 @@ void uloop_run(void) if (do_sigchld) uloop_handle_processes(); - if (uloop_cancelled) + if (uloop_status >= 0) break; uloop_gettime(&tv); @@ -473,6 +473,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..4d87d46 100644 --- a/uloop.h +++ b/uloop.h @@ -83,7 +83,7 @@ struct uloop_process pid_t pid; }; -extern bool uloop_cancelled; +extern int uloop_status; extern bool uloop_handle_sigchld; int uloop_fd_add(struct uloop_fd *sock, unsigned int flags); @@ -99,11 +99,11 @@ int uloop_process_delete(struct uloop_process *p); static inline void uloop_end(void) { - uloop_cancelled = true; + uloop_status = 0; } int uloop_init(void); -void uloop_run(void); +int uloop_run(void); void uloop_done(void); #endif