[qubes-users] xdg-open works in dvm, but qvm-open-in-dvm from other qube does not

Hi, I've been trying to get a dvm to open media files in mplayer in a disposable qube.
Starting the disposable media qube from dom0 with qvm-run --dispvm media-dvm --service -- qubes.StartApp+st works.
Copying files(same as the ones used to test qvm-open-in-vm/qvm-open-in-dvm) to the vm with qvm-copy works.
Opening the copied files with xdg-open or qubes-open works in the dvm.
Opening media files in mplayer in the disposable qube with qvm-open-in-dvm used to work.
It stopped working after I switched the media qube's template from debian-11-minimal to debian-12-minimal.
I used qubesctl with state.highstate to get the new template to be in the same state as the previous template.
I checked journalctl -f in the media dvm while running qvm-open-in-vm from the vm that usually calls qvm-open-in-dvm.
The media dvm consistently gives the same errors:
May 01 10:04:54 disp7040 systemctl[914]: Failed to connect to bus: No medium found
May 01 10:04:56 disp7040 qubes.OpenInVM+-browse-disp[925]: cat: write error: Bad file descriptor
May 01 10:04:56 disp7040 qubes.OpenInVM+-browse-disp[925]:
May 01 10:04:56 disp7040 qubes.OpenInVM+-browse-disp[925]:
May 01 10:04:56 disp7040 qubes.OpenInVM+-browse-disp[925]: MPlayer interrupted by signal 13 in module: unknown
This is was using a mplayer binary I built myself.
If I use remove that and let it use a version from apt I get a sligthly different set of errors:
May 01 10:26:46 disp7040 systemctl[1234]: Failed to connect to bus: No medium found
May 01 10:26:48 disp7040 qubes.OpenInVM+-browse-disp[1246]: cat: write error: Bad file descriptor
May 01 10:26:48 disp7040 qubes.OpenInVM+-browse-disp[1246]: do_connect: could not connect to socket
May 01 10:26:48 disp7040 qubes.OpenInVM+-browse-disp[1246]: connect: No such file or directory
May 01 10:26:48 disp7040 qubes.OpenInVM+-browse-disp[1246]: Failed to open LIRC support. You will not be able to use your remote control.
May 01 10:26:48 disp7040 qubes.OpenInVM+-browse-disp[1246]:
May 01 10:26:48 disp7040 qubes.OpenInVM+-browse-disp[1246]:
May 01 10:26:48 disp7040 qubes.OpenInVM+-browse-disp[1246]: MPlayer interrupted by signal 13 in module: unknown
The vm that calls qvm-open-in-dvm can successfully open media files in other vms.
Thanks in advance for any ideas you might have.

Hi, I've been trying to get a dvm to open media files in mplayer in a
disposable qube. Starting the disposable media qube from dom0 with
qvm-run --dispvm media-dvm --service -- qubes.StartApp+st works.
Copying files(same as the ones used to test
qvm-open-in-vm/qvm-open-in-dvm) to the vm with qvm-copy works.
Opening the copied files with xdg-open or qubes-open works in the
dvm. Opening media files in mplayer in the disposable qube with
qvm-open-in-dvm used to work.

Same here.

It stopped working after I switched the media qube's template from
debian-11-minimal to debian-12-minimal.

I am not sure if that per se is the reason. It used to work for me in
debian-12-minimal too.

Here is what I get when I "Open in VM" a text file (VM is based on
debian-12-minimal with thunar, xpdf and mpv installed).

[ 277.623816] systemctl[1176]: Failed to connect to bus: No medium found
[ 277.649127] qubes.OpenInVM+-storage[1187]: xdg-mime: mimetype argument missing
[ 277.649430] qubes.OpenInVM+-storage[1187]: Try 'xdg-mime --help' for more information.
[ 277.678605] qubes.OpenInVM+-storage[1187]: /usr/bin/xdg-open: 882: x-www-browser: not found
[ 277.679554] qubes.OpenInVM+-storage[1187]: /usr/bin/xdg-open: 882: firefox: not found
[ 277.680597] qubes.OpenInVM+-storage[1187]: /usr/bin/xdg-open: 882: iceweasel: not found
[ 277.681603] qubes.OpenInVM+-storage[1187]: /usr/bin/xdg-open: 882: seamonkey: not found
[ 277.682573] qubes.OpenInVM+-storage[1187]: /usr/bin/xdg-open: 882: mozilla: not found
[ 277.683527] qubes.OpenInVM+-storage[1187]: /usr/bin/xdg-open: 882: epiphany: not found
[ 277.684437] qubes.OpenInVM+-storage[1187]: /usr/bin/xdg-open: 882: konqueror: not found
[ 277.685364] qubes.OpenInVM+-storage[1187]: /usr/bin/xdg-open: 882: chromium: not found
[ 277.686320] qubes.OpenInVM+-storage[1187]: /usr/bin/xdg-open: 882: chromium-browser: not found
[ 277.687446] qubes.OpenInVM+-storage[1187]: /usr/bin/xdg-open: 882: google-chrome: not found
[ 277.688471] qubes.OpenInVM+-storage[1187]: /usr/bin/xdg-open: 882: www-browser: not found
[ 277.689353] qubes.OpenInVM+-storage[1187]: /usr/bin/xdg-open: 882: links2: not found
[ 277.690593] qubes.OpenInVM+-storage[1187]: /usr/bin/xdg-open: 882: elinks: not found
[ 277.691631] qubes.OpenInVM+-storage[1187]: /usr/bin/xdg-open: 882: links: not found
[ 277.692557] qubes.OpenInVM+-storage[1187]: /usr/bin/xdg-open: 882: lynx: not found
[ 277.693781] qubes.OpenInVM+-storage[1187]: /usr/bin/xdg-open: 882: w3m: not found
[ 277.693832] qubes.OpenInVM+-storage[1187]: xdg-open: no method available for opening '/tmp/storage-LVDbTK/TEST.pdf'

Trying to copy the file first and then 'xdg-open TEST.pdf' in the
target VM, I get the same series of errors:

$ xdg-open TEST.pdf
xdg-mime: mimetype argument missing
Try 'xdg-mime --help' for more information.
/usr/bin/xdg-open: 882: x-www-browser: not found
/usr/bin/xdg-open: 882: firefox: not found
/usr/bin/xdg-open: 882: iceweasel: not found
/usr/bin/xdg-open: 882: seamonkey: not found
/usr/bin/xdg-open: 882: mozilla: not found
/usr/bin/xdg-open: 882: epiphany: not found
/usr/bin/xdg-open: 882: konqueror: not found
/usr/bin/xdg-open: 882: chromium: not found
/usr/bin/xdg-open: 882: chromium-browser: not found
/usr/bin/xdg-open: 882: google-chrome: not found
/usr/bin/xdg-open: 882: www-browser: not found
/usr/bin/xdg-open: 882: links2: not found
/usr/bin/xdg-open: 882: elinks: not found
/usr/bin/xdg-open: 882: links: not found
/usr/bin/xdg-open: 882: lynx: not found
/usr/bin/xdg-open: 882: w3m: not found
xdg-open: no method available for opening 'TEST.pdf'

Then I tried this:

but it changed nothing. Tested with an mp4 file - same result.

I can open the files through thunar, where I can set default app for
the type too. However, thunar does not use xdg-open but exo-open.

Next, I looked at the code of xdg-open (it is a shell script) and I saw
it used some form of desktop environment (DE) detection and acted based
on that.

So, to see what exactly happens:

$ bash -x xdg-open TEST.pdf
...
+ DEBUG 2 'Selected DE gnome3'
...
+ open_gnome3 TEST.pdf
+ gio help open
+ gvfs-open --help
+ open_generic TEST.pdf
...

And there it is: xdg-open wrongly detects gnome3 which is not
installed. Then I checked:

$ printenv | grep XDG_CURRENT_DESKTOP
XDG_CURRENT_DESKTOP=X-QUBES ## NOT XFCE, which is the correct value

After:

$ export XDG_CURRENT_DESKTOP=XFCE

xdg-open works as expected in the current session.

To have "Open in VM" work as well, obviously the above must be set
persistently.

Speculation 1 (needs checking and confirmation):

Since I see in a fedora-xfce-template-based qubes the
XDG_CURRENT_DESKTOP=XFCE, I suppose it is somehow set when XFCE itself
is installed (and not just thunar), so perhaps the fact of the Debian
template being "-minimal" (and not "-xfce") is related to this issue
and one needs to set this thing manually to make it work properly.

Speculation 2 (if the above is wrong):

It might be Debian specific.

If you have the time to test these speculations, please post back so
others know too.

Trying to copy the file first and then 'xdg-open TEST.pdf' in the
target VM, I get the same series of errors:

$ xdg-open TEST.pdf
xdg-mime: mimetype argument missing
Try 'xdg-mime --help' for more information.
/usr/bin/xdg-open: 882: x-www-browser: not found
/usr/bin/xdg-open: 882: firefox: not found
/usr/bin/xdg-open: 882: iceweasel: not found
/usr/bin/xdg-open: 882: seamonkey: not found
/usr/bin/xdg-open: 882: mozilla: not found
/usr/bin/xdg-open: 882: epiphany: not found
/usr/bin/xdg-open: 882: konqueror: not found
/usr/bin/xdg-open: 882: chromium: not found
/usr/bin/xdg-open: 882: chromium-browser: not found
/usr/bin/xdg-open: 882: google-chrome: not found
/usr/bin/xdg-open: 882: www-browser: not found
/usr/bin/xdg-open: 882: links2: not found
/usr/bin/xdg-open: 882: elinks: not found
/usr/bin/xdg-open: 882: links: not found
/usr/bin/xdg-open: 882: lynx: not found
/usr/bin/xdg-open: 882: w3m: not found
xdg-open: no method available for opening 'TEST.pdf'

Then I tried this:

files - How to properly and easily configure `xdg-open` without any environment? - Unix & Linux Stack Exchange

but it changed nothing. Tested with an mp4 file - same result.

I did get xdg-open itself to work. Although all the different files and tools confused me a lot.
I added the lines to mimeapps.list directly, although I think xdg-mime default alone worked for me too.
I added a [Added Associations] line with the same entries as [Default Applications].
Not really sure what this does though.
The mimeapps.list file I use is in /etc/xdg/ (global), so I set it from the template.
Sometimes I've had to add a MimeType field (something like MimeType=video/mp4;video/x-matroska;video/webm) to the .desktop file being used, before running xdg-mime, to get it to work.

And there it is: xdg-open wrongly detects gnome3 which is not
installed. Then I checked:

$ printenv | grep XDG_CURRENT_DESKTOP
XDG_CURRENT_DESKTOP=X-QUBES ## NOT XFCE, which is the correct value

XDG_CURRENT_DESKTOP isn't even set for me, I use i3 though

After:

$ export XDG_CURRENT_DESKTOP=XFCE

I added export XDG_CURRENT_DESKTOP=XFCE to my template, shut it down and ran qvm-open-in-dvm to open a file in it.

xdg-open works as expected in the current session.

It started and shut down. I get the same error in journalctl on qvm-open-in-dvm.

To have "Open in VM" work as well, obviously the above must be set
persistently.

Speculation 1 (needs checking and confirmation):

Since I see in a fedora-xfce-template-based qubes the
XDG_CURRENT_DESKTOP=XFCE, I suppose it is somehow set when XFCE itself
is installed (and not just thunar), so perhaps the fact of the Debian
template being "-minimal" (and not "-xfce") is related to this issue
and one needs to set this thing manually to make it work properly.

Speculation 2 (if the above is wrong):

It might be Debian specific.

I downloaded Fedora 39 minimal, it didn't have mplayer, so I tried updating and installing only kmplayer.
It seems to install a lot of plasma, Qt stuff, about 200MB in total.
After installing kmplayer it qvm-open-in-dvm didn't work.
With journalctl in the fedora based vm it shows the same failed to connect to bus error as debian started with.
After that it seems to just give an mime error, like the one you showed earlier.
cat /usr/share/applications/mimeapps.list shows org.gnome.Totem as the default application.
XDG_CURRENT_DESKTOP was set to X-QUBES, as with you.
I copied mimeapps.list to /etc/xdg/ in the template and replaced

I also tried an untouched version of debian 12 minimal with updates and only mplayer added from apt.
There was no mimeapps.list file in /usr/share/applications, /etc/xdg/, $HOME/.config or $HOME/.local/share/applications.
I tried xdg-mime default mplayer.desktop video/x-matroska as the non-root user.
Still didn't work. Maybe because there wasn't a mplayer.desktop file in /usr/share/applications like in fedora.
I copy over mplayer.desktop without a MimeType field from the original debian 12 miminal media qube and move it to $HOME/.local/share/applications.
This gives the same error as the original media qube.
I add MimeType=video/x-matroska to the desktop file and re-run the xdg-mime command.
I still get the same error.

That's secondary, but in case you are interested, mpv gives better playback:

It does not seem to play back better to me, as well at most, especially not with the aggressive frame-dropping that is turned on by default.
It's even more aggressive than setting framedropping to hard on mplayer.
I decided to use --framedrop=no to have it get more out of sync instead.
Thank you for the suggestion though, I might decide to switch to mpv.