[gnome-boxes/check-kvm-user] main, util-app: Add check whether user is in KVM group



commit 2ce9ae0abe8c4892455ad6d928729c9a2c1c6d85
Author: Felipe Borges <felipeborges gnome org>
Date:   Tue Sep 18 15:49:02 2018 +0200

    main, util-app: Add check whether user is in KVM group
    
    We should verify whether the current user is member of the KVM
    group, otherwise VMs might fail to start.
    
    This is exposed by running Boxes with the --checks argument.
    
      $ gnome-boxes --checks
    
    Fixes #225

 src/main.vala     | 2 ++
 src/util-app.vala | 5 +++++
 2 files changed, 7 insertions(+)
---
diff --git a/src/main.vala b/src/main.vala
index ff7e14f3..a83a8b2d 100644
--- a/src/main.vala
+++ b/src/main.vala
@@ -46,6 +46,7 @@ private async void run_checks () {
     var cpu = yield Boxes.check_cpu_vt_capability ();
     var kvm = yield Boxes.check_module_kvm_loaded ();
     var libvirt_kvm = yield Boxes.check_libvirt_kvm ();
+    var kvm_group = yield Boxes.check_user_in_kvm_group ();
     var selinux_context_default = yield Boxes.check_selinux_context_default (out selinux_context_diagnosis);
     var storage_pool = yield Boxes.check_storage_pool (out storage_pool_diagnosis);
 
@@ -53,6 +54,7 @@ private async void run_checks () {
     GLib.stdout.printf (_("• The CPU is capable of virtualization: %s\n").printf (Boxes.yes_no (cpu)));
     GLib.stdout.printf (_("• The KVM module is loaded: %s\n").printf (Boxes.yes_no (kvm)));
     GLib.stdout.printf (_("• Libvirt KVM guest available: %s\n").printf (Boxes.yes_no (libvirt_kvm)));
+    GLib.stdout.printf (_("• User is a member of KVM group: %s\n").printf (Boxes.yes_no (kvm_group)));
     GLib.stdout.printf (_("• Boxes storage pool available: %s\n").printf (Boxes.yes_no (storage_pool)));
     if (storage_pool_diagnosis.length != 0)
         GLib.stdout.printf (Boxes.indent ("    ", storage_pool_diagnosis) + "\n");
diff --git a/src/util-app.vala b/src/util-app.vala
index aba87cfd..c14c8663 100644
--- a/src/util-app.vala
+++ b/src/util-app.vala
@@ -345,6 +345,11 @@ public async bool check_storage_pool (out string diagnosis) {
         return true;
     }
 
+    public async bool check_user_in_kvm_group () {
+        unowned Posix.Group group = Posix.getgrnam ("kvm");
+
+        return (group != null && Posix.group_member (group.gr_gid) == 0);
+    }
 
     // FIXME: Better ways to remove alpha more than welcome
     private Gdk.Pixbuf remove_alpha (Gdk.Pixbuf pixbuf) {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]