浏览代码

SystemServer: Change group ownership on all framebuffer devices

WindowServer was not able to utilize any other framebuffer device in the
/dev directory due to wrong group ownership of other framebuffer
devices. Therefore we need to ensure that when SystemServer starts,
it checks all directory entries in /dev, searching for framebuffer
devices, and then apply the correct ownership for them.
Liav A 4 年之前
父节点
当前提交
16979bec15
共有 1 个文件被更改,包括 24 次插入1 次删除
  1. 24 1
      Userland/Services/SystemServer/main.cpp

+ 24 - 1
Userland/Services/SystemServer/main.cpp

@@ -9,6 +9,7 @@
 #include <AK/ByteBuffer.h>
 #include <AK/Debug.h>
 #include <LibCore/ConfigFile.h>
+#include <LibCore/DirIterator.h>
 #include <LibCore/Event.h>
 #include <LibCore/EventLoop.h>
 #include <LibCore/File.h>
@@ -82,6 +83,28 @@ static void chown_wrapper(const char* path, uid_t uid, gid_t gid)
     }
 }
 
+static void chown_all_framebuffer_devices(group* phys_group)
+{
+    VERIFY(phys_group);
+    struct stat cur_file_stat;
+
+    Core::DirIterator di("/dev/", Core::DirIterator::SkipParentAndBaseDir);
+    if (di.has_error())
+        VERIFY_NOT_REACHED();
+    while (di.has_next()) {
+        auto entry_name = di.next_full_path();
+        auto rc = stat(entry_name.characters(), &cur_file_stat);
+        if (rc < 0)
+            continue;
+        if (!S_ISBLK(cur_file_stat.st_mode))
+            continue;
+        // FIXME: Try to find a way to not hardcode the major number of framebuffer device nodes.
+        if (major(cur_file_stat.st_rdev) != 29)
+            continue;
+        chown_wrapper(entry_name.characters(), 0, phys_group->gr_gid);
+    }
+}
+
 static void prepare_devfs()
 {
     // FIXME: Find a better way to all of this stuff, without hardcoding all of this!
@@ -113,7 +136,7 @@ static void prepare_devfs()
 
     auto phys_group = getgrnam("phys");
     VERIFY(phys_group);
-    chown_wrapper("/dev/fb0", 0, phys_group->gr_gid);
+    chown_all_framebuffer_devices(phys_group);
 
     chown_wrapper("/dev/keyboard0", 0, phys_group->gr_gid);