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

Die if uinput module is neither loaded nor built into the kernel #30

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ i↑ ⟶ up↑
rightalt↑ ⟶ ∅
```

Load uinput module (**kbct will not function but will not produce an error if the uinput module is not loaded**)
Load uinput module

```bash
sudo modprobe uinput
Expand Down
25 changes: 25 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,32 @@ impl EventObserver for KeyLogger {
}
}

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;
}

Comment on lines +270 to +291
Copy link
Owner

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?

Copy link
Contributor Author

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.

fn start_mapper_from_file_conf(config_file: String) -> Result<()> {
if !check_uinput_loaded() {
panic!("'uinput' module must be loaded OR built into the kernel");
}
let config = serde_yaml::from_str(
&*std::fs::read_to_string(config_file.as_str())
.expect(&format!("Could not open file {}", config_file)))
Expand Down