Hi! I'm some weird issues which I can't explain.
Short story: There is some issue with my Linux setup that keeps resetting my keyboard repeat rate randomly once in a few minutes. I don't have time for dealing with this, so I decided to fix it bluntly with this Rust code.
As you can see it just sits in the background and spawns xset every N seconds.
use nix::unistd::{fork, ForkResult};
use std::time::Duration;
fn main() {
match fork() {
Ok(ForkResult::Parent { child: _, .. }) => {
println!("starting xset_daemon");
}
Ok(ForkResult::Child) => {
println!("xset_daemon started");
loop {
std::thread::sleep(Duration::from_secs(10));
match std::process::Command::new("xset")
.args(&["r", "rate", "250", "50"]).spawn() {
Err(e) => eprintln!("xset_daemon error: {}", e),
_ => ()
}
}
}
Err(e) => eprintln!("Could not fork: {}", e)
}
}
It works perfectly fine for a while, but after some time (usually one day) I'm starting seeing errors in other places in my system, errors like:
Unable to create native thread: possibly out of memory or process/resource limits reached
At the same time, the daemon itself begins printing:
xset_daemon error: Resource temporarily unavailable (os error 11)
I'm relatively new to Rust and must be doing something wrong, do you have any ideas what's wrong with the code? Could it be an issue with the nix create and how it creates a fork?