diff options
author | Andreas Kling <kling@serenityos.org> | 2021-11-29 21:22:07 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-11-30 23:34:40 +0100 |
commit | 2bb27184b4eb14621a957318fe5659af462b00be (patch) | |
tree | 4a39f94ff714ece990de13f948a245ef4dd35449 /Userland | |
parent | fbeebce4e39fbe8ef9a7f01fec28ccee44952d81 (diff) | |
download | serenity-2bb27184b4eb14621a957318fe5659af462b00be.zip |
KeyboardPreferenceLoader: Port to LibMain :^)
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Services/KeyboardPreferenceLoader/CMakeLists.txt | 2 | ||||
-rw-r--r-- | Userland/Services/KeyboardPreferenceLoader/main.cpp | 43 |
2 files changed, 12 insertions, 33 deletions
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 <LibCore/ConfigFile.h> #include <LibCore/File.h> +#include <LibCore/System.h> +#include <LibMain/Main.h> #include <errno.h> #include <spawn.h> #include <stdio.h> #include <sys/ioctl.h> #include <unistd.h> -int main() +ErrorOr<int> 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; } |