2.42.9-1
[arch-packages.git] / xf86-video-vesa / trunk / 0001-Refuse-to-run-if-framebuffer-or-dri-devices-are-pres.patch
blob52f0bdf83d99e9aad99d44a222df1be6af787638
1 From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2 From: Jocelyn Falempe <jfalempe@redhat.com>
3 Date: Thu, 14 Apr 2022 14:39:37 +0200
4 Subject: [PATCH] Refuse to run if framebuffer or dri devices are present
6 The simpledrm driver, introduced in kernel 5.14,
7 can replace efifb to provide the efi framebuffer.
9 This fixes a bug on Fedora 36 (first version to use simpledrm driver):
10 https://bugzilla.redhat.com/show_bug.cgi?id=2074789
12 v2: check for framebuffer or dri devices instead of efi framebuffer interface.
14 Reviewed-by: Adam Jackson <ajax@redhat.com>
15 Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>
16 Signed-off-by: Jocelyn Falempe <jfalempe@redhat.com>
17 ---
18 src/vesa.c | 39 ++++++++++++++++++++++++++++++++++-----
19 1 file changed, 34 insertions(+), 5 deletions(-)
21 diff --git a/src/vesa.c b/src/vesa.c
22 index b2a1922c2332..2bf18e9f278c 100644
23 --- a/src/vesa.c
24 +++ b/src/vesa.c
25 @@ -44,6 +44,7 @@
27 #include <string.h>
28 #include <unistd.h>
29 +#include <dirent.h>
30 #include "vesa.h"
32 /* All drivers initialising the SW cursor need this */
33 @@ -439,22 +440,50 @@ VESAInitScrn(ScrnInfoPtr pScrn)
34 pScrn->FreeScreen = VESAFreeScreen;
37 +#ifdef XSERVER_LIBPCIACCESS
38 +#ifdef __linux__
39 +/*
40 + * check if a file exist in directory
41 + * should be equivalent to a glob ${directory}/${prefix}*
42 + */
44 +static Bool
45 +VESAFileExistsPrefix(const char *directory, const char *prefix) {
46 + DIR *dir;
47 + struct dirent *entry;
48 + Bool found = FALSE;
49 + int len = strlen(prefix);
51 + dir = opendir(directory);
52 + if (!dir)
53 + return FALSE;
55 + while ((entry = readdir(dir)) != NULL) {
56 + if (strlen(entry->d_name) > len &&
57 + !memcmp(entry->d_name, prefix, len)) {
58 + found = TRUE;
59 + break;
60 + }
61 + }
62 + closedir(dir);
63 + return found;
65 +#endif
68 * This function is called once, at the start of the first server generation to
69 * do a minimal probe for supported hardware.
72 -#ifdef XSERVER_LIBPCIACCESS
73 static Bool
74 VESAPciProbe(DriverPtr drv, int entity_num, struct pci_device *dev,
75 intptr_t match_data)
77 ScrnInfoPtr pScrn;
79 #ifdef __linux__
80 - if (access("/sys/devices/platform/efi-framebuffer.0", F_OK) == 0 ||
81 - access("/sys/devices/platform/efifb.0", F_OK) == 0) {
82 - ErrorF("vesa: Refusing to run on UEFI\n");
83 + if (VESAFileExistsPrefix("/dev", "fb") ||
84 + VESAFileExistsPrefix("/dev/dri", "card")) {
85 + ErrorF("vesa: Refusing to run, Framebuffer or dri device present\n");
86 return FALSE;
88 #endif