[gnome-session] gl-helper: Support reading gnome.fallback value from FreeBSD kenv



commit bf47f850a9611045c22d4a85319c0956ca16ca7a
Author: Ting-Wei Lan <lantw src gnome org>
Date:   Sun Apr 24 16:08:20 2016 +0800

    gl-helper: Support reading gnome.fallback value from FreeBSD kenv
    
    This feature is the same as gnome.fallback kernel argument on Linux.
    FreeBSD users can force the check result of gl-helper to be accelerated
    or non-accelerated by setting gnome.fallback kernel environment variable
    with the bootloader or kenv system call.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=765491

 tools/gnome-session-check-accelerated-gl-helper.c |   34 +++++++++++++++++++++
 1 files changed, 34 insertions(+), 0 deletions(-)
---
diff --git a/tools/gnome-session-check-accelerated-gl-helper.c 
b/tools/gnome-session-check-accelerated-gl-helper.c
index 9a5d505..4be9638 100644
--- a/tools/gnome-session-check-accelerated-gl-helper.c
+++ b/tools/gnome-session-check-accelerated-gl-helper.c
@@ -79,6 +79,10 @@
 
 #include <regex.h>
 
+#ifdef __FreeBSD__
+#include <kenv.h>
+#endif
+
 #include <X11/Xlib.h>
 #include <X11/Xatom.h>
 #include <X11/extensions/Xcomposite.h>
@@ -103,6 +107,7 @@ _print_error (const char *str)
 #define CMDLINE_NON_FALLBACK_FORCED 0
 #define CMDLINE_FALLBACK_FORCED 1
 
+#if defined(__linux__)
 static int
 _parse_kcmdline (void)
 {
@@ -138,6 +143,35 @@ out:
 
         return ret;
 }
+#elif defined(__FreeBSD__)
+static int
+_parse_kcmdline (void)
+{
+        int ret = CMDLINE_UNSET;
+        char value[KENV_MVALLEN];
+
+        /* a compile time check to avoid unexpected stack overflow */
+        _Static_assert(KENV_MVALLEN < 1024 * 1024, "KENV_MVALLEN is too large");
+
+        if (kenv (KENV_GET, "gnome.fallback", value, KENV_MVALLEN) == -1)
+                return ret;
+
+        if (*value != '0' && *value != '1')
+                fprintf (stderr, "gnome-session-is-accelerated: Invalid value '%s' for gnome.fallback passed 
in kernel environment.\n", value);
+        else
+                ret = atoi (value);
+
+        g_debug ("Kernel environment parsed to %d", ret);
+
+        return ret;
+}
+#else
+static int
+_parse_kcmdline (void)
+{
+        return CMDLINE_UNSET;
+}
+#endif
 
 static gboolean
 _has_composite (Display *display)


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