Skip to content

Commit

Permalink
feat: Upgrade nix, which allows removing unsafe code and backported c…
Browse files Browse the repository at this point in the history
…ode from this crate
  • Loading branch information
VorpalBlade committed Aug 28, 2023
1 parent fb4eb64 commit 4dcc2c6
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 135 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ anyhow = { version = "1.0.75", features = ["backtrace"] }
env_logger = { version = "0.10.0", default-features = false }
evdev-rs = "0.6.1"
log = "0.4.20"
nix = { version = "0.26.2", default-features = false, features = [
nix = { version = "0.27.1", default-features = false, features = [
"event",
"inotify",
] }
Expand Down
1 change: 0 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ mod flags;
mod handlers;
mod led;
mod monitor;
mod nix_polyfill;
mod policy;
mod state;
mod utils;
Expand Down
16 changes: 4 additions & 12 deletions src/monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,21 @@
use std::{
cell::RefCell,
collections::HashMap,
os::fd::{AsRawFd, BorrowedFd},
os::fd::AsFd,
rc::Rc,
time::{Duration, Instant},
};

use nix::{
errno::Errno,
sys::{
epoll::{EpollCreateFlags, EpollFlags},
epoll::{Epoll, EpollCreateFlags, EpollEvent, EpollFlags},
inotify::{AddWatchFlags, InitFlags, Inotify},
},
};

use crate::{
flags::KeyboardBacklightd,
handlers::Handler,
led::Led,
nix_polyfill::{Epoll, EpollEvent},
policy::run_policy,
state::State,
flags::KeyboardBacklightd, handlers::Handler, led::Led, policy::run_policy, state::State,
};

/// Marker value in epoll for the inotify watch.
Expand All @@ -36,13 +31,10 @@ pub(crate) fn monitor(
config: &KeyboardBacklightd,
) -> anyhow::Result<()> {
let inotify = Inotify::init(InitFlags::IN_CLOEXEC | InitFlags::IN_NONBLOCK)?;
// SAFETY: Epoll and inotify lives equally long. Also this cannot create a memory error anyway.
// This is safe.
let ifd = unsafe { BorrowedFd::borrow_raw(inotify.as_raw_fd()) };
let epoll = Epoll::new(EpollCreateFlags::EPOLL_CLOEXEC)?;

epoll.add(
ifd,
inotify.as_fd(),
EpollEvent::new(EpollFlags::EPOLLIN | EpollFlags::EPOLLERR, INOTIFY_HANDLE),
)?;

Expand Down
119 changes: 0 additions & 119 deletions src/nix_polyfill.rs

This file was deleted.

0 comments on commit 4dcc2c6

Please sign in to comment.