From patchwork Tue Feb 13 15:59:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Crispin X-Patchwork-Id: 872946 X-Patchwork-Delegate: blogic@openwrt.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=lede-dev-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="J1w1DuxM"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3zgnLs3Mjgz9sNr for ; Wed, 14 Feb 2018 03:00:35 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Subject:Message-Id: Date:To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=eldKhvWsqwmBKTpGus2DwgYToxFcRe/2VUmPeAr4G8w=; b=J1w1DuxMApHOe3 n20MefL4Q96tKaEbvm/WWuB8JZijY5guQjVW5EnLdVZhAp10G1V61Vwb4vpL09AXYhuIRa86dXsOR 1VFh1/VG7NjWWa0XBxDOuZgCKb9iPF4i3z+hvhbm3PFZVLpTVi5gsytfG7rYz3sRX9LB82Sic2WML 8oq5CKhcFdVjSQ2ooQPNl6dnR+NmyqBYLRCUH4pnafgYdT+VBJYixMXHQCI15tCZgiLQM0B0O0seg D5ImrN4Hat5QlXZnszhGos6Q861bIiJpOdo2CtdaYu+OMWP49Tq6x8ve7rIhj2kmRVfIHs15vZmFA 1bgJrRFBBIzh3Cs97Ucg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1eld0P-0004UW-S1; Tue, 13 Feb 2018 16:00:29 +0000 Received: from nbd.name ([2a01:4f8:221:3d45::2]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1eld09-00033G-Qn for lede-dev@lists.infradead.org; Tue, 13 Feb 2018 16:00:21 +0000 From: John Crispin To: jakub.horak@braiins.cz, lede-dev@lists.infradead.org Date: Tue, 13 Feb 2018 16:59:52 +0100 Message-Id: <20180213155952.23795-1-john@phrozen.org> X-Mailer: git-send-email 2.11.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180213_080014_271857_DBE9F4AC X-CRM114-Status: UNSURE ( 7.34 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -1.9 (-) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (-1.9 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Subject: [LEDE-DEV] [PATCH] procd: fix ustream deadlock when there are 0 bytes or no newlines X-BeenThere: lede-dev@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: John Crispin MIME-Version: 1.0 Sender: "Lede-dev" Errors-To: lede-dev-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Signed-off-by: John Crispin --- service/instance.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/service/instance.c b/service/instance.c index 917b003..27e35b1 100644 --- a/service/instance.c +++ b/service/instance.c @@ -469,18 +469,20 @@ instance_stdio(struct ustream *s, int prio, struct service_instance *in) ulog_open(ULOG_SYSLOG, LOG_DAEMON, ident); do { - str = ustream_get_read_buf(s, NULL); + str = ustream_get_read_buf(s, &len); if (!str) break; - newline = strchr(str, '\n'); - if (!newline) + newline = memchr(str, '\n', len); + if (!newline && (s->r.buffer_len != len)) break; - *newline = 0; + if (newline) { + *newline = 0; + len = newline + 1 - str; + } ulog(prio, "%s\n", str); - len = newline + 1 - str; ustream_consume(s, len); } while (1);