From nobody Mon Feb 9 01:47:53 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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 170.10.133.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=1669801710; cv=none; d=zohomail.com; s=zohoarc; b=DWSIIWTYDC/UTieg9ShJtEnn5s1Zll8cJ0VsbFAfdqP7ZoxtyXl9FLOLoMkJ2OyVtaun3zNJOkPG3sIHasqmiJUyCK92eE5Z+W1c8U1KzPHuCF2n8H3F6tyNiTkwjYSVg+s6+iNjIz0ROvUthndTYBcXg9kdV/J7y4Z56J8uOZM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1669801710; h=Content-Type:Content-Transfer-Encoding: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=jIMjpJshCdyxIPTReIsxydCqH83QcRdVi7ULA7aVpTo=; b=ZiUa4R1lYhrFWiIA1UwX9mYYwA2wUo/MYkjWJ2Apc6MRwRS1QyKxKhp9LCtOmGfecKN6IAFaMghOJLNyvHMf3Xm4SheWYmT/q+ORZBw0W25j0QhR52PWo+iqPecIzvz5Znw0tAVd+y8cLFNIf2RNqvZivvWyJ1/h9ykINQzESK4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1669801710376121.87369199928378; Wed, 30 Nov 2022 01:48:30 -0800 (PST) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-580-X9t4_p4ANKqKof65VNqFQw-1; Wed, 30 Nov 2022 04:48:21 -0500 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 52DFD381079B; Wed, 30 Nov 2022 09:48:18 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3F55D4B3FCE; Wed, 30 Nov 2022 09:48:18 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 2D41F19465A2; Wed, 30 Nov 2022 09:48:18 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 3D5BE19465A0 for ; Wed, 30 Nov 2022 09:48:16 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 2F6324B3FC8; Wed, 30 Nov 2022 09:48:16 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.39]) by smtp.corp.redhat.com (Postfix) with ESMTP id C7D134B3FDF for ; Wed, 30 Nov 2022 09:48:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669801709; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to: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=jIMjpJshCdyxIPTReIsxydCqH83QcRdVi7ULA7aVpTo=; b=gL2teZLXrf7gQzjBLQT8pWj5rZm3G/0X68GYw0CbG5QBQaXfSqckBhQRNzhy0HEuvHrvwq nQGEuibTtsehKDry/PDXB3Atq3H53G7jAWSmcKkvwvrhgOb51PqH4VB/yHuKVvK24tEO43 mv1oP14kTLfYj72XBLU0wxt9cUAm97o= X-MC-Unique: X9t4_p4ANKqKof65VNqFQw-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 5/9] commandtest: Test virCommandSetSendBuffer() with virCommandDoAsyncIO() Date: Wed, 30 Nov 2022 10:48:07 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1669801710797100003 Content-Type: text/plain; charset="utf-8"; x-default="true" Introduce a test case which ensures that a daemonized process can work with virCommandSetSendBuffer() when async IO is enabled. Signed-off-by: Michal Privoznik --- tests/commanddata/test29.log | 20 ++++++++ tests/commandtest.c | 97 ++++++++++++++++++++++++++++++++++++ 2 files changed, 117 insertions(+) create mode 100644 tests/commanddata/test29.log diff --git a/tests/commanddata/test29.log b/tests/commanddata/test29.log new file mode 100644 index 0000000000..962f8526f1 --- /dev/null +++ b/tests/commanddata/test29.log @@ -0,0 +1,20 @@ +ARG:--close-stdin +ARG:--check-daemonize +ARG:--readfd +ARG:3 +ENV:DISPLAY=3D:0.0 +ENV:HOME=3D/home/test +ENV:HOSTNAME=3Dtest +ENV:LANG=3DC +ENV:LOGNAME=3Dtest +ENV:PATH=3D/usr/bin:/bin +ENV:TMPDIR=3D/tmp +ENV:USER=3Dtest +FD:0 +FD:1 +FD:2 +FD:3 +FD:6 +DAEMON:yes +CWD:/ +UMASK:0022 diff --git a/tests/commandtest.c b/tests/commandtest.c index 8c5a9245a1..6d45ff196f 100644 --- a/tests/commandtest.c +++ b/tests/commandtest.c @@ -25,6 +25,7 @@ #include #ifndef WIN32 # include +# include #endif #include =20 @@ -1155,6 +1156,101 @@ test28(const void *unused G_GNUC_UNUSED) } =20 =20 +static int +test29(const void *unused G_GNUC_UNUSED) +{ + g_autoptr(virCommand) cmd =3D virCommandNew(abs_builddir "/commandhelp= er"); + g_autofree char *pidfile =3D virPidFileBuildPath(abs_builddir, "comman= dhelper"); + pid_t pid; + int buffd; + VIR_AUTOCLOSE outfd =3D -1; + size_t buflen =3D 1024 * 10; + g_autofree unsigned char *buffer =3D NULL; + g_autofree char *outactual =3D NULL; + g_autofree char *outexpect =3D NULL; + size_t i; + size_t outactuallen =3D 0; + int ret =3D -1; + + if (!pidfile) + return -1; + + buffer =3D g_new0(unsigned char, buflen + 1); + for (i =3D 0; i < buflen; i++) { + buffer[i] =3D 'a' + i % ('z' - 'a' + 1); + } + buffer[buflen] =3D '\0'; + + outexpect =3D g_strdup_printf("BEGIN STDOUT\n%sEND STDOUT\n", buffer); + + buffd =3D virCommandSetSendBuffer(cmd, &buffer, buflen); + + virCommandAddArg(cmd, "--close-stdin"); + virCommandAddArg(cmd, "--check-daemonize"); + virCommandAddArg(cmd, "--readfd"); + virCommandAddArgFormat(cmd, "%d", buffd); + + virCommandSetOutputFD(cmd, &outfd); + virCommandSetPidFile(cmd, pidfile); + virCommandDaemonize(cmd); + virCommandDoAsyncIO(cmd); + + if (virCommandRun(cmd, NULL) < 0) { + fprintf(stderr, "Cannot run child %s\n", virGetLastErrorMessage()); + goto cleanup; + } + + if (virPidFileReadPath(pidfile, &pid) < 0) { + fprintf(stderr, "cannot read pidfile: %s\n", pidfile); + goto cleanup; + } + + while (1) { + char buf[1024] =3D { 0 }; + struct pollfd pfd =3D {.fd =3D outfd, .events =3D POLLIN, .revents= =3D 0}; + int rc =3D 0; + + rc =3D poll(&pfd, 1, 1000); + if (rc < 0) { + if (errno =3D=3D EINTR) + continue; + + fprintf(stderr, "poll() returned errno =3D %d\n", errno); + goto cleanup; + } + + if (pfd.revents & POLLIN) { + rc =3D read(outfd, buf, sizeof(buf)); + if (rc < 0) { + fprintf(stderr, "cannot read from output pipe: errno=3D%d\= n", errno); + goto cleanup; + } + + outactual =3D g_renew(char, outactual, outactuallen + rc + 1); + memcpy(outactual + outactuallen, buf, rc); + outactuallen +=3D rc; + outactual[outactuallen] =3D '\0'; + } else if (pfd.revents & POLLERR || + pfd.revents & POLLHUP) { + break; + } + } + + if (STRNEQ_NULLABLE(outactual, outexpect)) { + virTestDifference(stderr, outexpect, outactual); + goto cleanup; + } + + ret =3D checkoutput("test29"); + + cleanup: + if (pidfile) + unlink(pidfile); + + return ret; +} + + static int mymain(void) { @@ -1252,6 +1348,7 @@ mymain(void) DO_TEST(test26); DO_TEST(test27); DO_TEST(test28); + DO_TEST(test29); =20 return ret =3D=3D 0 ? EXIT_SUCCESS : EXIT_FAILURE; } --=20 2.37.4