Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uinput check #19

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions main.cc
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <fstream>
#include <unistd.h> //sleep
#include <thread> //thread
#include <mutex>
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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]);
Expand Down