From patchwork Mon Jan 26 20:12:02 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= X-Patchwork-Id: 433027 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from arrakis.dune.hu (arrakis.dune.hu [78.24.191.176]) (using TLSv1.1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 5DD4F1400B7 for ; Tue, 27 Jan 2015 07:12:26 +1100 (AEDT) Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id A40CA289C94; Mon, 26 Jan 2015 21:09:54 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on arrakis.dune.hu X-Spam-Level: X-Spam-Status: No, score=-1.2 required=5.0 tests=BAYES_00, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, T_DKIM_INVALID autolearn=no version=3.3.2 Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id 43329289C94 for ; Mon, 26 Jan 2015 21:09:48 +0100 (CET) X-policyd-weight: using cached result; rate: -8.5 Received: from mail-wg0-f51.google.com (mail-wg0-f51.google.com [74.125.82.51]) by arrakis.dune.hu (Postfix) with ESMTPS for ; Mon, 26 Jan 2015 21:09:48 +0100 (CET) Received: by mail-wg0-f51.google.com with SMTP id k14so11040404wgh.10 for ; Mon, 26 Jan 2015 12:12:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; bh=XqSsAkZ1kI35ogAzbjMB2bUgF0BlCQh5/ca8kcWSMrE=; b=qo5bYvGSKOC2ZfcdhWzj8nLVuTu05dDMnAORHmvnZo8IszgF7ct671gFzasjJR4IeU +DpKivMaFtM0YTqOextdu10EnSGD8TXCMD+rZe5VyWgdtrAidJx69GlckEG8dPp/oRvg GwwU1JSrlHazAzOIzLlt5GTxzayW1RfEw8u5NKFqIro8IFTV2pFfpXT9fZJleL1yd6Tg 8QFX6znObs8nFTngtTx56RlZxJG/GvjNGt8JK4zHSIyRF78BBuORtkW7k9Yeq4qz+Mu7 HhDx0cSfr2abzf9zOFO3bJeEHE9JZyx2YqY9Zh9qByTogZ+Nr9YyeG4C59SD+aVe9MRk 6Tpg== X-Received: by 10.180.72.199 with SMTP id f7mr36026807wiv.58.1422303132716; Mon, 26 Jan 2015 12:12:12 -0800 (PST) Received: from linux-tdhb.lan (ip-194-187-74-233.konfederacka.maverick.com.pl. [194.187.74.233]) by mx.google.com with ESMTPSA id cm7sm15293609wib.6.2015.01.26.12.12.11 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 26 Jan 2015 12:12:11 -0800 (PST) From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= To: Felix Fietkau , John Crispin Date: Mon, 26 Jan 2015 21:12:02 +0100 Message-Id: <1422303122-18312-1-git-send-email-zajec5@gmail.com> X-Mailer: git-send-email 1.8.4.5 In-Reply-To: <1422267933-5240-1-git-send-email-zajec5@gmail.com> References: <1422267933-5240-1-git-send-email-zajec5@gmail.com> MIME-Version: 1.0 Cc: openwrt-devel@lists.openwrt.org Subject: [OpenWrt-Devel] [PATCH V2 libubox] uloop: ignore SIGPIPE by default X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: openwrt-devel-bounces@lists.openwrt.org Sender: "openwrt-devel" Most app don't want to crash because of unhandled SIGPIPE. It could happen is such trivial situations like writing to socket. Signed-off-by: Rafał Miłecki --- V2: Replace signal call with sigaction --- uloop.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/uloop.c b/uloop.c index 9a77ce4..baaef8d 100644 --- a/uloop.c +++ b/uloop.c @@ -582,6 +582,27 @@ static void uloop_install_handler(int signum, void (*handler)(int), struct sigac sigaction(signum, act, NULL); } +static void uloop_ignore_signal(int signum, bool ignore) +{ + struct sigaction s; + + sigaction(signum, NULL, &s); + + if (ignore) { + if (s.sa_handler == SIG_DFL) { /* Ignore only if there isn't any custom handler */ + s.sa_handler = SIG_IGN; + s.sa_flags = 0; + sigaction(signum, &s, NULL); + } + } else { + if (s.sa_handler == SIG_IGN) { /* Restore only if noone modified our SIG_IGN */ + s.sa_handler = SIG_DFL; + s.sa_flags = 0; + sigaction(signum, &s, NULL); + } + } +} + static void uloop_setup_signals(bool add) { static struct sigaction old_sigint, old_sigchld, old_sigterm; @@ -589,6 +610,8 @@ static void uloop_setup_signals(bool add) uloop_install_handler(SIGINT, uloop_handle_sigint, &old_sigint, add); uloop_install_handler(SIGTERM, uloop_handle_sigint, &old_sigterm, add); uloop_install_handler(SIGCHLD, uloop_sigchld, &old_sigchld, add); + + uloop_ignore_signal(SIGPIPE, add); } static int uloop_get_next_timeout(struct timeval *tv)