Closed naftulikay closed 1 year ago
This is my bad, I was passing an uninitialized Vec<u8>
as a buffer. The problem was here:
let mut event_stream = Inotify::init()?.into_event_stream(Vec::with_capacity(4096))?;
Vec::with_capacity
does not initialize the memory. Either of the following will fix the issue:
// with a stack array
let mut event_stream = Inotify::init()?.into_event_stream([0; 4096])?;
// with an *initialized* vector: the vec! macro does initialize memory
let mut event_stream = Inotify::init()?.into_event_stream(vec![0; 4096])?;
Glad you figured it out!
I'm using the current stable version of
inotify
,0.10.2
, on Ubuntu LTS Focal, kernel 5.15,amd64
. I'm attempting to port this C code to Rust to make management of a certain hardware audio device easier and more idiomatic. The C code mentioned essentially does the following:Essentially, this is done to setup callbacks for when devices are added/removed from
/dev/snd
to detect new devices and remove ones that were disconnected.I'm essentially trying to do the same thing in Rust, but all I get is errors:
Here is my Rust code, which should simply log out all events that are received:
Note that in this example code, I'm allowing any event to come across just to see if it's working at all. When I unplug my USB audio device, I get flooded with thousands of errors, so much so that my IDE begins to freeze up. Other than the errors, I receive no other events whatsoever.
I am admittedly not as familiar with
inotify
as it relates to kernel device files, but simply using:does report changes as they occur, so it seems to be related to either how I'm using this
inotify
crate or some bug within the crate.What am I doing incorrectly here?