From nobody Sun Feb 8 22:50:29 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.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.129.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=1646229419; cv=none; d=zohomail.com; s=zohoarc; b=SFixrmCGDG55n/VqTs1idldtM2ADh4RQi/N4d62xmUjnQwdEzSFgCr6z8iE6HomxvdWfkVsppO5NPtly0EK0MRSwbUs3LD8J1+50JpOU4asYHNLSIPBGgS8MDG/4cSh4XpPbnFNyeADq4V2PI5zTFgGPS1WKIzVCHsaOvWTPESM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1646229419; 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=K6QEawQ69s92MFGSZqy/L4y91DAdlLeaWYnSblzUO8Y=; b=J8tH4aZvuLFPRWk9fkrwQfAFG9i3iJEIANrHAulKcdRIB+aoZSfUi47PkBYTdD5aDeHUQlTUDSYjqnc5u8jdK9TZ+PhAUMgOi5L664VUvBRrH0ko0gZArUNpclRjWziT6VZc5eIREj01hzP0WUkHdGr+zHs/6DXt95Vqgc0sGe0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.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.129.124]) by mx.zohomail.com with SMTPS id 1646229419373645.7528939000008; Wed, 2 Mar 2022 05:56:59 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-25-lIkJD39qM8yzCEeC-Ss2ow-1; Wed, 02 Mar 2022 08:56:54 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E2D5C18BA283; Wed, 2 Mar 2022 13:56:47 +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 B78361042A66; Wed, 2 Mar 2022 13:56:47 +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 866D91809CB4; Wed, 2 Mar 2022 13:56:47 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 222DujkL018304 for ; Wed, 2 Mar 2022 08:56:45 -0500 Received: by smtp.corp.redhat.com (Postfix) id 8775783581; Wed, 2 Mar 2022 13:56:45 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id E37F383577 for ; Wed, 2 Mar 2022 13:56:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1646229418; 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=K6QEawQ69s92MFGSZqy/L4y91DAdlLeaWYnSblzUO8Y=; b=YnNMMKpguJqL6g/XJYvZ2MuBSJgnbHjUJlkXo3YgYSqDplNB0x4eFkcZzvU/9WTL4GnguW IPlCj8We3pqKjAS46Drh5p0hh5Diz8Mo+i+983DSHV0oaxnBNYIZfcvFXtQoTpF0ZS+k02 9OEPIHRlzETHDbnZHuDP/tUIDSWwrIY= X-MC-Unique: lIkJD39qM8yzCEeC-Ss2ow-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 23/23] virsh: cmdDesc: Fix logic when '-edit' is used along with 'desc' argument Date: Wed, 2 Mar 2022 14:55:22 +0100 Message-Id: <4fe3f3d7063a3f78a3dd892361245e5f912bc117.1646229194.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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.22 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) X-ZM-MESSAGEID: 1646229421602100002 Content-Type: text/plain; charset="utf-8" Historically the use of the '-desc' multiple argument parameter was not forbidden toghether with '-edit', but use of both together has some unexpected behaviour. Specifically the editor is filled with the contents passed via '-desc' but if the user doesn't change the text in any way virsh will claim that the description was not chaged even if it differs from the currently set description. Similarly, when the user would edit the description provided via 'desc' so that it's identical with the one configured for the domain, virsh would claim that it was updated: # virsh desc cd No description for domain: cd # EDITOR=3Dtrue virsh desc cd --edit "test desc" Domain description not changed After the fix: # virsh desc cd No description for domain: cd # EDITOR=3Dtrue virsh desc cd --edit "test desc" Domain description updated successfully # EDITOR=3Dtrue virsh desc cd --edit "test desc" Domain description not changed Signed-off-by: Peter Krempa --- tools/virsh-domain.c | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 89ad45dbf0..d5fd8be7c3 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -8335,7 +8335,7 @@ cmdDesc(vshControl *ctl, const vshCmd *cmd) int state; int type; - g_autofree char *desc =3D NULL; + g_autofree char *descArg =3D NULL; const vshCmdOpt *opt =3D NULL; g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; unsigned int flags =3D VIR_DOMAIN_AFFECT_CURRENT; @@ -8367,14 +8367,17 @@ cmdDesc(vshControl *ctl, const vshCmd *cmd) virBufferTrim(&buf, " "); - desc =3D virBufferContentAndReset(&buf); + descArg =3D virBufferContentAndReset(&buf); - if (edit || desc) { - if (!desc) { - desc =3D virshGetDomainDescription(ctl, dom, title, queryf= lags); - if (!desc) - return false; - } + if (edit || descArg) { + g_autofree char *descDom =3D NULL; + g_autofree char *descNew =3D NULL; + + if (!(descDom =3D virshGetDomainDescription(ctl, dom, title, query= flags))) + return false; + + if (!descArg) + descArg =3D g_strdup(descDom); if (edit) { g_autoptr(vshTempFile) tmp =3D NULL; @@ -8382,7 +8385,7 @@ cmdDesc(vshControl *ctl, const vshCmd *cmd) char *tmpstr; /* Create and open the temporary file. */ - if (!(tmp =3D vshEditWriteToTempFile(ctl, desc))) + if (!(tmp =3D vshEditWriteToTempFile(ctl, descArg))) return false; /* Start the editor. */ @@ -8402,7 +8405,7 @@ cmdDesc(vshControl *ctl, const vshCmd *cmd) *tmpstr =3D '\0'; /* Compare original XML with edited. Has it changed at all? */ - if (STREQ(desc, desc_edited)) { + if (STREQ(descDom, desc_edited)) { if (title) vshPrintExtra(ctl, "%s", _("Domain title not changed\n= ")); else @@ -8411,11 +8414,12 @@ cmdDesc(vshControl *ctl, const vshCmd *cmd) return true; } - VIR_FREE(desc); - desc =3D g_steal_pointer(&desc_edited); + descNew =3D g_steal_pointer(&desc_edited); + } else { + descNew =3D g_steal_pointer(&descArg); } - if (virDomainSetMetadata(dom, type, desc, NULL, NULL, flags) < 0) { + if (virDomainSetMetadata(dom, type, descNew, NULL, NULL, flags) < = 0) { if (title) vshError(ctl, "%s", _("Failed to set new domain title")); else @@ -8430,7 +8434,7 @@ cmdDesc(vshControl *ctl, const vshCmd *cmd) vshPrintExtra(ctl, "%s", _("Domain description updated success= fully")); } else { - desc =3D virshGetDomainDescription(ctl, dom, title, queryflags); + g_autofree char *desc =3D virshGetDomainDescription(ctl, dom, titl= e, queryflags); if (!desc) return false; --=20 2.35.1