[gnome-session] tools: Look at gnome.fallback argument in kernel boot line



commit a8ccac0ef5074229b562b90dc8dcf183c0440395
Author: Vincent Untz <vuntz gnome org>
Date:   Wed Oct 19 13:14:50 2011 +0200

    tools: Look at gnome.fallback argument in kernel boot line
    
    This is a quick way to let users easily force the fallback (or
    non-fallback mode) with gnome.fallback=0/1 on boot.

 tools/gnome-session-check-accelerated-helper.c |   64 ++++++++++++++++++++++++
 1 files changed, 64 insertions(+), 0 deletions(-)
---
diff --git a/tools/gnome-session-check-accelerated-helper.c b/tools/gnome-session-check-accelerated-helper.c
index 3f83f76..c1b49e2 100644
--- a/tools/gnome-session-check-accelerated-helper.c
+++ b/tools/gnome-session-check-accelerated-helper.c
@@ -70,7 +70,9 @@
 /* for strcasestr */
 #define _GNU_SOURCE
 
+#include <ctype.h>
 #include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
 
 #include <X11/Xlib.h>
@@ -87,6 +89,54 @@ _print_error (const char *str)
 }
 
 static int
+_parse_kcmdline (void)
+{
+        FILE *kcmdline;
+        char *line = NULL;
+        size_t line_len = 0;
+        int ret = -1;
+
+        kcmdline = fopen("/proc/cmdline", "r");
+        if (kcmdline == NULL)
+                return ret;
+
+        while (getline (&line, &line_len, kcmdline) != -1) {
+                const char *arg;
+                const char *str;
+                int key_len = strlen ("gnome.fallback=");
+
+                if (line == NULL)
+                        break;
+
+                /* don't break if we found the argument once: last mention wins */
+
+                str = line;
+                do {
+                        arg = strstr (str, "gnome.fallback=");
+                        str = arg + key_len;
+
+                        if (arg &&
+                                        (arg == line || isspace (arg[-1])) && /* gnome.fallback= is really the beginning of an argument */
+                                        (isdigit (arg[key_len]))) { /* the first character of the value of this argument is an integer */
+                                if ((arg[key_len+1] == '\0' || isspace (arg[key_len+1]))) /* the value of this argument is only one character long */
+                                        ret = arg[key_len] - '0';
+                                else /* invalid value */
+                                        ret = 0xDEAD;
+
+                        }
+                } while (arg != NULL);
+
+                free (line);
+                line = NULL;
+                line_len = 0;
+        }
+
+        fclose (kcmdline);
+
+        return ret;
+}
+
+static int
 _has_composite (Display *display)
 {
         int dummy1, dummy2;
@@ -257,9 +307,23 @@ _is_max_texture_size_big_enough (Display *display)
 int
 main (int argc, char **argv)
 {
+        int      kcmdline_parsed;
         Display *display = NULL;
         int      ret = 1;
 
+        kcmdline_parsed = _parse_kcmdline ();
+        if (kcmdline_parsed >= 0) {
+                if (kcmdline_parsed == 0) {
+                        _print_error ("Non-fallback mode forced by kernel command line.");
+                        ret = 0;
+                        goto out;
+                } else if (kcmdline_parsed == 1) {
+                        _print_error ("Fallback mode forced by kernel command line.");
+                        goto out;
+                } else
+                        _print_error ("Invalid value for gnome.fallback passed in kernel command line.");
+        }
+
         display = XOpenDisplay (NULL);
         if (!display) {
                 _print_error ("No X display.");



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