[gnome-boxes] util: Better check for bridge network availability
- From: Zeeshan Ali Khattak <zeeshanak src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-boxes] util: Better check for bridge network availability
- Date: Fri, 13 Dec 2013 14:06:05 +0000 (UTC)
commit 69e5ef4a2904220fa80ffd5be9360e7f8e907b12
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date: Fri Dec 13 14:04:37 2013 +0000
util: Better check for bridge network availability
Instead of trying to connect to system libvirt to check if its running,
lets just check if "virbr0" is up or not.
src/Makefile.am | 1 +
src/util-app.vala | 23 ++++++++++++++++++++---
2 files changed, 21 insertions(+), 3 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index cbfec97..da1d380 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -35,6 +35,7 @@ AM_VALAFLAGS = \
--pkg libvirt-gobject-1.0 \
--pkg libxml-2.0 \
--pkg posix \
+ --pkg linux \
--pkg spice-client-gtk-3.0 \
--pkg tracker-sparql-$(TRACKER_VERSION) \
$(VALA_DEBUG_FLAGS) \
diff --git a/src/util-app.vala b/src/util-app.vala
index 616442d..f4e2b54 100644
--- a/src/util-app.vala
+++ b/src/util-app.vala
@@ -1,6 +1,7 @@
// This file is part of GNOME Boxes. License: LGPLv2+
using Gtk;
using Xml;
+using Linux;
namespace Boxes {
@@ -244,11 +245,27 @@ namespace Boxes {
if (libvirt_bridge_net_checked)
return libvirt_bridge_net_available;
- var connection = new GVir.Connection ("qemu:///system");
-
try {
- connection.open_read_only ();
+ // First check if bridge interface is up
+ var sock = Posix.socket (Posix.AF_INET, Posix.SOCK_STREAM, 0);
+ if (sock < 0)
+ throw (GLib.IOError) new GLib.Error (G_IO_ERROR,
+ g_io_error_from_errno (Posix.errno),
+ "Failed to create a socket");
+
+ var req = Network.IfReq ();
+ var if_name = "virbr0";
+ for (var i = 0; i <= if_name.length; i++)
+ req.ifr_name[i] = (char) if_name[i];
+
+ if (Posix.ioctl (sock, Network.SIOCGIFFLAGS, ref req) < 0 ||
+ !(Network.IfFlag.UP in req.ifr_flags)) {
+ debug ("Interface '%s' is either not available or not up.", if_name);
+
+ return false;
+ }
+ // Now check if unprivileged qemu is allowed to access it
var file = File.new_for_path ("/etc/qemu/bridge.conf");
uint8[] contents;
file.load_contents (null, out contents, null);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]