From patchwork Tue Jul 24 22:15:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geoff Levand X-Patchwork-Id: 948889 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41Zt6P1MRnz9s2g for ; Wed, 25 Jul 2018 08:18:21 +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="SdgFildP"; 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 41Zt6N6vDhzDrS7 for ; Wed, 25 Jul 2018 08:18:20 +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="SdgFildP"; 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="SdgFildP"; 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 41Zt3P5BXHzDrHF for ; Wed, 25 Jul 2018 08:15:45 +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=VElIBwWOSTCJJcOuFo6PbtF7j621s3LRK1FDDw6d9h8=; b=SdgFildPdL447xc6QRxrc7MX5 HVpcBRmk94U0l8OAk6C4mSaIQ9CGuBHtPL4MLEMycb38HDx83oLZBLDxg+ynjB3Ergq/gqezXHqzT LENo26+hWoVLj+/Esm2btTNWjFI445QXvkjpiILc6tzUzH/o5PUG1+O8e61A13DHDWEqmv+VUlQpA 0RNwwoAlVI1C7SFnIqndx/YseYwOaZHdJpvrChscdwAr3z0em9iVoCz5hfEsW1BZuI/6pGqHmZ5s/ s49u92u125MWwgRRN/rsEHs4hkEsVANDVZUHPN8bm7D52UZVMe+ooeGekIAKPIOAkRgJLCJtjJ1UV 2TCTA/CSA==; Received: from geoff by merlin.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1fi5an-0004je-8z; Tue, 24 Jul 2018 22:15:41 +0000 Message-Id: In-Reply-To: References: From: Geoff Levand Patch-Date: Tue, 24 Jul 2018 15:03:16 -0700 Subject: [PATCH v1 12/30] lib/process: Cleanup stdout callback To: Samuel Mendoza-Jonas Date: Tue, 24 Jul 2018 22:15:41 +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 c5b5778..68149cb 100644 --- a/discover/paths.c +++ b/discover/paths.c @@ -154,7 +154,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 */