diff --git a/main.cc b/main.cc index 0ffa67a..831f9bc 100644 --- a/main.cc +++ b/main.cc @@ -1,3 +1,4 @@ +#include #include //sleep #include //thread #include @@ -53,6 +54,54 @@ void updateThreadKeyboard(LuaScript& lScript) }//while } +bool check_uinput_loaded() +{ + bool uinput_loaded = false; + std::string this_line; + std::string kernel_version; + std::ifstream version_file; + std::ifstream builtin_file; + std::ifstream modules_file; + + version_file.open("/proc/version"); + + // kernel_version is third "word" from version_file + version_file >> kernel_version; + version_file >> kernel_version; + version_file >> kernel_version; + + modules_file.open("/proc/modules"); + if ( modules_file.is_open() ) + { + while ( getline(modules_file, this_line) ) + { + if ( this_line.find("uinput ") == 0 ) + { + uinput_loaded = true; + break; + } + } + modules_file.close(); + } + + builtin_file.open("/lib/modules/" + kernel_version + "/modules.builtin"); + if ( builtin_file.is_open() ) + { + while ( getline(builtin_file, this_line) ) + { + // TODO: modules.builtin CHECK LINE SYNTAX!! + if ( this_line.find("kernel/drivers/input/misc/uinput") == 0 ) + { + uinput_loaded = true; + break; + } + } + builtin_file.close(); + } + + return uinput_loaded; +} + //Called from user via lua script int l_send_keyboard_event(lua_State* L) { @@ -274,6 +323,12 @@ int main(int argc, char** argv) return 0; } + if (!check_uinput_loaded()) + { + std::cout << "\nThe uinput module is neither loaded nor built-in to the kernel."; + std::cout << "\nThe uinput module MUST be loaded for WeJoy to operate correctly.\n"; + return 0; + } //Open the user lua file. LuaScript lScript(argv[1]);