Skip to content

Commit

Permalink
Log virtual device creation
Browse files Browse the repository at this point in the history
  • Loading branch information
htrefil committed May 13, 2023
1 parent 1fb0b57 commit 7cc34c7
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 1 deletion.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions rkvm-input/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ smallvec = { version = "1.10.0", features = ["serde"] }
inotify = "0.10.0"
tokio = { version = "1.0.1", features = ["fs", "io-util", "net", "sync", "rt", "time", "macros"] }
libc = "0.2.77"
log = "0.4.11"

[build-dependencies]
bindgen = "0.65.1"
Expand Down
20 changes: 20 additions & 0 deletions rkvm-input/src/event_reader.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use crate::event::{Axis, Direction, Event, EventBatch, KeyKind};
use crate::glue::{self, input_event, libevdev, libevdev_uinput, timeval};

use std::ffi::{CStr, OsStr};
use std::fs::{File, OpenOptions};
use std::io::Error;
use std::mem::MaybeUninit;
use std::os::unix::ffi::OsStrExt;
use std::os::unix::fs::OpenOptionsExt;
use std::os::unix::io::AsRawFd;
use std::path::Path;
Expand Down Expand Up @@ -110,6 +112,24 @@ impl EventReader {
let uinput_handle = unsafe { uinput_handle.assume_init() };
let uinput_handle = NonNull::new(uinput_handle).unwrap();

let uinput_path = unsafe { glue::libevdev_uinput_get_devnode(uinput_handle.as_ptr()) };
let uinput_path = unsafe {
CStr::from_ptr(if uinput_path.is_null() {
"<unknown>".as_ptr() as *const _
} else {
uinput_path
})
};

let uinput_path = OsStr::from_bytes(uinput_path.to_bytes());
let uinput_path = Path::new(uinput_path);

log::info!(
"Registered helper for {} at {}",
path.display(),
uinput_path.display()
);

Ok(Self {
evdev_file,
evdev_handle,
Expand Down
20 changes: 19 additions & 1 deletion rkvm-input/src/event_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@ use crate::event::Event;
use crate::glue::{self, input_event, libevdev, libevdev_uinput, timeval};
use crate::{Axis, Direction};

use std::ffi::{CStr, OsStr};
use std::fs::{File, OpenOptions};
use std::io::{Error, ErrorKind};
use std::mem::MaybeUninit;
use std::ops::RangeInclusive;
use std::os::fd::AsRawFd;
use std::os::unix::ffi::OsStrExt;
use std::path::Path;
use std::ptr::NonNull;
use std::{iter, ptr};
use tokio::io::unix::AsyncFd;
use tokio::task;

pub struct EventWriter {
evdev_handle: NonNull<libevdev>,
Expand All @@ -19,7 +23,7 @@ pub struct EventWriter {

impl EventWriter {
pub async fn new() -> Result<Self, Error> {
tokio::task::spawn_blocking(Self::new_sync).await?
task::spawn_blocking(Self::new_sync).await?
}

fn new_sync() -> Result<Self, Error> {
Expand Down Expand Up @@ -63,6 +67,20 @@ impl EventWriter {
let uinput_handle = unsafe { uinput_handle.assume_init() };
let uinput_handle = NonNull::new(uinput_handle).unwrap();

let uinput_path = unsafe { glue::libevdev_uinput_get_devnode(uinput_handle.as_ptr()) };
let uinput_path = unsafe {
CStr::from_ptr(if uinput_path.is_null() {
"<unknown>".as_ptr() as *const _
} else {
uinput_path
})
};

let uinput_path = OsStr::from_bytes(uinput_path.to_bytes());
let uinput_path = Path::new(uinput_path);

log::info!("Registered virtual device at {}", uinput_path.display());

Ok(Self {
evdev_handle,
uinput_file,
Expand Down

0 comments on commit 7cc34c7

Please sign in to comment.