From nobody Tue Apr 30 12:59:09 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.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 216.205.24.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=1614701550; cv=none; d=zohomail.com; s=zohoarc; b=Ofd36H3B3hKckhwfTA7ROzERLd3ZiGZcSIpyUtQvHBUPLWPNLnHxXLgzCvun0jiqYSHT2P/lnSFYqrrZGHlAllSvVYTFZnFT48XzwXYetdzwtQJLDJqa6ggdoC7RjBXj0ywgFX6eaR+M6rWJ195jSd7T9hSgsmaiORZM1gKGMAM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1614701550; 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=WJH6ovONzVBibInWGXoXBSCpvN8LjiGZn+D/F6k/ack=; b=e/NVVlSAPAy9yheTSjIx9SimKEaxGhO20vnPoj76YW8Dr4tl/ZxIpKwbckvMHIEH7sUrg6xnJ85aE8qbM7NwfXEwP7R1cPODFN8eb4J1W51q93dzZHySJDD6pWkWwevre7LfmklK+m0UUrJxvZteW4cdTuRBNiQHZSzEkFF4wLs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.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 [216.205.24.124]) by mx.zohomail.com with SMTPS id 1614701550642207.82124214729072; Tue, 2 Mar 2021 08:12:30 -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-603-lx58TDM1MiWYfZ3TvF2llg-1; Tue, 02 Mar 2021 11:12:26 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id F2EF5107ACE6; Tue, 2 Mar 2021 16:12:20 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5883960C47; Tue, 2 Mar 2021 16:12:20 +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 4F69C18095C9; Tue, 2 Mar 2021 16:12:18 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 122GCGX2023990 for ; Tue, 2 Mar 2021 11:12:16 -0500 Received: by smtp.corp.redhat.com (Postfix) id 8665B60C05; Tue, 2 Mar 2021 16:12:16 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id E450960BFA for ; Tue, 2 Mar 2021 16:12:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614701549; 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=WJH6ovONzVBibInWGXoXBSCpvN8LjiGZn+D/F6k/ack=; b=cqD0WDSmFmumxVndIOO2TtDT2e7YwbTvMuFxW+0CY5j9Js5QiTNbJwI9ASccq551iBKsST d3mT8FHzpy5CEOeaaWiLVcWedWVJAVARwKgnNFNypYt4rFmYerXDVFoc5f/AsfYRXSGyP9 39ubiCgFdPbTwRx8qUWmY7G2Ci408C4= X-MC-Unique: lx58TDM1MiWYfZ3TvF2llg-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 1/6] virPipeImpl: Don't overwrite error Date: Tue, 2 Mar 2021 17:12:03 +0100 Message-Id: <6a4db99dc941e7b4e522227564e037a271e990f3.1614701477.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com 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.12 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" If WITH_PIPE2 is not defined we attempt to set the pipe to nonblocking operation after they are created. We errorneously rewrote the existing error message on failure to do so or even reported an error if quiet mode was requested. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/util/virutil.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/util/virutil.c b/src/util/virutil.c index a0cd0f1bcd..0f3cf98613 100644 --- a/src/util/virutil.c +++ b/src/util/virutil.c @@ -1924,8 +1924,6 @@ virPipeImpl(int fds[2], bool nonblock, bool errreport) if (errreport) virReportSystemError(errno, "%s", _("Unable to set pipes to non-blockin= g")); - virReportSystemError(errno, "%s", - _("Unable to create pipes")); VIR_FORCE_CLOSE(fds[0]); VIR_FORCE_CLOSE(fds[1]); return -1; --=20 2.29.2 From nobody Tue Apr 30 12:59:09 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.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 216.205.24.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=1614701564; cv=none; d=zohomail.com; s=zohoarc; b=JqQnf+c2tTGP+3pjIlsCa3TOmrVv8Zu0FxokrTbM/CXvWPLbbqI6TpVgNniIvJ9EGTOs7f9MqFR0lFO04/SfYYJmFHrS+2aXm4papkWjRfbbCx/mSp/XDqf8Dkl3L4nVrQeA0dZw/9LnecSbYNQDqPL+bpj+uy0HQMxG3h2l2V4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1614701564; 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=rQiyqTFU8H8Qx8G5fr7JZ5jK1JDfnY46pdJs4o1cBNw=; b=J7gPRyuhakoFtUFQcGuDovZGfQwy1/5rL1oY3TzTYAUk5b+1XTPrsyNh8iB/aIDSjAEsXdA26+z63lYiObXShJKlr6iEPH5HdrK4O5R8t13XJBe105OLfiWptQGbUUfcnlkmXp4Y26QduWAb4wmYE+FfWFsf0bu8R2ttJAqp5vk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.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 [216.205.24.124]) by mx.zohomail.com with SMTPS id 1614701564226560.1709564318832; Tue, 2 Mar 2021 08:12:44 -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-315-bhspl4s6MBWMoZoHemPO6g-1; Tue, 02 Mar 2021 11:12:40 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B67A1801985; Tue, 2 Mar 2021 16:12:33 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 915DE60BFA; Tue, 2 Mar 2021 16:12:33 +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 4A8ED18095CE; Tue, 2 Mar 2021 16:12:33 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 122GCJUk024002 for ; Tue, 2 Mar 2021 11:12:19 -0500 Received: by smtp.corp.redhat.com (Postfix) id D0CFD60C43; Tue, 2 Mar 2021 16:12:19 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2BB0260C05 for ; Tue, 2 Mar 2021 16:12:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614701563; 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=rQiyqTFU8H8Qx8G5fr7JZ5jK1JDfnY46pdJs4o1cBNw=; b=WhrNxzpeGKStc7W7DVU6hT8/YH69qUp6/nv39vEAQHpwN0NLhNe3J7ncTXQN1VHDlq6cwr ZA6bBsRTRdvesq0YdB2wASazSgBE0oWGtYriUb8Cxs2uVXk6iGP4MP9YTAQKQl3a7gOuCi Zuz1hezVw9ZjbB0ueX+6aS0rihQQyXE= X-MC-Unique: bhspl4s6MBWMoZoHemPO6g-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 2/6] virCommandAddEnvBuffer: Remove unused function Date: Tue, 2 Mar 2021 17:12:04 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com 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.12 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: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/libvirt_private.syms | 1 - src/util/vircommand.c | 26 -------------------------- src/util/vircommand.h | 3 --- 3 files changed, 30 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 2a3bbdc577..90c02a250c 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1965,7 +1965,6 @@ virCommandAddArgFormat; virCommandAddArgList; virCommandAddArgPair; virCommandAddArgSet; -virCommandAddEnvBuffer; virCommandAddEnvFormat; virCommandAddEnvPair; virCommandAddEnvPass; diff --git a/src/util/vircommand.c b/src/util/vircommand.c index 1a4b77ea24..28a903e117 100644 --- a/src/util/vircommand.c +++ b/src/util/vircommand.c @@ -1409,32 +1409,6 @@ virCommandAddEnvString(virCommandPtr cmd, const char= *str) } -/** - * virCommandAddEnvBuffer: - * @cmd: the command to modify - * @buf: buffer that contains name=3Dvalue string, which will be reset on = return - * - * Convert a buffer containing preformatted name=3Dvalue into an - * environment variable of the child. - * Correctly transfers memory errors or contents from buf to cmd. - */ -void -virCommandAddEnvBuffer(virCommandPtr cmd, virBufferPtr buf) -{ - if (!cmd || cmd->has_error) { - virBufferFreeAndReset(buf); - return; - } - - if (!virBufferUse(buf)) { - cmd->has_error =3D EINVAL; - return; - } - - virCommandAddEnv(cmd, virBufferContentAndReset(buf)); -} - - /** * virCommandAddEnvPass: * @cmd: the command to modify diff --git a/src/util/vircommand.h b/src/util/vircommand.h index 0ea6c8229f..9fb625ec4b 100644 --- a/src/util/vircommand.h +++ b/src/util/vircommand.h @@ -109,9 +109,6 @@ void virCommandAddEnvPair(virCommandPtr cmd, void virCommandAddEnvString(virCommandPtr cmd, const char *str) ATTRIBUTE_NONNULL(2); -void virCommandAddEnvBuffer(virCommandPtr cmd, - virBufferPtr buf); - void virCommandAddEnvPass(virCommandPtr cmd, const char *name) ATTRIBUTE_NONNULL(2); --=20 2.29.2 From nobody Tue Apr 30 12:59:09 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.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 216.205.24.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=1614701564; cv=none; d=zohomail.com; s=zohoarc; b=WR/h1DbLp/Gvdn+Jhg4tWDfwy1F9E6EDyHZeFvhjaWTd4fWqmtcza1mF6DOtWEusLga84Rl5e4kRamMmq28cY4+4Ngt6j+2WHmFAJJoGKPHK4O55ZGCULoe371ndCBVxFlgB9vLT6QW0/mn4H9PFsRXJG3Xk+I2fHfoQcSru3sk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1614701564; 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=noA6Fz/w/lbRduRmn8xdA9jsLR8w06o7/dpahogD/qk=; b=FG6tFxgPt4fBIm0Hp4Qm5RjLdU6vr4PbSRb4amhjOZO9iSx473osoQZo1UbLzve+tgYKa43HP0zDjZlta9rMbHUNu/MBldzXnd5rEv5zzgPS3PGwkLYMbySOrCj/FXiFHoPlumRO4tK1AQWd+/se/JDM7xnU2EPUDqhEjyAEYqw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.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 [216.205.24.124]) by mx.zohomail.com with SMTPS id 1614701564829219.53503218505932; Tue, 2 Mar 2021 08:12:44 -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-21-etxoxM1_PLimyF40Jmy6Iw-1; Tue, 02 Mar 2021 11:12:41 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E163A801981; Tue, 2 Mar 2021 16:12:34 +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 A49C719D6C; Tue, 2 Mar 2021 16:12:34 +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 67FCC58074; Tue, 2 Mar 2021 16:12:34 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 122GCLU1024012 for ; Tue, 2 Mar 2021 11:12:21 -0500 Received: by smtp.corp.redhat.com (Postfix) id 3700060C47; Tue, 2 Mar 2021 16:12:21 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4C4FF60C05 for ; Tue, 2 Mar 2021 16:12:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614701563; 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=noA6Fz/w/lbRduRmn8xdA9jsLR8w06o7/dpahogD/qk=; b=S6ila17fdy/PdCC3r757ph513A6paiyUTV+IdYpzGt7A3zG+gm41yZN87zxNkPBU3uA4VY VK9OPViSXieRTbJh1u8A94z5eQlGX9jl3qTmyQxeZJsv3F1t0t66McaiFHYTkK5MJkgGYy 5KI26R9oR0BzxW1rJ4YlZOlqVFJCr5E= X-MC-Unique: etxoxM1_PLimyF40Jmy6Iw-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 3/6] util: vircommand: Add wrappers for virCommand error checking Date: Tue, 2 Mar 2021 17:12:05 +0100 Message-Id: <0fb97bb1360e184ba454586469400f8359e099bd.1614701477.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com 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.84 on 10.5.11.23 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" Extract the check and reporting of error from the individual virCommand APIs into a separate helper. This will aid future refactors. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/util/vircommand.c | 143 ++++++++++++++++++++++-------------------- 1 file changed, 76 insertions(+), 67 deletions(-) diff --git a/src/util/vircommand.c b/src/util/vircommand.c index 28a903e117..2f6635671d 100644 --- a/src/util/vircommand.c +++ b/src/util/vircommand.c @@ -161,6 +161,27 @@ static void *dryRunOpaque; static int dryRunStatus; #endif /* !WIN32 */ + +static bool +virCommandHasError(virCommandPtr cmd) +{ + return !cmd || cmd->has_error !=3D 0; +} + + +static int +virCommandRaiseError(virCommandPtr cmd) +{ + if (!cmd || cmd->has_error !=3D 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("invalid use of command API")); + return -1; + } + + return 0; +} + + /* * virCommandFDIsSet: * @cmd: pointer to virCommand @@ -982,7 +1003,7 @@ virCommandNewVAList(const char *binary, va_list list) virCommandPtr cmd =3D virCommandNew(binary); const char *arg; - if (!cmd || cmd->has_error) + if (virCommandHasError(cmd)) return cmd; while ((arg =3D va_arg(list, const char *)) !=3D NULL) @@ -1076,7 +1097,7 @@ virCommandPassFDGetFDIndex(virCommandPtr cmd, int fd) { size_t i =3D 0; - if (!cmd || cmd->has_error) + if (virCommandHasError(cmd)) return -1; while (i < cmd->npassfd) { @@ -1100,7 +1121,7 @@ virCommandPassFDGetFDIndex(virCommandPtr cmd, int fd) void virCommandSetPidFile(virCommandPtr cmd, const char *pidfile) { - if (!cmd || cmd->has_error) + if (virCommandHasError(cmd)) return; VIR_FREE(cmd->pidfile); @@ -1125,7 +1146,7 @@ virCommandGetUID(virCommandPtr cmd) void virCommandSetGID(virCommandPtr cmd, gid_t gid) { - if (!cmd || cmd->has_error) + if (virCommandHasError(cmd)) return; cmd->gid =3D gid; @@ -1134,7 +1155,7 @@ virCommandSetGID(virCommandPtr cmd, gid_t gid) void virCommandSetUID(virCommandPtr cmd, uid_t uid) { - if (!cmd || cmd->has_error) + if (virCommandHasError(cmd)) return; cmd->uid =3D uid; @@ -1143,7 +1164,7 @@ virCommandSetUID(virCommandPtr cmd, uid_t uid) void virCommandSetMaxMemLock(virCommandPtr cmd, unsigned long long bytes) { - if (!cmd || cmd->has_error) + if (virCommandHasError(cmd)) return; cmd->maxMemLock =3D bytes; @@ -1152,7 +1173,7 @@ virCommandSetMaxMemLock(virCommandPtr cmd, unsigned l= ong long bytes) void virCommandSetMaxProcesses(virCommandPtr cmd, unsigned int procs) { - if (!cmd || cmd->has_error) + if (virCommandHasError(cmd)) return; cmd->maxProcesses =3D procs; @@ -1161,7 +1182,7 @@ virCommandSetMaxProcesses(virCommandPtr cmd, unsigned= int procs) void virCommandSetMaxFiles(virCommandPtr cmd, unsigned int files) { - if (!cmd || cmd->has_error) + if (virCommandHasError(cmd)) return; cmd->maxFiles =3D files; @@ -1169,7 +1190,7 @@ virCommandSetMaxFiles(virCommandPtr cmd, unsigned int= files) void virCommandSetMaxCoreSize(virCommandPtr cmd, unsigned long long bytes) { - if (!cmd || cmd->has_error) + if (virCommandHasError(cmd)) return; cmd->maxCore =3D bytes; @@ -1178,7 +1199,7 @@ void virCommandSetMaxCoreSize(virCommandPtr cmd, unsi= gned long long bytes) void virCommandSetUmask(virCommandPtr cmd, int mask) { - if (!cmd || cmd->has_error) + if (virCommandHasError(cmd)) return; cmd->mask =3D mask; @@ -1193,7 +1214,7 @@ void virCommandSetUmask(virCommandPtr cmd, int mask) void virCommandClearCaps(virCommandPtr cmd) { - if (!cmd || cmd->has_error) + if (virCommandHasError(cmd)) return; cmd->flags |=3D VIR_EXEC_CLEAR_CAPS; @@ -1210,7 +1231,7 @@ void virCommandAllowCap(virCommandPtr cmd, int capability) { - if (!cmd || cmd->has_error) + if (virCommandHasError(cmd)) return; cmd->capabilities |=3D (1ULL << capability); @@ -1231,7 +1252,7 @@ void virCommandSetSELinuxLabel(virCommandPtr cmd, const char *label G_GNUC_UNUSED) { - if (!cmd || cmd->has_error) + if (virCommandHasError(cmd)) return; #if defined(WITH_SECDRIVER_SELINUX) @@ -1255,7 +1276,7 @@ void virCommandSetAppArmorProfile(virCommandPtr cmd, const char *profile G_GNUC_UNUSED) { - if (!cmd || cmd->has_error) + if (virCommandHasError(cmd)) return; #if defined(WITH_SECDRIVER_APPARMOR) @@ -1277,7 +1298,7 @@ virCommandSetAppArmorProfile(virCommandPtr cmd, void virCommandDaemonize(virCommandPtr cmd) { - if (!cmd || cmd->has_error) + if (virCommandHasError(cmd)) return; cmd->flags |=3D VIR_EXEC_DAEMON; @@ -1293,7 +1314,7 @@ virCommandDaemonize(virCommandPtr cmd) void virCommandNonblockingFDs(virCommandPtr cmd) { - if (!cmd || cmd->has_error) + if (virCommandHasError(cmd)) return; cmd->flags |=3D VIR_EXEC_NONBLOCK; @@ -1312,7 +1333,7 @@ virCommandNonblockingFDs(virCommandPtr cmd) void virCommandRawStatus(virCommandPtr cmd) { - if (!cmd || cmd->has_error) + if (virCommandHasError(cmd)) return; cmd->rawStatus =3D true; @@ -1361,7 +1382,7 @@ virCommandAddEnvFormat(virCommandPtr cmd, const char = *format, ...) char *env; va_list list; - if (!cmd || cmd->has_error) + if (virCommandHasError(cmd)) return; va_start(list, format); @@ -1400,7 +1421,7 @@ virCommandAddEnvString(virCommandPtr cmd, const char = *str) { char *env; - if (!cmd || cmd->has_error) + if (virCommandHasError(cmd)) return; env =3D g_strdup(str); @@ -1421,7 +1442,7 @@ void virCommandAddEnvPass(virCommandPtr cmd, const char *name) { const char *value; - if (!cmd || cmd->has_error) + if (virCommandHasError(cmd)) return; value =3D getenv(name); @@ -1440,7 +1461,7 @@ virCommandAddEnvPass(virCommandPtr cmd, const char *n= ame) void virCommandAddEnvPassCommon(virCommandPtr cmd) { - if (!cmd || cmd->has_error) + if (virCommandHasError(cmd)) return; ignore_value(VIR_RESIZE_N(cmd->env, cmd->maxenv, cmd->nenv, 9)); @@ -1460,7 +1481,7 @@ virCommandAddEnvPassCommon(virCommandPtr cmd) void virCommandAddEnvXDG(virCommandPtr cmd, const char *baseDir) { - if (!cmd || cmd->has_error) + if (virCommandHasError(cmd)) return; ignore_value(VIR_RESIZE_N(cmd->env, cmd->maxenv, cmd->nenv, 3)); @@ -1484,7 +1505,7 @@ virCommandAddEnvXDG(virCommandPtr cmd, const char *ba= seDir) void virCommandAddArg(virCommandPtr cmd, const char *val) { - if (!cmd || cmd->has_error) + if (virCommandHasError(cmd)) return; if (val =3D=3D NULL) { @@ -1512,7 +1533,7 @@ virCommandAddArgBuffer(virCommandPtr cmd, virBufferPt= r buf) { g_autofree char *str =3D virBufferContentAndReset(buf); - if (!cmd || cmd->has_error) + if (virCommandHasError(cmd)) return; if (!str) @@ -1540,7 +1561,7 @@ virCommandAddArgFormat(virCommandPtr cmd, const char = *format, ...) char *arg; va_list list; - if (!cmd || cmd->has_error) + if (virCommandHasError(cmd)) return; va_start(list, format); @@ -1583,7 +1604,7 @@ virCommandAddArgSet(virCommandPtr cmd, const char *co= nst*vals) { int narg =3D 0; - if (!cmd || cmd->has_error) + if (virCommandHasError(cmd)) return; if (vals[0] =3D=3D NULL) { @@ -1619,7 +1640,7 @@ virCommandAddArgList(virCommandPtr cmd, ...) va_list list; int narg =3D 0; - if (!cmd || cmd->has_error) + if (virCommandHasError(cmd)) return; va_start(list, cmd); @@ -1653,7 +1674,7 @@ virCommandAddArgList(virCommandPtr cmd, ...) void virCommandSetWorkingDirectory(virCommandPtr cmd, const char *pwd) { - if (!cmd || cmd->has_error) + if (virCommandHasError(cmd)) return; if (cmd->pwd) { @@ -1701,7 +1722,7 @@ virCommandSetSendBuffer(virCommandPtr cmd, { size_t i; - if (!cmd || cmd->has_error) + if (virCommandHasError(cmd)) return -1; if (fcntl(fd, F_SETFL, O_NONBLOCK) < 0) { @@ -1795,7 +1816,7 @@ virCommandSendBuffersHandlePoll(virCommandPtr cmd, void virCommandSetInputBuffer(virCommandPtr cmd, const char *inbuf) { - if (!cmd || cmd->has_error) + if (virCommandHasError(cmd)) return; if (cmd->infd !=3D -1 || cmd->inbuf) { @@ -1825,7 +1846,7 @@ void virCommandSetOutputBuffer(virCommandPtr cmd, char **outbuf) { *outbuf =3D NULL; - if (!cmd || cmd->has_error) + if (virCommandHasError(cmd)) return; if (cmd->outfdptr) { @@ -1859,7 +1880,7 @@ void virCommandSetErrorBuffer(virCommandPtr cmd, char **errbuf) { *errbuf =3D NULL; - if (!cmd || cmd->has_error) + if (virCommandHasError(cmd)) return; if (cmd->errfdptr) { @@ -1883,7 +1904,7 @@ virCommandSetErrorBuffer(virCommandPtr cmd, char **er= rbuf) void virCommandSetInputFD(virCommandPtr cmd, int infd) { - if (!cmd || cmd->has_error) + if (virCommandHasError(cmd)) return; if (cmd->infd !=3D -1 || cmd->inbuf) { @@ -1913,7 +1934,7 @@ virCommandSetInputFD(virCommandPtr cmd, int infd) void virCommandSetOutputFD(virCommandPtr cmd, int *outfd) { - if (!cmd || cmd->has_error) + if (virCommandHasError(cmd)) return; if (cmd->outfdptr) { @@ -1939,7 +1960,7 @@ virCommandSetOutputFD(virCommandPtr cmd, int *outfd) void virCommandSetErrorFD(virCommandPtr cmd, int *errfd) { - if (!cmd || cmd->has_error) + if (virCommandHasError(cmd)) return; if (cmd->errfdptr) { @@ -1968,7 +1989,7 @@ virCommandSetErrorFD(virCommandPtr cmd, int *errfd) void virCommandSetPreExecHook(virCommandPtr cmd, virExecHook hook, void *opaque) { - if (!cmd || cmd->has_error) + if (virCommandHasError(cmd)) return; if (cmd->hook) { @@ -1999,7 +2020,7 @@ virCommandWriteArgLog(virCommandPtr cmd, int logfd) /* Any errors will be reported later by virCommandRun, which means * no command will be run, so there is nothing to log. */ - if (!cmd || cmd->has_error) + if (virCommandHasError(cmd)) return; for (i =3D 0; i < cmd->nenv; i++) { @@ -2043,11 +2064,8 @@ virCommandToString(virCommandPtr cmd, bool linebreak= s) /* Cannot assume virCommandRun will be called; so report the error * now. If virCommandRun is called, it will report the same error. */ - if (!cmd || cmd->has_error) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("invalid use of command API")); + if (virCommandRaiseError(cmd) < 0) return NULL; - } for (i =3D 0; i < cmd->nenv; i++) { /* In shell, a=3D'b c' has a different meaning than 'a=3Db c', so @@ -2092,11 +2110,8 @@ virCommandGetArgList(virCommandPtr cmd, { size_t i; - if (cmd->has_error) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("invalid use of command API")); + if (virCommandRaiseError(cmd) < 0) return -1; - } *args =3D g_new0(char *, cmd->nargs); *nargs =3D cmd->nargs - 1; @@ -2279,11 +2294,8 @@ virCommandProcessIO(virCommandPtr cmd) */ int virCommandExec(virCommandPtr cmd, gid_t *groups, int ngroups) { - if (!cmd || cmd->has_error) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("invalid use of command API")); + if (virCommandRaiseError(cmd) < 0) return -1; - } if (virExecCommon(cmd, groups, ngroups) < 0) return -1; @@ -2324,11 +2336,8 @@ virCommandRun(virCommandPtr cmd, int *exitstatus) char *str; int tmpfd; - if (!cmd || cmd->has_error) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("invalid use of command API")); + if (virCommandRaiseError(cmd) < 0) return -1; - } /* Avoid deadlock, by requiring that any open fd not under our * control must be visiting a regular file, or that we are @@ -2471,11 +2480,8 @@ virCommandRunAsync(virCommandPtr cmd, pid_t *pid) bool synchronous =3D false; int infd[2] =3D {-1, -1}; - if (!cmd || cmd->has_error) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("invalid use of command API")); + if (virCommandRaiseError(cmd) < 0) return -1; - } synchronous =3D cmd->flags & VIR_EXEC_RUN_SYNC; cmd->flags &=3D ~VIR_EXEC_RUN_SYNC; @@ -2620,11 +2626,8 @@ virCommandWait(virCommandPtr cmd, int *exitstatus) int ret; int status =3D 0; - if (!cmd || cmd->has_error) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("invalid use of command API")); + if (virCommandRaiseError(cmd) < 0) return -1; - } if (dryRunBuffer || dryRunCallback) { VIR_DEBUG("Dry run requested, returning status %d", @@ -2717,7 +2720,7 @@ virCommandAbort(virCommandPtr cmd) */ void virCommandRequireHandshake(virCommandPtr cmd) { - if (!cmd || cmd->has_error) + if (virCommandHasError(cmd)) return; if (cmd->handshake) { @@ -2760,7 +2763,10 @@ int virCommandHandshakeWait(virCommandPtr cmd) char c; int rv; - if (!cmd || cmd->has_error || !cmd->handshake) { + if (virCommandRaiseError(cmd) < 0) + return -1; + + if (!cmd->handshake) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("invalid use of command API")); return -1; @@ -2818,7 +2824,10 @@ int virCommandHandshakeNotify(virCommandPtr cmd) { char c =3D '1'; - if (!cmd || cmd->has_error || !cmd->handshake) { + if (virCommandRaiseError(cmd) < 0) + return -1; + + if (!cmd->handshake) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("invalid use of command API")); return -1; @@ -2846,7 +2855,7 @@ virCommandSetSendBuffer(virCommandPtr cmd, unsigned char *buffer G_GNUC_UNUSED, size_t buflen G_GNUC_UNUSED) { - if (!cmd || cmd->has_error) + if (virCommandHasError(cmd)) return -1; cmd->has_error =3D ENOTSUP; @@ -2903,7 +2912,7 @@ virCommandAbort(virCommandPtr cmd G_GNUC_UNUSED) void virCommandRequireHandshake(virCommandPtr cmd) { - if (!cmd || cmd->has_error) + if (virCommandHasError(cmd)) return; cmd->has_error =3D ENOSYS; @@ -3030,7 +3039,7 @@ virCommandFree(virCommandPtr cmd) void virCommandDoAsyncIO(virCommandPtr cmd) { - if (!cmd || cmd->has_error) + if (virCommandHasError(cmd)) return; cmd->flags |=3D VIR_EXEC_ASYNC_IO | VIR_EXEC_NONBLOCK; --=20 2.29.2 From nobody Tue Apr 30 12:59:09 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.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 216.205.24.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=1614701553; cv=none; d=zohomail.com; s=zohoarc; b=Qhtx+WeNfD7uzXpRhGJWRAQejuFh/Ehy8613jIgFsmjFEOLs2Dx5/0G2NmGL7KjlS5pz8TtxQV0ZV5/Ca/Q0UNtWPImo5VGRyHLPQjG7cQTst41R9n0+x5TySRkdvoZpsva8GP9nrKS9/e6WwzuJgSUZIzfSzNCp3QjniQa0rcs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1614701553; 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=ae0pzHUZO38q+7bXCMcZ9h1HnU+UaQCbkA+z6Mim2v0=; b=LbwsrPsSbb5LreeDeLgbrOqD9eL52u6GJtwfmDkkDcMPx48WnBgz3PH18pjZjwqPUzzkEhxIgtcAaLwHpsNRfsWWDbsssVctwDZ3gZWqQhCLvE0wlKPCmvb/Df0oifBxsYfvf05wJZM3wBCSdmZ2N2MDYEyGannpAxy4OB8pIXM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.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 [216.205.24.124]) by mx.zohomail.com with SMTPS id 1614701553048764.972251644863; Tue, 2 Mar 2021 08:12:33 -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-271-UHp81Q4_OKOn8F5P3_Idrw-1; Tue, 02 Mar 2021 11:12:29 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 52F36803F47; Tue, 2 Mar 2021 16:12:23 +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 1E1AE5D9F1; Tue, 2 Mar 2021 16:12:23 +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 CEA8A57DFE; Tue, 2 Mar 2021 16:12:22 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 122GCMRd024024 for ; Tue, 2 Mar 2021 11:12:22 -0500 Received: by smtp.corp.redhat.com (Postfix) id 5630260BFA; Tue, 2 Mar 2021 16:12:22 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id A1D8360C05 for ; Tue, 2 Mar 2021 16:12:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614701552; 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=ae0pzHUZO38q+7bXCMcZ9h1HnU+UaQCbkA+z6Mim2v0=; b=BvrZ0FapMNDD4ecptEUlhPRIeRn2mcOMQyKG+KoJ1HcgRnOBy55rrO3mmHrCduJIHEJy9W KzFRaCtiTuwUjIEBLORXejJH2743SJjR7NuoeR1gkeHshsn5nDc9mpdCpd40w1MvvLBJxM xhoCaKtvoCNYvj/6HzZfy9uo8QVVSs4= X-MC-Unique: UHp81Q4_OKOn8F5P3_Idrw-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 4/6] virCommandFDSet: Remove return value Date: Tue, 2 Mar 2021 17:12:06 +0100 Message-Id: <187f93cbb691403e0863a8db3b5a098a84f321cc.1614701477.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com 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.14 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" The function can't fail nowadays. Remove the return value and adjust the only caller which ensures that @cmd is non-NULL and @fd is positive. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/util/vircommand.c | 22 +++------------------- 1 file changed, 3 insertions(+), 19 deletions(-) diff --git a/src/util/vircommand.c b/src/util/vircommand.c index 2f6635671d..579c77fd9f 100644 --- a/src/util/vircommand.c +++ b/src/util/vircommand.c @@ -216,27 +216,19 @@ virCommandFDIsSet(virCommandPtr cmd, * This is practically generalized implementation * of FD_SET() as we do not want to be limited * by FD_SETSIZE. - * - * Returns: 0 on success, - * -1 on usage error, */ -static int +static void virCommandFDSet(virCommandPtr cmd, int fd, unsigned int flags) { - if (!cmd || fd < 0) - return -1; - if (virCommandFDIsSet(cmd, fd)) - return 0; + return; ignore_value(VIR_EXPAND_N(cmd->passfd, cmd->npassfd, 1)); cmd->passfd[cmd->npassfd - 1].fd =3D fd; cmd->passfd[cmd->npassfd - 1].flags =3D flags; - - return 0; } #ifndef WIN32 @@ -1035,8 +1027,6 @@ virCommandNewVAList(const char *binary, va_list list) void virCommandPassFDIndex(virCommandPtr cmd, int fd, unsigned int flags, size_= t *idx) { - int ret =3D 0; - if (!cmd) { VIR_COMMAND_MAYBE_CLOSE_FD(fd, flags); return; @@ -1050,13 +1040,7 @@ virCommandPassFDIndex(virCommandPtr cmd, int fd, uns= igned int flags, size_t *idx return; } - if ((ret =3D virCommandFDSet(cmd, fd, flags)) !=3D 0) { - if (!cmd->has_error) - cmd->has_error =3D ret; - VIR_DEBUG("cannot preserve %d", fd); - VIR_COMMAND_MAYBE_CLOSE_FD(fd, flags); - return; - } + virCommandFDSet(cmd, fd, flags); if (idx) *idx =3D cmd->npassfd - 1; --=20 2.29.2 From nobody Tue Apr 30 12:59:09 2024 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=1614701566; cv=none; d=zohomail.com; s=zohoarc; b=mVWWSkg8AmFNLjj/88IvKFtMEuqRbKfiG8GV7xHPZIQQoOIJdco4qH359A9TvybS5wtSPBAVSxRzDWc5aLdx1KvNiEmJmPyli12hNMyp3qGobmB84ehBbRuEu9tFkVOGfUqqTnq3vnGxDP6KzgosvG4CygKPHoPjdYL8ZEcX+D0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1614701566; 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=8M7RPKffF2jMaTsUQ6cxpyeF3wx6WnlRDN8qTgD8TYo=; b=llTEkxS5KiQfiV8xQLS1d/xv9SLhCLvD3WKUToeCMoc/5ukxvOgfkVV5s04L8IKLZ6H9aAgX+5kGIzZJwqTiPtkiHpxpOjaGqdv3DDkYn6cpv2tYMemOeKzk23PUCJXVgwI1DtT1NgDPiM7WwrwR3A5FOHYpXM4hJhb7Hi+R3Qs= 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) header.from= 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 16147015663991015.8122292855385; Tue, 2 Mar 2021 08:12:46 -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-104-68e9zOSYMSyBhkLcjttpkw-1; Tue, 02 Mar 2021 11:12:42 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C5D2C803F48; Tue, 2 Mar 2021 16:12:36 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9E1696A035; Tue, 2 Mar 2021 16:12:36 +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 67D041809C91; Tue, 2 Mar 2021 16:12:36 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 122GCNZ5024039 for ; Tue, 2 Mar 2021 11:12:23 -0500 Received: by smtp.corp.redhat.com (Postfix) id 79E2060C43; Tue, 2 Mar 2021 16:12:23 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id C2AAA60BFA for ; Tue, 2 Mar 2021 16:12:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614701565; 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=8M7RPKffF2jMaTsUQ6cxpyeF3wx6WnlRDN8qTgD8TYo=; b=dnP0U8yNq+jgw5AFdPfK/23ll5RtfUZgS5Vuf+RVqxFqkwGHZKkUzIPcnXHYSWkKZFyYs6 5MsScko0oouCz2vS/eDQYdSGs8QfIR4c6Zl5RX3PpW8/qJPXD1xoH97LN0SDOo/xn00haH yIZpcdkSy4EPk/nNKbY1oARtRFJx2rE= X-MC-Unique: 68e9zOSYMSyBhkLcjttpkw-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 5/6] virCommandSetSendBuffer: Provide saner semantics Date: Tue, 2 Mar 2021 17:12:07 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com 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.13 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" The function is used to automatically feed a buffer into a pipe which can be used by the command to read contents of the buffer. Rather than passing in a pipe, let's create the pipe inside virCommandSetSendBuffer and directly associate the reader end with the command. This way the ownership of both ends of the pipe will end up with the virCommand right away reducing the need of cleanup in callers. The returned value then can be used just to format the appropriate arguments without worrying about cleanup or failure. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_tpm.c | 50 +++++++++---------------------------------- src/util/vircommand.c | 39 ++++++++++++++++++++++----------- src/util/vircommand.h | 6 +++--- tests/commandtest.c | 32 ++++++--------------------- 4 files changed, 46 insertions(+), 81 deletions(-) diff --git a/src/qemu/qemu_tpm.c b/src/qemu/qemu_tpm.c index d994816484..d8c518fc73 100644 --- a/src/qemu/qemu_tpm.c +++ b/src/qemu/qemu_tpm.c @@ -353,14 +353,14 @@ qemuTPMEmulatorPrepareHost(virDomainTPMDefPtr tpm, * This function reads the passphrase and writes it into the * write-end of a pipe so that the read-end of the pipe can be * passed to the emulator for reading the passphrase from. + * + * Note that the returned FD is owned by @cmd. */ static int qemuTPMSetupEncryption(const unsigned char *secretuuid, virCommandPtr cmd) { - int ret =3D -1; - int pipefd[2] =3D { -1, -1 }; - virConnectPtr conn; + g_autoptr(virConnect) conn =3D NULL; g_autofree uint8_t *secret =3D NULL; size_t secret_len; virSecretLookupTypeDef seclookupdef =3D { @@ -375,27 +375,9 @@ qemuTPMSetupEncryption(const unsigned char *secretuuid, if (virSecretGetSecretString(conn, &seclookupdef, VIR_SECRET_USAGE_TYPE_VTPM, &secret, &secret_len) < 0) - goto error; - - if (virPipe(pipefd) < 0) - goto error; - - if (virCommandSetSendBuffer(cmd, pipefd[1], secret, secret_len) < 0) - goto error; - - secret =3D NULL; - ret =3D pipefd[0]; - - cleanup: - virObjectUnref(conn); - - return ret; - - error: - VIR_FORCE_CLOSE(pipefd[1]); - VIR_FORCE_CLOSE(pipefd[0]); + return -1; - goto cleanup; + return virCommandSetSendBuffer(cmd, g_steal_pointer(&secret), secret_l= en); } /* @@ -549,8 +531,8 @@ qemuTPMEmulatorBuildCommand(virDomainTPMDefPtr tpm, bool created =3D false; g_autofree char *pidfile =3D NULL; g_autofree char *swtpm =3D virTPMGetSwtpm(); - VIR_AUTOCLOSE pwdfile_fd =3D -1; - VIR_AUTOCLOSE migpwdfile_fd =3D -1; + int pwdfile_fd =3D -1; + int migpwdfile_fd =3D -1; const unsigned char *secretuuid =3D NULL; if (!swtpm) @@ -618,25 +600,13 @@ qemuTPMEmulatorBuildCommand(virDomainTPMDefPtr tpm, } pwdfile_fd =3D qemuTPMSetupEncryption(tpm->data.emulator.secretuui= d, cmd); - if (pwdfile_fd) { - migpwdfile_fd =3D qemuTPMSetupEncryption(tpm->data.emulator.se= cretuuid, - cmd); - } - - if (pwdfile_fd < 0 || migpwdfile_fd < 0) - goto error; + migpwdfile_fd =3D qemuTPMSetupEncryption(tpm->data.emulator.secret= uuid, cmd); virCommandAddArg(cmd, "--key"); - virCommandAddArgFormat(cmd, "pwdfd=3D%d,mode=3Daes-256-cbc", - pwdfile_fd); - virCommandPassFD(cmd, pwdfile_fd, VIR_COMMAND_PASS_FD_CLOSE_PARENT= ); - pwdfile_fd =3D -1; + virCommandAddArgFormat(cmd, "pwdfd=3D%d,mode=3Daes-256-cbc", pwdfi= le_fd); virCommandAddArg(cmd, "--migration-key"); - virCommandAddArgFormat(cmd, "pwdfd=3D%d,mode=3Daes-256-cbc", - migpwdfile_fd); - virCommandPassFD(cmd, migpwdfile_fd, VIR_COMMAND_PASS_FD_CLOSE_PAR= ENT); - migpwdfile_fd =3D -1; + virCommandAddArgFormat(cmd, "pwdfd=3D%d,mode=3Daes-256-cbc", migpw= dfile_fd); } return g_steal_pointer(&cmd); diff --git a/src/util/vircommand.c b/src/util/vircommand.c index 579c77fd9f..04964b730b 100644 --- a/src/util/vircommand.c +++ b/src/util/vircommand.c @@ -1694,39 +1694,55 @@ virCommandFreeSendBuffers(virCommandPtr cmd) /** * virCommandSetSendBuffer * @cmd: the command to modify + * @buffer: buffer to pass to the filedescriptror + * @buflen: length of @buffer * - * Pass a buffer to virCommand that will be written into the - * given file descriptor. The buffer will be freed automatically - * and the file descriptor closed. + * Registers @buffer as an input buffer for @cmd which will be accessible = via + * the returned file descriptor. The returned file descriptor is already + * registered to be passed to @cmd, so callers must use it only to format = the + * appropriate argument of @cmd. + * + * @buffer is always stolen regardless of the return value. This function + * doesn't raise a libvirt error, but rather propagates the error via virC= ommand. + * Thus callers don't need to take a special action if -1 is returned. */ int virCommandSetSendBuffer(virCommandPtr cmd, - int fd, - unsigned char *buffer, size_t buflen) + unsigned char *buffer, + size_t buflen) { + g_autofree unsigned char *localbuf =3D g_steal_pointer(&buffer); + int pipefd[2] =3D { -1, -1 }; size_t i; if (virCommandHasError(cmd)) return -1; - if (fcntl(fd, F_SETFL, O_NONBLOCK) < 0) { - virReportSystemError(errno, "%s", - _("fcntl failed to set O_NONBLOCK")); + if (virPipeQuiet(pipefd) < 0) { + cmd->has_error =3D errno; + return -1; + } + + if (fcntl(pipefd[1], F_SETFL, O_NONBLOCK) < 0) { cmd->has_error =3D errno; + VIR_FORCE_CLOSE(pipefd[0]); + VIR_FORCE_CLOSE(pipefd[1]); return -1; } i =3D virCommandGetNumSendBuffers(cmd); ignore_value(VIR_REALLOC_N(cmd->sendBuffers, i + 1)); - cmd->sendBuffers[i].fd =3D fd; - cmd->sendBuffers[i].buffer =3D buffer; + cmd->sendBuffers[i].fd =3D pipefd[1]; + cmd->sendBuffers[i].buffer =3D g_steal_pointer(&localbuf); cmd->sendBuffers[i].buflen =3D buflen; cmd->sendBuffers[i].offset =3D 0; cmd->numSendBuffers++; - return 0; + virCommandPassFD(cmd, pipefd[0], VIR_COMMAND_PASS_FD_CLOSE_PARENT); + + return pipefd[0]; } @@ -2835,7 +2851,6 @@ int virCommandHandshakeNotify(virCommandPtr cmd) #else /* WIN32 */ int virCommandSetSendBuffer(virCommandPtr cmd, - int fd G_GNUC_UNUSED, unsigned char *buffer G_GNUC_UNUSED, size_t buflen G_GNUC_UNUSED) { diff --git a/src/util/vircommand.h b/src/util/vircommand.h index 9fb625ec4b..a00f30f51f 100644 --- a/src/util/vircommand.h +++ b/src/util/vircommand.h @@ -141,9 +141,9 @@ void virCommandSetWorkingDirectory(virCommandPtr cmd, const char *pwd) ATTRIBUTE_NONNULL(2); int virCommandSetSendBuffer(virCommandPtr cmd, - int fd, - unsigned char *buffer, size_t buflen) - ATTRIBUTE_NONNULL(3); + unsigned char *buffer, + size_t buflen) + ATTRIBUTE_NONNULL(2); void virCommandSetInputBuffer(virCommandPtr cmd, const char *inbuf) ATTRIBUTE_NONNULL(2); diff --git a/tests/commandtest.c b/tests/commandtest.c index df86725f0e..524c959eba 100644 --- a/tests/commandtest.c +++ b/tests/commandtest.c @@ -1039,8 +1039,8 @@ static int test26(const void *unused G_GNUC_UNUSED) static int test27(const void *unused G_GNUC_UNUSED) { g_autoptr(virCommand) cmd =3D virCommandNew(abs_builddir "/commandhelp= er"); - int pipe1[2]; - int pipe2[2]; + int buf1fd; + int buf2fd; int ret =3D -1; size_t buflen =3D 1024 * 128; g_autofree char *buffer0 =3D NULL; @@ -1078,30 +1078,14 @@ static int test27(const void *unused G_GNUC_UNUSED) errexpect =3D g_strdup_printf(TEST27_ERREXPECT_TEMP, buffer0, buffer1, buffer2); - if (virPipeQuiet(pipe1) < 0 || virPipeQuiet(pipe2) < 0) { - printf("Could not create pipe: %s\n", g_strerror(errno)); - goto cleanup; - } - - if (virCommandSetSendBuffer(cmd, pipe1[1], - (unsigned char *)buffer1, buflen - 1) < 0 || - virCommandSetSendBuffer(cmd, pipe2[1], - (unsigned char *)buffer2, buflen - 1) < 0) { - printf("Could not set send buffers\n"); - goto cleanup; - } - pipe1[1] =3D -1; - pipe2[1] =3D -1; - buffer1 =3D NULL; - buffer2 =3D NULL; + buf1fd =3D virCommandSetSendBuffer(cmd, (unsigned char *) g_steal_poin= ter(&buffer1), buflen - 1); + buf2fd =3D virCommandSetSendBuffer(cmd, (unsigned char *) g_steal_poin= ter(&buffer2), buflen - 1); virCommandAddArg(cmd, "--readfd"); - virCommandAddArgFormat(cmd, "%d", pipe1[0]); - virCommandPassFD(cmd, pipe1[0], 0); + virCommandAddArgFormat(cmd, "%d", buf1fd); virCommandAddArg(cmd, "--readfd"); - virCommandAddArgFormat(cmd, "%d", pipe2[0]); - virCommandPassFD(cmd, pipe2[0], 0); + virCommandAddArgFormat(cmd, "%d", buf2fd); virCommandSetInputBuffer(cmd, buffer0); virCommandSetOutputBuffer(cmd, &outactual); @@ -1130,10 +1114,6 @@ static int test27(const void *unused G_GNUC_UNUSED) ret =3D 0; cleanup: - VIR_FORCE_CLOSE(pipe1[0]); - VIR_FORCE_CLOSE(pipe2[0]); - VIR_FORCE_CLOSE(pipe1[1]); - VIR_FORCE_CLOSE(pipe2[1]); return ret; } --=20 2.29.2 From nobody Tue Apr 30 12:59:09 2024 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=1614701569; cv=none; d=zohomail.com; s=zohoarc; b=CQ/zKPO2VahXcnBx8ELaZPhnfFl7BPkTHMWz7L96DaPOjTlc+sKwm6Qbc9Uu2OjoAqaJqn9I5EKgNbcV48p5Grg1wowO7SA9Fg5VDF0LpzETBh9MopolKLk2Z7Nt6XpzzgfBIlrpQ2icncv2bcwraCcc7hvx+nL4tzCCXU4R/XY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1614701569; 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=7NhiXOM4VsHPAwgW21xAtYlqHSy4rYeqjClHu9sUdXI=; b=Pfvpy2CHiut4Z4r2CVz+kFXtLUpmwXwhHEzqu4c7kCE3+Iv2vUbpEQbO+/EtgcWW2XWryJ2XU0LuId4tmIGR2ANn/foTTt9Fau1IoYnm1sJuSQJEUtwOQtGsqpbyxRXv/rXiovut8CiKuE1feb8KS/GJwnCo9HNMwASbRK9oqlY= 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) header.from= 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 1614701569495539.5943480732171; Tue, 2 Mar 2021 08:12:49 -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-98--YKQz8TcNU2gurld0AKkBQ-1; Tue, 02 Mar 2021 11:12:46 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 14712801980; Tue, 2 Mar 2021 16:12:40 +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 E05F56F991; Tue, 2 Mar 2021 16:12:39 +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 A4D3D58079; Tue, 2 Mar 2021 16:12:39 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 122GCQin024059 for ; Tue, 2 Mar 2021 11:12:26 -0500 Received: by smtp.corp.redhat.com (Postfix) id C06AE60C47; Tue, 2 Mar 2021 16:12:26 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3437360BFA for ; Tue, 2 Mar 2021 16:12:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614701568; 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=7NhiXOM4VsHPAwgW21xAtYlqHSy4rYeqjClHu9sUdXI=; b=jHqxVVzwABJt9i/c9RkL/3QrCjY/rqFBDLzCxuZfB3u/ofqwW0tRbF+xbo4mRtApMuDURY s1l5ITd7VXjj1t+aFbKHrYhvKiWA0BwkX68OYHzdA4J45c1HL85Z/lx8v1Sx8C7kxIYrMa T2+Pm6W5GCjRnqgJIhBtHnLSBDYVQRM= X-MC-Unique: -YKQz8TcNU2gurld0AKkBQ-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 6/6] commandtest: test27: Remove pointless 'cleanup' label Date: Tue, 2 Mar 2021 17:12:08 +0100 Message-Id: <075a5316673a45548069a21a7eadde4053dc5d86.1614701477.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com 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.13 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: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- tests/commandtest.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/tests/commandtest.c b/tests/commandtest.c index 524c959eba..aaf391935c 100644 --- a/tests/commandtest.c +++ b/tests/commandtest.c @@ -1041,7 +1041,6 @@ static int test27(const void *unused G_GNUC_UNUSED) g_autoptr(virCommand) cmd =3D virCommandNew(abs_builddir "/commandhelp= er"); int buf1fd; int buf2fd; - int ret =3D -1; size_t buflen =3D 1024 * 128; g_autofree char *buffer0 =3D NULL; g_autofree char *buffer1 =3D NULL; @@ -1093,29 +1092,25 @@ static int test27(const void *unused G_GNUC_UNUSED) if (virCommandRun(cmd, NULL) < 0) { printf("Cannot run child %s\n", virGetLastErrorMessage()); - goto cleanup; + return -1; } if (!outactual || !erractual) - goto cleanup; + return -1; if (STRNEQ(outactual, outexpect)) { virTestDifference(stderr, outexpect, outactual); - goto cleanup; + return -1; } if (STRNEQ(erractual, errexpect)) { virTestDifference(stderr, errexpect, erractual); - goto cleanup; + return -1; } if (checkoutput("test27") < 0) - goto cleanup; - - ret =3D 0; - - cleanup: + return -1; - return ret; + return 0; } --=20 2.29.2