RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.
Bug 1379895 - Virsh/virt-admin client doesn't write the history commands into file
Summary: Virsh/virt-admin client doesn't write the history commands into file
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: libvirt
Version: 7.3
Hardware: x86_64
OS: Linux
medium
medium
Target Milestone: rc
: ---
Assignee: John Ferlan
QA Contact: Lili Zhu
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2016-09-28 02:37 UTC by Fangge Jin
Modified: 2017-09-25 03:18 UTC (History)
9 users (show)

Fixed In Version: libvirt-2.5.0-1.el7
Doc Type: Bug Fix
Doc Text:
Cause: Erroneous skip of setting if interactive mode was not set; however, the field to check is cleared for 'quit' and 'exit' commands (NB: using <ctrl>D would save the history). Consequence: When exiting the "virsh" using the 'quit' or 'exit' command, the shell history will be lost. Fix: Removed the unnecessary check for flag. Result: When exiting the "virsh" shell using the 'quit' or 'exit' command, the shell history will be updated.
Clone Of:
Environment:
Last Closed: 2017-08-01 17:16:43 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)
strace output of virsh client (71.33 KB, text/plain)
2016-09-28 02:37 UTC, Fangge Jin
no flags Details


Links
System ID Private Priority Status Summary Last Updated
Red Hat Product Errata RHEA-2017:1846 0 normal SHIPPED_LIVE libvirt bug fix and enhancement update 2017-08-01 18:02:50 UTC

Description Fangge Jin 2016-09-28 02:37:40 UTC
Created attachment 1205380 [details]
strace output of virsh client

Description of problem:
There are two problems that exist for both virsh client and virt-admin client, take virsh client as example:

1)Virsh client doesn't create history file automatically
# ll /root/.cache/libvirt/
total 0

# virsh
Welcome to virsh, the virtualization interactive terminal.

Type:  'help' for help with commands
       'quit' to quit

virsh # echo 1
1
virsh # echo 2
2
virsh # exit

After execute some commands in interactive mode and exit, no history file is created.
# ll /root/.cache/libvirt/
total 0


2)After I create history file manually, virsh client still doesn't flush the history commands into the file.
# mkdir /root/.cache/libvirt/virsh

# touch /root/.cache/libvirt/virsh/history

# strace -o /tmp/strace  virsh
Welcome to virsh, the virtualization interactive terminal.

Type:  'help' for help with commands
       'quit' to quit

virsh # echo 1
1
virsh # echo 2
2
virsh # exit

# cat /root/.cache/libvirt/virsh/history
(no output)


Version-Release number of selected component:
libvirt-2.0.0-10.el7.x86_64

How reproducible:
100%

Steps to Reproduce:
As description

Actual results:
As description

Expected results:
1) Virsh/virt-admin client can create history file automatically if no such file exists
2) Virsh/virt-admin client can flush the history commands into file when exits the interactive mode


Additional info:
RHEl7.2 build libvirt-1.2.17-13.el7_2.5.x86_64 works well

Comment 3 John Ferlan 2016-09-28 19:28:33 UTC
Instead of typing "exit" or "quit", press the key combo <ctrl>D and the history file is automagically created.  IOW: 'write_history' is called. So something in the exit/quit handling is amiss...

This is because during main() loop processing/parsing interactive commands runs while "ctl->imode" is true.  When exit or quit is typed, cmdQuit() is called clearing the 'imode' setting.  When "<ctrl>D" is typed, the main() loop processing will "break" from the loop because EOF is found.

When the loop is exited, main() will call virshDeinit() which calls vshDeinit() which will only call vshReadlineDeinit() [e.g. the function that writes out the history file] if ctl->imode is set. Since exit/quit clear it, the history file isn't written. 

The "workaround" is to use <ctrl>D (which fortunately I've trained my fingers to do long ago).

In 7.2, the vshReadlineDeinit() was called unconditionally from vshDeinit() [this prior to a rather massive change from libvirt commit id '834c5720'.]

I've posted a patch upstream :

http://www.redhat.com/archives/libvir-list/2016-September/msg01312.html

Comment 5 John Ferlan 2016-09-29 11:38:19 UTC
The patch has been pushed upstream:

commit bcfa2f427d53264830ff5fa5d029b6897773702d
Author: John Ferlan <jferlan>
Date:   Wed Sep 28 15:01:55 2016 -0400

    vsh: Write out history on "quit" or "exit" in interactive mode
    
...

$ git describe bcfa2f427d53264830ff5fa5d029b6897773702d
v2.3.0-rc1-9-gbcfa2f4
$

Comment 6 Fangge Jin 2016-10-08 08:38:28 UTC
Test with upstream version v2.3.0-40-g0f3f8ac, it works well.

Steps:

1.
# ll /root/.cache/libvirt/
total 0

2. Enter interactive mode of virsh client and do some operations:
1) # virsh
Welcome to virsh, the virtualization interactive terminal.

Type:  'help' for help with commands
       'quit' to quit

virsh # echo 1
1
virsh # echo 2
2
virsh # quit


2) # virsh
Welcome to virsh, the virtualization interactive terminal.

Type:  'help' for help with commands
       'quit' to quit

virsh # echo 3
3
virsh # echo 4
4
virsh # exit


3) # virsh
Welcome to virsh, the virtualization interactive terminal.

Type:  'help' for help with commands
       'quit' to quit

virsh # echo 5
5
virsh # echo 6
6
virsh #
(Press Ctrl+D)

3. Check the history file, the history commands are all recorded correctly:
# cat /root/.cache/libvirt/virsh/history
echo 1
echo 2
quit
echo 3
echo 4
exit
echo 5
echo 6

4. Re-do step 2 and step3 with virt-admin client, it also works well.

Comment 9 Lili Zhu 2017-06-15 03:09:29 UTC
Reproduce this bug with build libvirt-2.0.0-10.el7.x86_64
steps to reproduce:
Scenario 1: virsh
1.
# ll /root/.cache/libvirt/
total 0

2.
# virsh 
Welcome to virsh, the virtualization interactive terminal.

Type:  'help' for help with commands
       'quit' to quit

virsh # list --all
 Id    Name                           State
----------------------------------------------------
 -     rhel6.9-mt6.6                  shut off
 -     rhel6.9-q35                    shut off
 -     rhel7.4-mt7.3                  shut off
 -     rhel7.4-q35                    shut off

virsh # echo 1
1
virsh # echo 2
2
virsh # exit

3. 
# ll /root/.cache/libvirt/
total 0


Scenario 2: virt-admin
1. # virt-admin 
Welcome to virt-admin, the administrating virtualization interactive terminal.

Type:  'help' for help with commands
       'quit' to quit

virt-admin # srv-list 
 Id    Name           
---------------
 0     admin          
 1     libvirtd       

virt-admin # srv-clients-list admin 
 Id    Transport       Connected since
--------------------------------------------------
 1     unix            2017-06-15 10:33:24+0800

virt-admin # srv-clients-list libvirtd 
 Id    Transport       Connected since
--------------------------------------------------

virt-admin # exit

# ll /root/.cache/libvirt/

Verify this bug with build libvirt-3.2.0-10.el7.x86_64
Steps to verify:
Scenario 1: virsh
1. 
# ll /root/.cache/libvirt/
total 0

2.
# virsh 
Welcome to virsh, the virtualization interactive terminal.

Type:  'help' for help with commands
       'quit' to quit

virsh # echo 1
1
virsh # echo 2
2
virsh # list --all
 Id    Name                           State
----------------------------------------------------
 -     rhel6.9-mt6.6                  shut off

virsh # 
(Press Ctrl+D)

3.# ll /root/.cache/libvirt/virsh/
total 4
-rw-------. 1 root root 45 Jun 15 11:01 history

4. 
# virsh 
Welcome to virsh, the virtualization interactive terminal.

Type:  'help' for help with commands
       'quit' to quit

virsh # echo 5 
5
virsh # echo 6
6
virsh # exit

5. 
# cat /root/.cache/libvirt/virsh/history 
echo 1
echo 2
list --all
echo 5 
echo 6
exit

Scenario 2: virt-admin 
1.
# virt-admin 
Welcome to virt-admin, the administrating virtualization interactive terminal.

Type:  'help' for help with commands
       'quit' to quit

virt-admin # echo 7 
7
virt-admin # echo 8
8
virt-admin # exit

2.
# cat /root/.cache/libvirt/virt-admin/history 
echo 7 
echo 8
exit


As the result match the expectations, so mark the bug as verified.

Comment 10 errata-xmlrpc 2017-08-01 17:16:43 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHEA-2017:1846

Comment 11 errata-xmlrpc 2017-08-01 23:57:38 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHEA-2017:1846


Note You need to log in before you can comment on or make changes to this bug.