-
Notifications
You must be signed in to change notification settings - Fork 24
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
Die if uinput module is neither loaded nor built into the kernel #30
base: master
Are you sure you want to change the base?
Conversation
Holy frijoles, Batman. In my testing, this works correctly, dies when it should, and announces accurately that uinput is either a loaded module or is built into the kernel. HOWEVER, I strongly suspect my completely ignorant coding style in Rust will look to those who know Rust ... like completely ignorant coding style in Rust. I do not ask you developers to "go easy on me; it's my first try at this," but rather to be brutal and instructive. I have a thick skin and would rather learn than be treated gently. It took me about seven hours of learning Rust notions to make something that would compile ... and another two to make something that would do what it was intended to do. This does not mean that what little I've written is stylistically desirable Rust. I come from Java (despite hating Java) and my only coding pal (we're both dentists, not professional developers, though he is a significantly better coder than am I) regularly notes that whether I write Haskell, Python or C, it all looks like Java. (EDIT: Also, I really thought I would have this done in twenty minutes when I sat down to do it. : ) |
fn check_uinput_loaded() -> bool { | ||
let mut kernel_version = std::fs::read_to_string("/proc/version").unwrap(); | ||
kernel_version = kernel_version.to_string().split(' ').nth(2).unwrap().to_string(); | ||
|
||
let built_in_modules = std::fs::read_to_string(String::from("/lib/modules/") + &kernel_version + &String::from("/modules.builtin")).unwrap(); | ||
for line in built_in_modules.lines() { | ||
if line.eq("kernel/drivers/input/misc/uinput.ko") { | ||
info!("'uinput' is built into running kernel version: {}", kernel_version); | ||
return true; | ||
} | ||
} | ||
|
||
let modules = std::fs::read_to_string("/proc/modules").unwrap(); | ||
for line in modules.lines() { | ||
if line.starts_with("uinput ") { | ||
info!("'uinput' module is loaded"); | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR
How confident are you about this being cross-platform? Will it work across most popular linux desktop distros/kernel versions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am confident only that it compiles cleanly on Arch. Your question is very fair. I have not tested it on other Linux distros/kernels.
No description provided.