From patchwork Thu Aug 2 17:29:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geoff Levand X-Patchwork-Id: 952911 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41hHKC4xwQz9s2g for ; Fri, 3 Aug 2018 03:31:27 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="PlvLOkXg"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 41hHKC3THJzF2DN for ; Fri, 3 Aug 2018 03:31:27 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="PlvLOkXg"; dkim-atps=neutral X-Original-To: Petitboot@lists.ozlabs.org Delivered-To: Petitboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (mailfrom) smtp.mailfrom=infradead.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.infradead.org; envelope-from=geoff@infradead.org; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="PlvLOkXg"; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 41hHH74zhczF2D4 for ; Fri, 3 Aug 2018 03:29:39 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=Date:Cc:To:Subject:From:References: In-Reply-To:Message-Id:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=aqBzsM/xa9xn9TGIuw10hac4EqrhkGbteLU3RuzLpHk=; b=PlvLOkXgyybmH0AQunhsha9An LAsXU0Xs/20v3+M+l3Haj1g5Uo/hZXd9qtkyYZ3ZCo5mAd2Q+Za2+Ob5NoRiKpgGDFvv0Lk1S5lM7 gE1vxgu3Z+aVSx3JB2GHT7EiFcvyv3jKTBcphzccrffn2BZMnLAfwLVRlKge34cYWtbjh+9rQxXNG BuGudLnzVlGZCLO+/ekAHqF7u27OD9mCYphkho3ye1BiG03e73VrWmSnaMdX49n5A4NVi4EH+EUUO mQE86FYYosCy8HzwY6JHN1F/O2cLA1XkTikQooZudbS7AdpKtpeM2Bzicn6IrtW1TqmROrFdvmeT1 wN7X3obOA==; Received: from geoff by merlin.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1flHPr-0007Xj-LI; Thu, 02 Aug 2018 17:29:35 +0000 Message-Id: In-Reply-To: References: From: Geoff Levand Patch-Date: Thu, 2 Aug 2018 10:19:53 -0700 Subject: [PATCH v2 12/30] lib/process: Cleanup stdout callback To: Samuel Mendoza-Jonas Date: Thu, 02 Aug 2018 17:29:35 +0000 X-BeenThere: petitboot@lists.ozlabs.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: Petitboot bootloader development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ge Song , Petitboot@lists.ozlabs.org MIME-Version: 1.0 Errors-To: petitboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Petitboot" General cleanup of async stdout processing. The process_stdout_cb and process_stdout_custom routines were doing the same thing, so rename process_stdout_custom to process_process_stdout and make process_stdout_cb a wrapper that calls process_process_stdout. Signed-off-by: Geoff Levand --- discover/paths.c | 2 +- lib/process/process.c | 32 ++++++++------------------------ lib/process/process.h | 2 +- 3 files changed, 10 insertions(+), 26 deletions(-) diff --git a/discover/paths.c b/discover/paths.c index 174bdae..dc654bd 100644 --- a/discover/paths.c +++ b/discover/paths.c @@ -158,7 +158,7 @@ static int busybox_progress_cb(void *arg) p = procinfo_get_process(procinfo); handler = p->stdout_data; - rc = process_stdout_custom(procinfo, &line); + rc = process_process_stdout(procinfo, &line); if (rc) { /* Unregister ourselves from progress tracking */ diff --git a/lib/process/process.c b/lib/process/process.c index 1fa0bb0..bc392dc 100644 --- a/lib/process/process.c +++ b/lib/process/process.c @@ -178,28 +178,7 @@ static int process_read_stdout(struct process_info *procinfo) return rc < 0 ? rc : 0; } -static int process_stdout_cb(void *arg) -{ - struct process_info *procinfo = arg; - int rc; - - rc = process_read_stdout_once(procinfo, NULL); - - /* if we're going to signal to the waitset that we're done (ie, non-zero - * return value), then the waiters will remove us, so we drop the - * reference */ - if (rc < 0) { - talloc_unlink(procset, procinfo); - procinfo->stdout_waiter = NULL; - rc = -1; - } else { - rc = 0; - } - - return rc; -} - -int process_stdout_custom(struct process_info *procinfo, char **line) +int process_process_stdout(struct process_info *procinfo, char **line) { int rc; @@ -417,10 +396,14 @@ int process_run_sync(struct process *process) return 0; } +static int process_stdout_cb(struct process_info *procinfo) +{ + return process_process_stdout(procinfo, NULL); +} + int process_run_async(struct process *process) { struct process_info *procinfo = get_info(process); - waiter_cb stdout_cb; int rc; rc = process_run_common(procinfo); @@ -428,7 +411,8 @@ int process_run_async(struct process *process) return rc; if (process->keep_stdout) { - stdout_cb = process->stdout_cb ?: process_stdout_cb; + waiter_cb stdout_cb = process->stdout_cb ?: + (waiter_cb)process_stdout_cb; procinfo->stdout_waiter = waiter_register_io(procset->waitset, procinfo->stdout_pipe[0], WAIT_IN, stdout_cb, procinfo); diff --git a/lib/process/process.h b/lib/process/process.h index 4904ffc..003ff8e 100644 --- a/lib/process/process.h +++ b/lib/process/process.h @@ -87,6 +87,6 @@ bool process_exit_ok(struct process *process); /* Functions to assist callers using a custom stdout callback */ struct process *procinfo_get_process(struct process_info *procinfo); -int process_stdout_custom(struct process_info *procinfo, char **line); +int process_process_stdout(struct process_info *procinfo, char **line); #endif /* PROCESS_H */