File virtinst-set-root-audio-to-none.patch of Package virt-manager
From: Antonio Larrosa <alarrosa@suse.com>
Subject: Disable audio when running virt-manager as root
Running virt-manager as root is not something normally should be done, but since
users are doing it, we better disable audio since pulseaudio isn't running anyway.
See bsc#1222762
Index: virt-manager-4.1.0/virtinst/guest.py
===================================================================
--- virt-manager-4.1.0.orig/virtinst/guest.py
+++ virt-manager-4.1.0/virtinst/guest.py
@@ -1173,6 +1173,10 @@ class Guest(XMLBuilder):
dev.set_defaults(self)
self.add_device(dev)
+ dev = DeviceAudio(self.conn)
+ dev.set_defaults(self)
+ self.add_device(dev)
+
def _add_spice_usbredir(self):
if not self.lookup_domcaps().supports_redirdev_usb():
return # pragma: no cover
Index: virt-manager-4.1.0/virtinst/devices/audio.py
===================================================================
--- virt-manager-4.1.0.orig/virtinst/devices/audio.py
+++ virt-manager-4.1.0/virtinst/devices/audio.py
@@ -3,6 +3,7 @@
from .device import Device
from ..xmlbuilder import XMLProperty
+import os
class DeviceAudio(Device):
@@ -10,3 +11,31 @@ class DeviceAudio(Device):
type = XMLProperty("./@type")
id = XMLProperty("./@id")
+
+ def set_defaults(self, guest):
+ if not self.id:
+ self.id = 1
+
+ if not self.type and os.getuid() == 0:
+ # if we're running virt-manager as root, probably pulseaudio is not running
+ # so we better set the audio tag type to "none" (boo#1222762)
+ path = os.environ.get("XDG_RUNTIME_DIR")
+ if not path:
+ path = '/run/user/0'
+ path += '/pulse/native'
+ pa_is_running = False
+ try:
+ st = os.stat(path)
+ except FileNotFoundError:
+ pass
+ else:
+ import stat
+ pa_is_running = stat.S_ISSOCK(st.st_mode)
+
+ if not pa_is_running:
+ self.type = 'none'
+
+ elif not self.type:
+ self.type = "spice"
+
+