From nobody Mon Feb 9 14:36:26 2026 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1714793614624457.24367311302467; Fri, 3 May 2024 20:33:34 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 547D81BF4; Fri, 3 May 2024 23:33:33 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 3BCEF1BEB; Fri, 3 May 2024 23:32:58 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 176381B90; Fri, 3 May 2024 23:32:54 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 806961B90 for ; Fri, 3 May 2024 23:32:53 -0400 (EDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-103-VAY1UgZfNrmpC9CmYoEhBQ-1; Fri, 03 May 2024 23:32:49 -0400 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C03D6812C50 for ; Sat, 4 May 2024 03:32:48 +0000 (UTC) Received: from localhost.localdomain (unknown [10.45.224.8]) by smtp.corp.redhat.com (Postfix) with ESMTP id 67157492BC7 for ; Sat, 4 May 2024 03:32:48 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.7 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 X-MC-Unique: VAY1UgZfNrmpC9CmYoEhBQ-1 From: Michal Privoznik To: devel@lists.libvirt.org Subject: [PATCH] vsh: Don't init history in cmdComplete() Date: Sat, 4 May 2024 05:32:39 +0200 Message-ID: <06fb690c5951b58ac4c45c9e63723bc2c87463ed.1714793559.git.mprivozn@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.10 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Message-ID-Hash: IJRBXYFQNV3E2QFVUGKUUXIDX3OQQ6FK X-Message-ID-Hash: IJRBXYFQNV3E2QFVUGKUUXIDX3OQQ6FK X-MailFrom: mprivozn@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="utf-8"; x-default="true" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1714793615671100001 Recent rework of virshtest uncovered a subtle bug that was dormant in now vsh but before that even in monolithic virsh. In vsh.c there's this vshReadlineInit() function that's supposed to initialize readline library, i.e. set those global rl_* pointers. But it also initializes history library. Then, when virsh/virt-admin quits, vshReadlineDeinit() is called which writes history into a file (ensuring the parent directory exists). So far no problem. Problem arises when cmdComplete() is called (from a bash completer, for instance). It does not guard call to vshReadlineInit() with check for interactive shell (and it should not), but it sets ctl->historyfile which signals to vshReadlineDeinit() the history should be written. Now, no real history is written, because nothing was entered on the stdin, but the parent directory is created nevertheless. With recent movement in virshtest.c this means some test cases might create virsh history file which breaks our promise of not touching user's data in test suite. Resolves: https://bugs.gentoo.org/931109 Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- tools/vsh.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/tools/vsh.c b/tools/vsh.c index 58855f63ba..e74045c24e 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -2973,7 +2973,7 @@ vshReadlineInit(vshControl *ctl) const char *quote_characters =3D "\"'"; =20 /* initialize readline stuff only once */ - if (ctl->historydir) + if (autoCompleteOpaque) return 0; =20 /* Opaque data for autocomplete callbacks. */ @@ -2989,6 +2989,11 @@ vshReadlineInit(vshControl *ctl) rl_completer_quote_characters =3D quote_characters; rl_char_is_quoted_p =3D vshReadlineCharIsQuoted; =20 + /* Stuff below is needed only for interactive mode. */ + if (!ctl->imode) { + return 0; + } + histsize_env =3D g_strdup_printf("%s_HISTSIZE", ctl->env_prefix); =20 /* Limit the total size of the history buffer */ @@ -3149,7 +3154,7 @@ vshInit(vshControl *ctl, const vshCmdGrp *groups) cmdGroups =3D groups; =20 if (vshInitDebug(ctl) < 0 || - (ctl->imode && vshReadlineInit(ctl) < 0)) + vshReadlineInit(ctl) < 0) return false; =20 return true; @@ -3168,7 +3173,7 @@ vshInitReload(vshControl *ctl) =20 if (ctl->imode) vshReadlineDeinit(ctl); - if (ctl->imode && vshReadlineInit(ctl) < 0) + if (vshReadlineInit(ctl) < 0) return false; =20 return true; --=20 2.43.2 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org