Blame SOURCES/0001-device-manager-fall-back-to-text-mode-if-graphical-d.patch

ff86aa
From 6cffa8daaca920f1d57da40d93ff112f5f096ae9 Mon Sep 17 00:00:00 2001
ff86aa
From: Ray Strode <rstrode@redhat.com>
ff86aa
Date: Tue, 7 Nov 2017 13:49:30 -0500
ff86aa
Subject: [PATCH] device-manager: fall back to text mode if graphical devices
ff86aa
 fail
ff86aa
ff86aa
Right now we assume if we find a /dev/dri/card0 that it will work.
ff86aa
That may not be true. The proprietary nvidia driver, for instance,
ff86aa
provides /dev/dri/card0 but disables modesetting by default.
ff86aa
ff86aa
This commit makes sure we fall back to text mode if /dev/dri/card0
ff86aa
is insufficient for our needs.
ff86aa
---
ff86aa
 src/libply-splash-core/ply-device-manager.c | 25 ++++++++++++++-----------
ff86aa
 1 file changed, 14 insertions(+), 11 deletions(-)
ff86aa
ff86aa
diff --git a/src/libply-splash-core/ply-device-manager.c b/src/libply-splash-core/ply-device-manager.c
ff86aa
index 14d7616..3a2db06 100644
ff86aa
--- a/src/libply-splash-core/ply-device-manager.c
ff86aa
+++ b/src/libply-splash-core/ply-device-manager.c
ff86aa
@@ -14,61 +14,61 @@
ff86aa
  *
ff86aa
  * You should have received a copy of the GNU General Public License
ff86aa
  * along with this program; if not, write to the Free Software
ff86aa
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
ff86aa
  * 02111-1307, USA.
ff86aa
  */
ff86aa
 #include "config.h"
ff86aa
 #include "ply-device-manager.h"
ff86aa
 
ff86aa
 #include <assert.h>
ff86aa
 #include <fcntl.h>
ff86aa
 #include <stdbool.h>
ff86aa
 #include <stdlib.h>
ff86aa
 #include <stdio.h>
ff86aa
 #include <string.h>
ff86aa
 #include <sys/inotify.h>
ff86aa
 #include <sys/stat.h>
ff86aa
 #include <sys/types.h>
ff86aa
 
ff86aa
 #include <libudev.h>
ff86aa
 
ff86aa
 #include "ply-logger.h"
ff86aa
 #include "ply-event-loop.h"
ff86aa
 #include "ply-hashtable.h"
ff86aa
 #include "ply-list.h"
ff86aa
 #include "ply-utils.h"
ff86aa
 
ff86aa
 #define SUBSYSTEM_DRM "drm"
ff86aa
 #define SUBSYSTEM_FRAME_BUFFER "graphics"
ff86aa
 
ff86aa
-static void create_devices_for_terminal_and_renderer_type (ply_device_manager_t *manager,
ff86aa
+static bool create_devices_for_terminal_and_renderer_type (ply_device_manager_t *manager,
ff86aa
                                                            const char           *device_path,
ff86aa
                                                            ply_terminal_t       *terminal,
ff86aa
                                                            ply_renderer_type_t   renderer_type);
ff86aa
 struct _ply_device_manager
ff86aa
 {
ff86aa
   ply_device_manager_flags_t  flags;
ff86aa
   ply_event_loop_t           *loop;
ff86aa
   ply_hashtable_t            *terminals;
ff86aa
   ply_hashtable_t            *renderers;
ff86aa
   ply_terminal_t             *local_console_terminal;
ff86aa
   ply_list_t                 *keyboards;
ff86aa
   ply_list_t                 *text_displays;
ff86aa
   ply_list_t                 *pixel_displays;
ff86aa
   struct udev                *udev_context;
ff86aa
   struct udev_queue          *udev_queue;
ff86aa
   int                         udev_queue_fd;
ff86aa
   ply_fd_watch_t             *udev_queue_fd_watch;
ff86aa
   struct udev_monitor        *udev_monitor;
ff86aa
 
ff86aa
   ply_keyboard_added_handler_t         keyboard_added_handler;
ff86aa
   ply_keyboard_removed_handler_t       keyboard_removed_handler;
ff86aa
   ply_pixel_display_added_handler_t    pixel_display_added_handler;
ff86aa
   ply_pixel_display_removed_handler_t  pixel_display_removed_handler;
ff86aa
   ply_text_display_added_handler_t     text_display_added_handler;
ff86aa
   ply_text_display_removed_handler_t   text_display_removed_handler;
ff86aa
   void                                *event_handler_data;
ff86aa
 
ff86aa
   uint32_t                    local_console_managed : 1;
ff86aa
   uint32_t                    local_console_is_text : 1;
ff86aa
   uint32_t                    serial_consoles_detected : 1;
ff86aa
@@ -134,110 +134,112 @@ fb_device_has_drm_device (ply_device_manager_t *manager,
ff86aa
 
ff86aa
   /* there should only ever be at most one match so we don't iterate through
ff86aa
    * the list, but just look at the first entry */
ff86aa
   card_entry = udev_enumerate_get_list_entry (card_matches);
ff86aa
 
ff86aa
   if (card_entry != NULL)
ff86aa
     {
ff86aa
       struct udev_device *card_device = NULL;
ff86aa
       const char *card_node;
ff86aa
       const char *card_path;
ff86aa
 
ff86aa
       card_path = udev_list_entry_get_name (card_entry);
ff86aa
       card_device = udev_device_new_from_syspath (manager->udev_context, card_path);
ff86aa
       card_node = udev_device_get_devnode (card_device);
ff86aa
       if (card_node != NULL && drm_device_in_use (manager, card_node))
ff86aa
         has_drm_device = true;
ff86aa
       else
ff86aa
         ply_trace ("no card node!");
ff86aa
 
ff86aa
       udev_device_unref (card_device);
ff86aa
     }
ff86aa
   else
ff86aa
     {
ff86aa
       ply_trace ("no card entry!");
ff86aa
     }
ff86aa
 
ff86aa
   udev_enumerate_unref (card_matches);
ff86aa
   return has_drm_device;
ff86aa
 }
ff86aa
 
ff86aa
-static void
ff86aa
+static bool
ff86aa
 create_devices_for_udev_device (ply_device_manager_t *manager,
ff86aa
                                 struct udev_device   *device)
ff86aa
 {
ff86aa
   const char *device_path;
ff86aa
+  bool created = false;
ff86aa
 
ff86aa
   device_path = udev_device_get_devnode (device);
ff86aa
 
ff86aa
   if (device_path != NULL)
ff86aa
     {
ff86aa
       const char *subsystem;
ff86aa
 
ff86aa
       ply_renderer_type_t renderer_type = PLY_RENDERER_TYPE_NONE;
ff86aa
 
ff86aa
       subsystem = udev_device_get_subsystem (device);
ff86aa
       ply_trace ("device subsystem is %s", subsystem);
ff86aa
 
ff86aa
       if (subsystem != NULL && strcmp (subsystem, SUBSYSTEM_DRM) == 0)
ff86aa
         {
ff86aa
           ply_trace ("found DRM device %s", device_path);
ff86aa
           renderer_type = PLY_RENDERER_TYPE_DRM;
ff86aa
         }
ff86aa
       else if (strcmp (subsystem, SUBSYSTEM_FRAME_BUFFER) == 0)
ff86aa
         {
ff86aa
           ply_trace ("found frame buffer device %s", device_path);
ff86aa
           if (!fb_device_has_drm_device (manager, device))
ff86aa
             {
ff86aa
               renderer_type = PLY_RENDERER_TYPE_FRAME_BUFFER;
ff86aa
             }
ff86aa
           else
ff86aa
             {
ff86aa
               ply_trace ("ignoring, since there's a DRM device associated with it");
ff86aa
             }
ff86aa
         }
ff86aa
 
ff86aa
       if (renderer_type != PLY_RENDERER_TYPE_NONE)
ff86aa
         {
ff86aa
           ply_terminal_t *terminal = NULL;
ff86aa
 
ff86aa
           if (!manager->local_console_managed)
ff86aa
             {
ff86aa
               terminal = manager->local_console_terminal;
ff86aa
             }
ff86aa
 
ff86aa
-          create_devices_for_terminal_and_renderer_type (manager,
ff86aa
-                                                         device_path,
ff86aa
-                                                         terminal,
ff86aa
-                                                         renderer_type);
ff86aa
+          created = create_devices_for_terminal_and_renderer_type (manager,
ff86aa
+                                                                   device_path,
ff86aa
+                                                                   terminal,
ff86aa
+                                                                   renderer_type);
ff86aa
        }
ff86aa
     }
ff86aa
+    return created;
ff86aa
 }
ff86aa
 
ff86aa
 static void
ff86aa
 free_displays_for_renderer (ply_device_manager_t *manager,
ff86aa
                             ply_renderer_t       *renderer)
ff86aa
 {
ff86aa
   ply_list_node_t *node;
ff86aa
 
ff86aa
   node = ply_list_get_first_node (manager->pixel_displays);
ff86aa
   while (node != NULL)
ff86aa
     {
ff86aa
       ply_list_node_t *next_node;
ff86aa
       ply_pixel_display_t *display;
ff86aa
       ply_renderer_t *display_renderer;
ff86aa
 
ff86aa
       display = ply_list_node_get_data (node);
ff86aa
       next_node = ply_list_get_next_node (manager->pixel_displays, node);
ff86aa
       display_renderer = ply_pixel_display_get_renderer (display);
ff86aa
 
ff86aa
       if (display_renderer == renderer)
ff86aa
         {
ff86aa
           if (manager->pixel_display_removed_handler != NULL)
ff86aa
             manager->pixel_display_removed_handler (manager->event_handler_data, display);
ff86aa
 
ff86aa
           ply_pixel_display_free (display);
ff86aa
           ply_list_remove_node (manager->pixel_displays, node);
ff86aa
         }
ff86aa
 
ff86aa
       node = next_node;
ff86aa
     }
ff86aa
@@ -300,62 +302,61 @@ create_devices_for_subsystem (ply_device_manager_t *manager,
ff86aa
       const char *path;
ff86aa
 
ff86aa
       path = udev_list_entry_get_name (entry);
ff86aa
 
ff86aa
       if (path == NULL)
ff86aa
         {
ff86aa
           ply_trace ("path was null!");
ff86aa
           continue;
ff86aa
         }
ff86aa
 
ff86aa
       ply_trace ("found device %s", path);
ff86aa
 
ff86aa
       device = udev_device_new_from_syspath (manager->udev_context, path);
ff86aa
 
ff86aa
       /* if device isn't fully initialized, we'll get an add event later
ff86aa
        */
ff86aa
       if (udev_device_get_is_initialized (device))
ff86aa
         {
ff86aa
           ply_trace ("device is initialized");
ff86aa
 
ff86aa
           /* We only care about devices assigned to a (any) seat. Floating
ff86aa
            * devices should be ignored.
ff86aa
            */
ff86aa
           if (udev_device_has_tag (device, "seat"))
ff86aa
             {
ff86aa
               const char *node;
ff86aa
               node = udev_device_get_devnode (device);
ff86aa
               if (node != NULL)
ff86aa
                 {
ff86aa
                   ply_trace ("found node %s", node);
ff86aa
-                  found_device = true;
ff86aa
-                  create_devices_for_udev_device (manager, device);
ff86aa
+                  found_device = create_devices_for_udev_device (manager, device);
ff86aa
                 }
ff86aa
             }
ff86aa
           else
ff86aa
             {
ff86aa
               ply_trace ("device doesn't have a seat tag");
ff86aa
             }
ff86aa
         }
ff86aa
       else
ff86aa
         {
ff86aa
           ply_trace ("it's not initialized");
ff86aa
         }
ff86aa
 
ff86aa
       udev_device_unref (device);
ff86aa
     }
ff86aa
 
ff86aa
   udev_enumerate_unref (matches);
ff86aa
 
ff86aa
   return found_device;
ff86aa
 }
ff86aa
 
ff86aa
 static void
ff86aa
 on_udev_event (ply_device_manager_t *manager)
ff86aa
 {
ff86aa
   struct udev_device *device;
ff86aa
   const char *action;
ff86aa
 
ff86aa
   device = udev_monitor_receive_device (manager->udev_monitor);
ff86aa
   if (device == NULL)
ff86aa
     return;
ff86aa
 
ff86aa
@@ -655,137 +656,139 @@ create_pixel_displays_for_renderer (ply_device_manager_t *manager,
ff86aa
       node = next_node;
ff86aa
     }
ff86aa
 }
ff86aa
 
ff86aa
 static void
ff86aa
 create_text_displays_for_terminal (ply_device_manager_t *manager,
ff86aa
                                    ply_terminal_t       *terminal)
ff86aa
 {
ff86aa
   ply_text_display_t *display;
ff86aa
 
ff86aa
   if (!ply_terminal_is_open (terminal))
ff86aa
     {
ff86aa
       if (!ply_terminal_open (terminal))
ff86aa
         {
ff86aa
           ply_trace ("could not add terminal %s: %m",
ff86aa
                      ply_terminal_get_name (terminal));
ff86aa
           return;
ff86aa
         }
ff86aa
     }
ff86aa
 
ff86aa
   ply_trace ("adding text display for terminal %s",
ff86aa
              ply_terminal_get_name (terminal));
ff86aa
 
ff86aa
   display = ply_text_display_new (terminal);
ff86aa
   ply_list_append_data (manager->text_displays, display);
ff86aa
 
ff86aa
   if (manager->text_display_added_handler != NULL)
ff86aa
     manager->text_display_added_handler (manager->event_handler_data, display);
ff86aa
 }
ff86aa
 
ff86aa
-static void
ff86aa
+static bool
ff86aa
 create_devices_for_terminal_and_renderer_type (ply_device_manager_t *manager,
ff86aa
                                                const char           *device_path,
ff86aa
                                                ply_terminal_t       *terminal,
ff86aa
                                                ply_renderer_type_t   renderer_type)
ff86aa
 {
ff86aa
   ply_renderer_t *renderer = NULL;
ff86aa
   ply_keyboard_t *keyboard = NULL;
ff86aa
 
ff86aa
   renderer = ply_hashtable_lookup (manager->renderers, (void *) device_path);
ff86aa
 
ff86aa
   if (renderer != NULL)
ff86aa
     {
ff86aa
       ply_trace ("ignoring device %s since it's already managed",
ff86aa
                  device_path);
ff86aa
-      return;
ff86aa
+      return true;
ff86aa
     }
ff86aa
 
ff86aa
   ply_trace ("creating devices for %s (renderer type: %u) (terminal: %s)",
ff86aa
              device_path? : "", renderer_type, terminal? ply_terminal_get_name (terminal): "none");
ff86aa
 
ff86aa
   if (renderer_type != PLY_RENDERER_TYPE_NONE)
ff86aa
     {
ff86aa
       renderer = ply_renderer_new (renderer_type, device_path, terminal);
ff86aa
 
ff86aa
       if (!ply_renderer_open (renderer))
ff86aa
         {
ff86aa
           ply_trace ("could not open renderer for %s", device_path);
ff86aa
           ply_renderer_free (renderer);
ff86aa
           renderer = NULL;
ff86aa
           if (renderer_type != PLY_RENDERER_TYPE_AUTO)
ff86aa
-            return;
ff86aa
+            return false;
ff86aa
         }
ff86aa
     }
ff86aa
 
ff86aa
   if (renderer != NULL)
ff86aa
     {
ff86aa
       keyboard = ply_keyboard_new_for_renderer (renderer);
ff86aa
       ply_list_append_data (manager->keyboards, keyboard);
ff86aa
 
ff86aa
       if (manager->keyboard_added_handler != NULL)
ff86aa
         manager->keyboard_added_handler (manager->event_handler_data, keyboard);
ff86aa
 
ff86aa
       ply_hashtable_insert (manager->renderers, strdup (device_path), renderer);
ff86aa
       create_pixel_displays_for_renderer (manager, renderer);
ff86aa
 
ff86aa
       if (manager->renderers_activated)
ff86aa
         {
ff86aa
           ply_trace ("activating renderer");
ff86aa
           ply_renderer_activate (renderer);
ff86aa
         }
ff86aa
     }
ff86aa
   else if (terminal != NULL)
ff86aa
     {
ff86aa
       keyboard = ply_keyboard_new_for_terminal (terminal);
ff86aa
       ply_list_append_data (manager->keyboards, keyboard);
ff86aa
 
ff86aa
       if (manager->keyboard_added_handler != NULL)
ff86aa
         manager->keyboard_added_handler (manager->event_handler_data, keyboard);
ff86aa
     }
ff86aa
 
ff86aa
   if (terminal != NULL)
ff86aa
     {
ff86aa
       create_text_displays_for_terminal (manager, terminal);
ff86aa
 
ff86aa
       if (terminal == manager->local_console_terminal)
ff86aa
         {
ff86aa
           manager->local_console_is_text = renderer == NULL;
ff86aa
           manager->local_console_managed = true;
ff86aa
         }
ff86aa
     }
ff86aa
 
ff86aa
   if (keyboard != NULL && manager->keyboards_activated)
ff86aa
     {
ff86aa
       ply_trace ("activating keyboards");
ff86aa
       ply_keyboard_watch_for_input (keyboard);
ff86aa
     }
ff86aa
+
ff86aa
+  return true;
ff86aa
 }
ff86aa
 
ff86aa
 static void
ff86aa
 create_devices_for_terminal (const char           *device_path,
ff86aa
                              ply_terminal_t       *terminal,
ff86aa
                              ply_device_manager_t *manager)
ff86aa
 {
ff86aa
   create_devices_for_terminal_and_renderer_type (manager,
ff86aa
                                                  device_path,
ff86aa
                                                  terminal,
ff86aa
                                                  PLY_RENDERER_TYPE_NONE);
ff86aa
 }
ff86aa
 static bool
ff86aa
 create_devices_from_terminals (ply_device_manager_t *manager)
ff86aa
 {
ff86aa
   bool has_serial_consoles;
ff86aa
 
ff86aa
   ply_trace ("checking for consoles");
ff86aa
 
ff86aa
   if (manager->flags & PLY_DEVICE_MANAGER_FLAGS_IGNORE_SERIAL_CONSOLES)
ff86aa
     {
ff86aa
       has_serial_consoles = false;
ff86aa
       ply_trace ("ignoring all consoles but default console because explicitly told to.");
ff86aa
     }
ff86aa
   else
ff86aa
     {
ff86aa
       has_serial_consoles = add_consoles_from_file (manager, "/sys/class/tty/console/active");
ff86aa
     }
ff86aa
 
ff86aa
   if (has_serial_consoles)
ff86aa
-- 
ff86aa
2.14.3
ff86aa