diff --git a/Userland/Services/KeyboardPreferenceLoader/CMakeLists.txt b/Userland/Services/KeyboardPreferenceLoader/CMakeLists.txt index a2a9000d4b..2335cae261 100644 --- a/Userland/Services/KeyboardPreferenceLoader/CMakeLists.txt +++ b/Userland/Services/KeyboardPreferenceLoader/CMakeLists.txt @@ -9,4 +9,4 @@ set(SOURCES ) serenity_bin(KeyboardPreferenceLoader) -target_link_libraries(KeyboardPreferenceLoader LibCore) +target_link_libraries(KeyboardPreferenceLoader LibCore LibMain) diff --git a/Userland/Services/KeyboardPreferenceLoader/main.cpp b/Userland/Services/KeyboardPreferenceLoader/main.cpp index 17413ef1a3..16d2aec79d 100644 --- a/Userland/Services/KeyboardPreferenceLoader/main.cpp +++ b/Userland/Services/KeyboardPreferenceLoader/main.cpp @@ -6,41 +6,23 @@ #include #include +#include +#include #include #include #include #include #include -int main() +ErrorOr serenity_main(Main::Arguments) { - if (pledge("stdio proc exec rpath", nullptr) < 0) { - perror("pledge"); - return 1; - } - + TRY(Core::System::pledge("stdio proc exec rpath")); auto keyboard_settings_config = Core::ConfigFile::open_for_app("KeyboardSettings"); - if (unveil("/bin/keymap", "x") < 0) { - perror("unveil /bin/keymap"); - return 1; - } - - if (unveil("/etc/Keyboard.ini", "r") < 0) { - perror("unveil /etc/Keyboard.ini"); - return 1; - } - - if (unveil("/dev/keyboard0", "r") < 0) { - perror("unveil /dev/keyboard0"); - return 1; - } - - if (unveil(nullptr, nullptr) < 0) { - perror("unveil"); - return 1; - } - + TRY(Core::System::unveil("/bin/keymap", "x")); + TRY(Core::System::unveil("/etc/Keyboard.ini", "r")); + TRY(Core::System::unveil("/dev/keyboard0", "r")); + TRY(Core::System::unveil(nullptr, nullptr)); auto mapper_config(Core::ConfigFile::open("/etc/Keyboard.ini")); auto keymap = mapper_config->read_entry("Mapping", "Keymap", ""); @@ -53,16 +35,13 @@ int main() bool enable_num_lock = keyboard_settings_config->read_bool_entry("StartupEnable", "NumLock", true); - auto keyboard_device_or_error = Core::File::open("/dev/keyboard0", Core::OpenMode::ReadOnly); - if (keyboard_device_or_error.is_error()) { - warnln("Failed to open /dev/keyboard0: {}", keyboard_device_or_error.error()); - VERIFY_NOT_REACHED(); - } - auto keyboard_device = keyboard_device_or_error.release_value(); + auto keyboard_device = TRY(Core::File::open("/dev/keyboard0", Core::OpenMode::ReadOnly)); int rc = ioctl(keyboard_device->fd(), KEYBOARD_IOCTL_SET_NUM_LOCK, enable_num_lock); if (rc < 0) { perror("ioctl(KEYBOARD_IOCTL_SET_NUM_LOCK)"); return 1; } + + return 0; }