From nobody Tue Feb 10 16:22:35 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1611937060; cv=none; d=zohomail.com; s=zohoarc; b=bic9jk+UfJM44TL4PSKzDXdxoiCcwzvR/Ml+8SP16/AytoRO+W3WUI6XpMPKRzhmUMqQRwhpdHZAzzNZxgAMscZgf1Eq+9mXcVVMqdDuUBvv2B0U/T0Ma0TTIrxKcYMa7RuGogCvgDVDBvcFcz6frJIrZ+OL8Kcxo9XzZaazFoQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1611937060; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=zwZWe81T+/9T9WV2Kl4DKTCRYWs3sbf/ffjvuSy7l1M=; b=C0QFr++eSPginU13mY/CleA6f6cuG5Y1MuvBjNWTUqlkRV9o91L1ks4sUvc3iqREn1T0X9oOtSgLhUGKDnj5WGhYg0yb3bT+z/2N5Q0pBJAeqPl9MFqYeMrSt+jezNRB1Sbw+vbHlK17JaPqF2dAOYG1YOpVja8+yDjcecC+Gww= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1611937060062858.1704575641133; Fri, 29 Jan 2021 08:17:40 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-100-F37YWeLwNTWy6uopj_1cOQ-1; Fri, 29 Jan 2021 11:17:36 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7254C8144ED; Fri, 29 Jan 2021 16:17:28 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4BE9E62693; Fri, 29 Jan 2021 16:17:28 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id B5B3350049; Fri, 29 Jan 2021 16:17:27 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 10TGHOBt010657 for ; Fri, 29 Jan 2021 11:17:24 -0500 Received: by smtp.corp.redhat.com (Postfix) id 0E74160C5E; Fri, 29 Jan 2021 16:17:24 +0000 (UTC) Received: from work.redhat.com (ovpn-113-143.ams2.redhat.com [10.36.113.143]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4D79B60871; Fri, 29 Jan 2021 16:17:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611937059; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=zwZWe81T+/9T9WV2Kl4DKTCRYWs3sbf/ffjvuSy7l1M=; b=AH6ha25CfhIRPqCnL21PtAIe+Hta5tP5jCxyA0Y2qvfBYztlS0C5jQQWDKhCInmAxmitnb tNI+bLk66TzBHJBD9MFc/TsKlokKnj3BLcylZrFZZr3TFOX0x8jLWLHrvE+kmSBAElRWNk VJ9bSPmlyimoQGnzezhfHPxsjdczYrA= X-MC-Unique: F37YWeLwNTWy6uopj_1cOQ-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH 13/19] commandhelper: Factor out printInput Date: Fri, 29 Jan 2021 17:16:23 +0100 Message-Id: <20210129161629.604823-14-twiederh@redhat.com> In-Reply-To: <20210129161629.604823-1-twiederh@redhat.com> References: <20210129161629.604823-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: Tim Wiederhake X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Signed-off-by: Tim Wiederhake --- tests/commandhelper.c | 65 ++++++++++++++++++++++++++----------------- 1 file changed, 39 insertions(+), 26 deletions(-) diff --git a/tests/commandhelper.c b/tests/commandhelper.c index 929de7a05d..d501e33e88 100644 --- a/tests/commandhelper.c +++ b/tests/commandhelper.c @@ -191,39 +191,20 @@ static int printCwd(FILE *log) return 0; } =20 -int main(int argc, char **argv) { - struct Arguments *args =3D parseArguments(argc, argv); - size_t i; - FILE *log =3D fopen(abs_builddir "/commandhelper.log", "w"); - int ret =3D EXIT_FAILURE; +static int printInput(struct Arguments *args) +{ + char buf[1024]; struct pollfd fds[3]; char *buffers[3] =3D {NULL, NULL, NULL}; size_t buflen[3] =3D {0, 0, 0}; - char buf[1024]; + int ret =3D -1; + size_t i; ssize_t got; =20 - if (!log || !args) - goto cleanup; - - printArguments(log, argc, argv); - - if (printEnvironment(log) !=3D 0) - goto cleanup; - - if (printFds(log) !=3D 0) - goto cleanup; - - printDaemonization(log, args); - - if (printCwd(log) !=3D 0) - goto cleanup; - - fprintf(log, "UMASK:%04o\n", umask(0)); - if (args->close_stdin) { if (freopen("/dev/null", "r", stdin) !=3D stdin) goto cleanup; - usleep(100*1000); + usleep(100 * 1000); } =20 fprintf(stdout, "BEGIN STDOUT\n"); @@ -298,11 +279,43 @@ int main(int argc, char **argv) { fprintf(stderr, "END STDERR\n"); fflush(stderr); =20 - ret =3D EXIT_SUCCESS; + ret =3D 0; =20 cleanup: for (i =3D 0; i < G_N_ELEMENTS(buffers); i++) free(buffers[i]); + return ret; +} + +int main(int argc, char **argv) { + struct Arguments *args =3D parseArguments(argc, argv); + FILE *log =3D fopen(abs_builddir "/commandhelper.log", "w"); + int ret =3D EXIT_FAILURE; + + if (!log || !args) + goto cleanup; + + printArguments(log, argc, argv); + + if (printEnvironment(log) !=3D 0) + goto cleanup; + + if (printFds(log) !=3D 0) + goto cleanup; + + printDaemonization(log, args); + + if (printCwd(log) !=3D 0) + goto cleanup; + + fprintf(log, "UMASK:%04o\n", umask(0)); + + if (printInput(args) !=3D 0) + goto cleanup; + + ret =3D EXIT_SUCCESS; + + cleanup: if (args) free(args); if (log) --=20 2.26.2