diff options
author | Jean-Baptiste Boric <jblbeurope@gmail.com> | 2021-01-24 20:36:22 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-01-24 22:16:18 +0100 |
commit | 76e12a48408c15dae99f5ea3b334a1ccff067502 (patch) | |
tree | 61e2e3d5795a8a021aa55e9b0c02239331317f71 /Userland/Services | |
parent | 491a67ddc496a188ca9f31e976884de75f23c074 (diff) | |
download | serenity-76e12a48408c15dae99f5ea3b334a1ccff067502.zip |
SystemServer: Do not crash if device files are not present
Diffstat (limited to 'Userland/Services')
-rw-r--r-- | Userland/Services/SystemServer/main.cpp | 39 |
1 files changed, 14 insertions, 25 deletions
diff --git a/Userland/Services/SystemServer/main.cpp b/Userland/Services/SystemServer/main.cpp index 2cc0c9166e..a112b996e4 100644 --- a/Userland/Services/SystemServer/main.cpp +++ b/Userland/Services/SystemServer/main.cpp @@ -84,6 +84,14 @@ static void parse_boot_mode() dbgln("Booting in {} mode", g_boot_mode); } +static void chown_wrapper(const char* path, uid_t uid, gid_t gid) +{ + int rc = chown(path, uid, gid); + if (rc < 0 && errno != ENOENT) { + ASSERT_NOT_REACHED(); + } +} + static void prepare_devfs() { // FIXME: Find a better way to all of this stuff, without hardcoding all of this! @@ -109,45 +117,26 @@ static void prepare_devfs() } // FIXME: Find a better way to chown without hardcoding the gid! - // This will fail with ENOENT in text mode. - rc = chown("/dev/fb0", 0, 3); - if (rc < 0 && errno != ENOENT) { - ASSERT_NOT_REACHED(); - } + chown_wrapper("/dev/fb0", 0, 3); // FIXME: Find a better way to chown without hardcoding the gid! - rc = chown("/dev/keyboard", 0, 3); - if (rc < 0) { - ASSERT_NOT_REACHED(); - } + chown_wrapper("/dev/keyboard", 0, 3); // FIXME: Find a better way to chown without hardcoding the gid! - rc = chown("/dev/mouse", 0, 3); - if (rc < 0) { - ASSERT_NOT_REACHED(); - } + chown_wrapper("/dev/mouse", 0, 3); for (size_t index = 0; index < 4; index++) { // FIXME: Find a better way to chown without hardcoding the gid! - rc = chown(String::formatted("/dev/tty{}", index).characters(), 0, 2); - if (rc < 0) { - ASSERT_NOT_REACHED(); - } + chown_wrapper(String::formatted("/dev/tty{}", index).characters(), 0, 2); } for (size_t index = 0; index < 4; index++) { // FIXME: Find a better way to chown without hardcoding the gid! - rc = chown(String::formatted("/dev/ttyS{}", index).characters(), 0, 2); - if (rc < 0) { - ASSERT_NOT_REACHED(); - } + chown_wrapper(String::formatted("/dev/ttyS{}", index).characters(), 0, 2); } // FIXME: Find a better way to chown without hardcoding the gid! - rc = chown("/dev/audio", 0, 4); - if (rc < 0) { - ASSERT_NOT_REACHED(); - } + chown_wrapper("/dev/audio", 0, 4); rc = symlink("/proc/self/fd/0", "/dev/stdin"); if (rc < 0) { |