From 16979bec15afbd9b7b6c4a3dbd6474780e3bbbb5 Mon Sep 17 00:00:00 2001 From: Liav A Date: Fri, 6 Aug 2021 14:01:03 +0300 Subject: [PATCH] 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. --- Userland/Services/SystemServer/main.cpp | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/Userland/Services/SystemServer/main.cpp b/Userland/Services/SystemServer/main.cpp index d705d83248..15097733fc 100644 --- a/Userland/Services/SystemServer/main.cpp +++ b/Userland/Services/SystemServer/main.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -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);