1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
From 017ed59239e48ca689af36f1ddaec877a3c86175 Mon Sep 17 00:00:00 2001
From: Benedikt Peetz <benedikt.peetz@b-peetz.de>
Date: Tue, 20 May 2025 17:10:47 +0200
Subject: [PATCH] Revert "use std::io::pipe"
This reverts commit c9cee90d765198cf72c5a5155ee0d8ab566d98a9 as this
commit requires rustc 1.87.0
---
src/main.rs | 24 +++++++++++++++++++-----
1 file changed, 19 insertions(+), 5 deletions(-)
diff --git a/src/main.rs b/src/main.rs
index 4a86593..2e7aeb2 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, Read};
-use std::os::fd::AsRawFd;
+use std::io::{self, ErrorKind};
+use std::os::fd::{AsRawFd, RawFd};
use std::path::PathBuf;
use clap::Parser;
@@ -40,7 +40,7 @@ struct Cli {
fn main() -> anyhow::Result<()> {
let args = Cli::parse();
- let (mut sig_read, sig_write) = io::pipe()?;
+ let [sig_read, sig_write] = pipe(libc::O_NONBLOCK | libc::O_CLOEXEC)?;
signal_hook::low_level::pipe::register(SIGUSR1, sig_write)?;
let mut conn = Connection::connect()?;
@@ -55,8 +55,12 @@ fn main() -> anyhow::Result<()> {
Ok(event_loop::Action::Keep)
});
- el.register_with_fd(sig_read.as_raw_fd(), move |ctx| {
- sig_read.read_exact(&mut [0u8]).unwrap();
+ 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
+ );
ctx.state.toggle_visibility(ctx.conn);
Ok(event_loop::Action::Keep)
});
@@ -104,3 +108,13 @@ 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)
+ }
+}
--
2.49.0
|