summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
authorMaxVerevkin <maxxverrr@gmail.com>2025-05-16 09:40:58 +0300
committerMaxVerevkin <maxxverrr@gmail.com>2025-05-16 09:40:58 +0300
commitc9cee90d765198cf72c5a5155ee0d8ab566d98a9 (patch)
treef313eaa708c80f4e8ec9eddf3d9f042af5f06d41 /src/main.rs
parentaf5d45fbe26cdc4e9e28f11197c9a689728100e4 (diff)
downloadi3bar-mango-c9cee90d765198cf72c5a5155ee0d8ab566d98a9.tar.gz
use std::io::pipe
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs24
1 files changed, 5 insertions, 19 deletions
diff --git a/src/main.rs b/src/main.rs
index 2e7aeb2..4a86593 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -18,8 +18,8 @@ mod text;
mod utils;
mod wm_info_provider;
-use std::io::{self, ErrorKind};
-use std::os::fd::{AsRawFd, RawFd};
+use std::io::{self, ErrorKind, Read};
+use std::os::fd::AsRawFd;
use std::path::PathBuf;
use clap::Parser;
@@ -40,7 +40,7 @@ struct Cli {
fn main() -> anyhow::Result<()> {
let args = Cli::parse();
- let [sig_read, sig_write] = pipe(libc::O_NONBLOCK | libc::O_CLOEXEC)?;
+ let (mut sig_read, sig_write) = io::pipe()?;
signal_hook::low_level::pipe::register(SIGUSR1, sig_write)?;
let mut conn = Connection::connect()?;
@@ -55,12 +55,8 @@ fn main() -> anyhow::Result<()> {
Ok(event_loop::Action::Keep)
});
- el.register_with_fd(sig_read, move |ctx| {
- let mut buf = [0u8];
- assert_eq!(
- unsafe { libc::read(sig_read, buf.as_mut_ptr().cast(), 1) },
- 1
- );
+ el.register_with_fd(sig_read.as_raw_fd(), move |ctx| {
+ sig_read.read_exact(&mut [0u8]).unwrap();
ctx.state.toggle_visibility(ctx.conn);
Ok(event_loop::Action::Keep)
});
@@ -108,13 +104,3 @@ fn main() -> anyhow::Result<()> {
el.run(&mut conn, &mut state)?;
unreachable!();
}
-
-// TODO: remove once Rust 1.87.0 is stable
-fn pipe(flags: libc::c_int) -> io::Result<[RawFd; 2]> {
- let mut fds = [0; 2];
- if unsafe { libc::pipe2(fds.as_mut_ptr(), flags) } == -1 {
- Err(io::Error::last_os_error())
- } else {
- Ok(fds)
- }
-}