Serenity Operating System
at master 45 lines 1.6 kB view raw
1/* 2 * Copyright (c) 2021, the SerenityOS developers. 3 * 4 * SPDX-License-Identifier: BSD-2-Clause 5 */ 6 7#include <LibCore/ConfigFile.h> 8#include <LibCore/DeprecatedFile.h> 9#include <LibCore/System.h> 10#include <LibMain/Main.h> 11#include <errno.h> 12#include <spawn.h> 13#include <stdio.h> 14#include <sys/ioctl.h> 15#include <unistd.h> 16 17ErrorOr<int> serenity_main(Main::Arguments) 18{ 19 TRY(Core::System::pledge("stdio proc exec rpath cpath")); 20 auto keyboard_settings_config = TRY(Core::ConfigFile::open_for_app("KeyboardSettings")); 21 22 TRY(Core::System::unveil("/bin/keymap", "x")); 23 TRY(Core::System::unveil("/etc/Keyboard.ini", "r")); 24 TRY(Core::System::unveil("/dev/input/keyboard/0", "r")); 25 TRY(Core::System::unveil(nullptr, nullptr)); 26 auto mapper_config = TRY(Core::ConfigFile::open("/etc/Keyboard.ini")); 27 auto keymaps = mapper_config->read_entry("Mapping", "Keymaps", ""); 28 29 auto keymaps_vector = keymaps.split(','); 30 if (keymaps_vector.size() == 0) 31 exit(1); 32 33 pid_t child_pid; 34 char const* argv[] = { "/bin/keymap", "-m", keymaps_vector.first().characters(), nullptr }; 35 if ((errno = posix_spawn(&child_pid, "/bin/keymap", nullptr, nullptr, const_cast<char**>(argv), environ))) { 36 perror("posix_spawn"); 37 exit(1); 38 } 39 40 bool enable_num_lock = keyboard_settings_config->read_bool_entry("StartupEnable", "NumLock", true); 41 auto keyboard_device = TRY(Core::DeprecatedFile::open("/dev/input/keyboard/0", Core::OpenMode::ReadOnly)); 42 TRY(Core::System::ioctl(keyboard_device->fd(), KEYBOARD_IOCTL_SET_NUM_LOCK, enable_num_lock)); 43 44 return 0; 45}