Bug 1063239

Summary: remote-viewer not invoked from "xdg-open console.vv" command
Product: Red Hat Enterprise Linux 7 Reporter: Christophe Fergeau <cfergeau>
Component: virt-viewerAssignee: Christophe Fergeau <cfergeau>
Status: CLOSED ERRATA QA Contact: Virtualization Bugs <virt-bugs>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 7.0CC: agajania, berrange, cfergeau, codong, dblechte, dyuan, jjongsma, juzhou, mzhan, rbalakri, tzheng
Target Milestone: rc   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: virt-viewer-0.6.0-1.el7 Doc Type: Bug Fix
Doc Text:
Cause: remote-viewer was not registered properly as a handler for .vv files Consequence: remote-viewer was not automatically invoked to open .vv files Fix: Update package to register remote-viewer to handle .vv files Result: remote-viewer is launched to handle .vv files
Story Points: ---
Clone Of: 1044209 Environment:
Last Closed: 2015-03-05 13:38:54 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On: 1109400    
Bug Blocks:    

Description Christophe Fergeau 2014-02-10 10:49:25 UTC
+++ This bug was initially created as a clone of Bug #1044209 +++

Description of problem:

I have noticed that remote-viewer isn't getting automatically run when I try to bring up a virtual desktop from the RHEV User Portal with the Epiphany web browser.  Instead, the downloaded vv file is opened in gedit.

I have found that when I run the following command, the console.vv file gets opened in gedit instead of remote-viewer.

xdg-open console.vv


Version-Release number of selected component (if applicable):
virt-viewer-0.5.7-1.fc20.x86_64


How reproducible:  
Happens every time.


Steps to Reproduce:
1.  Download a console.vv file from the RHEV User Portal by attempting to open a SPICE console in Native Mode.
2.  Run the command "xdg-open console.vv" on the file that was just downloaded.


Actual results:
The console.vv file is opened with gedit.


Expected results:
The console.vv file should be opened with remote-viewer.

--- Additional comment from Aram Agajanian on 2013-12-17 18:04:39 EST ---

As was suggested on IRC, I ran the following command and the problem went away.

su -c "update-mime-database /usr/share/mime"

--- Additional comment from Christophe Fergeau on 2013-12-18 05:18:03 EST ---

Sent patch upstream 
https://www.redhat.com/archives/virt-tools-list/2013-December/msg00036.html

Comment 3 Christophe Fergeau 2014-02-20 15:38:04 UTC
Can you run
XDG_UTILS_DEBUG_LEVEL=5 xdg-mime query default application/x-virt-viewer 
in the working case and non-working ssh case and paste the result here?

I tried with a ssh -X to my local machine and this worked as expected.

Comment 4 CongDong 2014-02-24 02:12:40 UTC
ssh:
# XDG_UTILS_DEBUG_LEVEL=5 xdg-mime query default application/x-virt-viewer
Checking /usr/local/share//applications/defaults.list
Checking /usr/local/share//applications/defaults.list
Checking /usr/share//applications/defaults.list
Checking /usr/share//applications/defaults.list
 Checking /usr/share//applications/remote-viewer.desktop
   Select /usr/share//applications/remote-viewer.desktop [ -1 => 0 ]
remote-viewer.desktop
# xdg-open console.vv

Result:
open with gedit


non ssh:
# XDG_UTILS_DEBUG_LEVEL=5 xdg-mime query default application/x-virt-viewer
Running KDE trader query "application/x-virt-viewer" mimetype and "Application" servicetype
remote-viewer.desktop
# xdg-open console.vv

Result:
open with remote-viewer

Comment 5 Christophe Fergeau 2014-02-25 10:39:00 UTC
Pleease also run XDG_UTILS_DEBUG_LEVEL=5 xdg-open console.vv in both case.
It seems to me that remote-viewer is properly associated with .vv files, but that xdg-open is misbehaving somehow through ssh.

Comment 6 CongDong 2014-02-26 02:45:41 UTC
SSH:
# XDG_UTILS_DEGUG_LEVEL=5 xdg-open console.vv 
START /usr/bin/gedit "console.vv"

** (gedit:6232): WARNING **: Couldn't connect to accessibility bus: Failed to connect to socket /tmp/dbus-SPCRH4ZwLD: Connection refused

Result:
open the vv file with gedit


non-SSH:
# XDG_UTILS_DEBUG_LEVEL=5 xdg-open console.vv 
Selected DE kde

Result:
can connect the guest with remote-viewer

Comment 7 Christophe Fergeau 2014-02-26 09:23:32 UTC
I think if you run
XDG_CURRENT_DESKTOP=KDE  xdg-open console.vv 
things will work through ssh. At this point this really is an xdg-mime or system setup issue than an issue with this bug fix imo.

Did you run "XDG_UTILS_DEGUG_LEVEL=5 xdg-open console.vv" or ""XDG_UTILS_DEBUG_LEVEL=5 xdg-open console.vv" ? (DEGUG vs DEBUG) You put the 2 versions in your latest comment, and I think using _DEBUG_ would give more output. 
Alternatively, you can run sh -x /usr/bin/xdg-open console.vv

Comment 8 CongDong 2014-02-26 09:54:12 UTC
(In reply to Christophe Fergeau from comment #7)
> Did you run "XDG_UTILS_DEGUG_LEVEL=5 xdg-open console.vv" or
> ""XDG_UTILS_DEBUG_LEVEL=5 xdg-open console.vv" ? (DEGUG vs DEBUG) You put
> the 2 versions in your latest comment, and I think using _DEBUG_ would give
> more output. 


Sorry for the typo.
As you said it's not an issue of virt-viewer, should I file a new xdg-mime bug?

SSH:

1. # XDG_CURRENT_DESKTOP=KDE  xdg-open console.vv 
Result: can connect the guest with remote-viewer

2. # XDG_UTILS_DEBUG_LEVEL=5 xdg-open console.vv 
Selected DE generic
Running file --mime-type "/root/Downloads/console.vv"
Checking /usr/local/share//applications/defaults.list
Checking /usr/local/share//applications/defaults.list
Checking /usr/share//applications/defaults.list
/root/.local/share:/usr/local/share/:/usr/share/
START /usr/bin/gedit "console.vv"

** (gedit:3837): WARNING **: Couldn't connect to accessibility bus: Failed to connect to socket /tmp/dbus-SPCRH4ZwLD: Connection refused

Result: open vv file with gedit


3. # sh -x /usr/bin/xdg-open console.vv 
+ check_common_commands console.vv
+ '[' 1 -gt 0 ']'
+ parm=console.vv
+ shift
+ case "$parm" in
+ '[' 0 -gt 0 ']'
+ '[' -z '' ']'
+ unset XDG_UTILS_DEBUG_LEVEL
+ '[' 0 -lt 1 ']'
+ xdg_redirect_output=' > /dev/null 2> /dev/null'
+ '[' xconsole.vv '!=' x ']'
+ url=
+ '[' 1 -gt 0 ']'
+ parm=console.vv
+ shift
+ case "$parm" in
+ '[' -n '' ']'
+ url=console.vv
+ '[' 0 -gt 0 ']'
+ '[' -z console.vv ']'
+ detectDE
+ unset GREP_OPTIONS
+ '[' -n '' ']'
+ '[' x = x ']'
+ '[' x = xtrue ']'
+ '[' x '!=' x ']'
+ '[' x '!=' x ']'
++ dbus-send --print-reply --dest=org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus.GetNameOwner string:org.gnome.SessionManager
+ xprop -root _DT_SAVE_MODE
+ grep ' = \"xfce4\"$'
+ xprop -root
+ grep -i '^xfce_desktop_window'
+ '[' x = x ']'
+ case "$DESKTOP_SESSION" in
+ '[' x = x ']'
+ case "$(uname 2>/dev/null)" in
++ uname
+ '[' x = xgnome ']'
+ '[' x = x ']'
+ DE=generic
+ DEBUG 2 'Selected DE generic'
+ '[' -z '' ']'
+ return 0
+ case "${BROWSER}" in
+ '[' x = x ']'
+ BROWSER=links2:elinks:links:lynx:w3m
+ '[' -n localhost:10.0 ']'
+ BROWSER=x-www-browser:firefox:seamonkey:mozilla:epiphany:konqueror:chromium-browser:google-chrome:links2:elinks:links:lynx:w3m
+ case "$DE" in
+ open_generic console.vv
+ echo console.vv
+ grep -q '^file://'
+ echo console.vv
+ egrep -q '^[[:alpha:]+\.\-]+:'
+ local file=console.vv
+ echo console.vv
+ grep -q '^file:///'
+ check_input_file console.vv
+ '[' '!' -e console.vv ']'
+ '[' '!' -r console.vv ']'
+ open_generic_xdg_file_mime console.vv
++ xdg-mime query filetype console.vv
++ sed 's/;.*//'
+ filetype=text/plain
+ open_generic_xdg_mime console.vv text/plain
+ filetype=text/plain
++ xdg-mime query default text/plain
+ default=gedit.desktop
+ '[' -n gedit.desktop ']'
+ xdg_user_dir=
+ '[' -n '' ']'
+ xdg_user_dir=/root/.local/share
+ xdg_system_dirs=
+ '[' -n '' ']'
+ xdg_system_dirs=/usr/local/share/:/usr/share/
+ DEBUG 3 /root/.local/share:/usr/local/share/:/usr/share/
+ '[' -z '' ']'
+ return 0
++ echo /root/.local/share:/usr/local/share/:/usr/share/
++ sed 's/:/ /g'
+ for x in '`echo "$xdg_user_dir:$xdg_system_dirs" | sed '\''s/:/ /g'\''`'
+ search_desktop_file gedit.desktop /root/.local/share/applications/ console.vv
+ local default=gedit.desktop
+ local dir=/root/.local/share/applications/
+ local arg=console.vv
+ local file=
+ '[' -r /root/.local/share/applications//gedit.desktop ']'
++ echo gedit.desktop
++ sed -e 's|-|/|'
+ '[' -r /root/.local/share/applications//gedit.desktop ']'
+ '[' -r '' ']'
+ for d in '$dir/*/'
+ '[' -d '/root/.local/share/applications//*/' ']'
+ for x in '`echo "$xdg_user_dir:$xdg_system_dirs" | sed '\''s/:/ /g'\''`'
+ search_desktop_file gedit.desktop /usr/local/share//applications/ console.vv
+ local default=gedit.desktop
+ local dir=/usr/local/share//applications/
+ local arg=console.vv
+ local file=
+ '[' -r /usr/local/share//applications//gedit.desktop ']'
++ echo gedit.desktop
++ sed -e 's|-|/|'
+ '[' -r /usr/local/share//applications//gedit.desktop ']'
+ '[' -r '' ']'
+ for d in '$dir/*/'
+ '[' -d /usr/local/share//applications//kde4/ ']'
+ search_desktop_file gedit.desktop /usr/local/share//applications//kde4/ console.vv
+ local default=gedit.desktop
+ local dir=/usr/local/share//applications//kde4/
+ local arg=console.vv
+ local file=
+ '[' -r /usr/local/share//applications//kde4//gedit.desktop ']'
++ echo gedit.desktop
++ sed -e 's|-|/|'
+ '[' -r /usr/local/share//applications//kde4//gedit.desktop ']'
+ '[' -r '' ']'
+ for d in '$dir/*/'
+ '[' -d '/usr/local/share//applications//kde4//*/' ']'
+ for x in '`echo "$xdg_user_dir:$xdg_system_dirs" | sed '\''s/:/ /g'\''`'
+ search_desktop_file gedit.desktop /usr/share//applications/ console.vv
+ local default=gedit.desktop
+ local dir=/usr/share//applications/
+ local arg=console.vv
+ local file=
+ '[' -r /usr/share//applications//gedit.desktop ']'
+ file=/usr/share//applications//gedit.desktop
+ '[' -r /usr/share//applications//gedit.desktop ']'
++ grep -E '^Exec(\[[^]=]*])?=' /usr/share//applications//gedit.desktop
++ cut -d= -f 2-
++ first_word
++ read first rest
++ echo gedit
+ command=gedit
++ which gedit
+ command_exec=/usr/bin/gedit
++ grep -E '^Exec(\[[^]=]*])?=' /usr/share//applications//gedit.desktop
++ cut -d= -f 2-
++ last_word
++ read first rest
++ echo %U
+ arguments=%U
++ echo console.vv
++ sed 's/&/\\&/g'
+ arg_one=console.vv
++ echo %U
++ sed -e 's*%[fFuU]*"console.vv"*g'
+ arguments_exec='"console.vv"'
+ '[' -x /usr/bin/gedit ']'
+ echo %U
+ grep -iq '%[fFuU]'
+ echo START /usr/bin/gedit '"console.vv"'
START /usr/bin/gedit "console.vv"
+ eval /usr/bin/gedit '"console.vv"'
++ /usr/bin/gedit console.vv

** (gedit:4001): WARNING **: Couldn't connect to accessibility bus: Failed to connect to socket /tmp/dbus-SPCRH4ZwLD: Connection refused
+ '[' 0 -eq 0 ']'
+ exit_success
+ '[' 0 -gt 0 ']'
+ exit 0


Result: open vv file with gedit

Comment 9 Christophe Fergeau 2014-02-26 10:11:35 UTC
(In reply to CongDong from comment #8)
> As you said it's not an issue of virt-viewer, should I file a new xdg-mime
> bug?

Thanks for the additional testing! You can file an xdg-mime bug, but it's possible that it's the best it can do on your system. On my system it manages to detect a GNOME desktop even over ssh, it uses gvfs-info to get the file mime type (on yours it uses 'file'). These differences cause xdg-mime to use gedit in the end on your system.

Comment 10 Christophe Fergeau 2014-02-26 10:12:16 UTC
Moving the bug back to ON_QA as per comment #8

Comment 11 Christophe Fergeau 2014-02-26 10:15:56 UTC
Hmm, seems I'm confused about the state of this bug, seems the fix was not added to the rhel7 .spec file yet, moving back to NEW.

Comment 12 Christophe Fergeau 2014-03-12 15:39:25 UTC
Moving the bug to POST, the patch from comment #0 must be added to the RHEL package.

Comment 14 Jonathon Jongsma 2014-07-08 21:14:33 UTC
(In reply to Christophe Fergeau from comment #12)
> Moving the bug to POST, the patch from comment #0 must be added to the RHEL
> package.

Which will happen automatically when we rebase to 0.6.0

Comment 16 zhoujunqin 2014-07-23 10:09:46 UTC
(In reply to Christophe Fergeau from comment #9)
> (In reply to CongDong from comment #8)
> > As you said it's not an issue of virt-viewer, should I file a new xdg-mime
> > bug?
> 
> Thanks for the additional testing! You can file an xdg-mime bug, but it's
> possible that it's the best it can do on your system. On my system it
> manages to detect a GNOME desktop even over ssh, it uses gvfs-info to get
> the file mime type (on yours it uses 'file'). These differences cause
> xdg-mime to use gedit in the end on your system.

codong file a bug:
https://bugzilla.redhat.com/show_bug.cgi?id=1122447

Comment 19 zhoujunqin 2014-08-07 08:31:25 UTC
Christophe Fergeau, thanks for your help and suggestion.

With following verify steps, i can move this bug to verified.
package version:
virt-viewer-0.6.0-3.el7.x86_64

verify steps:
non-ssh 
1. Download the vv file
2. # xdg-open console.vv
The console.vv file opened with remote-viewer successfully.

over-ssh
1.Download the vv file
2.# xdg-open console.vv
The console.vv file opened with gedit.
this is the same issue with bug bug 1122447.

Try with KDE:
# XDG_CURRENT_DESKTOP=KDE  xdg-open console.vv
The console.vv file opened with remote-viewer successfully.

Try with GNOME:
# XDG_CURRENT_DESKTOP=GNOME  xdg-open console.vv
The console.vv file opened with remote-viewer successfully.

and confirmed with Christophe Fergeau about above steps, that's enough to verify this bug.

Comment 21 errata-xmlrpc 2015-03-05 13:38:54 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://rhn.redhat.com/errata/RHBA-2015-0295.html