File: 0001-Compatibility-with-nix-0.30.patch

package info (click to toggle)
waypipe 0.10.5-3
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 4,080 kB
  • sloc: ansic: 15,809; xml: 9,436; python: 1,726; sh: 248; makefile: 28
file content (366 lines) | stat: -rw-r--r-- 16,415 bytes parent folder | download | duplicates (2)
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
From: Gard Spreemann <gspr@nonempty.org>
Date: Wed, 3 Dec 2025 10:39:50 +0100
Subject: Compatibility with nix 0.30

Based on upstream commit e3ac818b4cdd438ba9baa72dca021b63405e48d9
---
 Cargo.toml        |  2 +-
 src/kernel.rs     |  3 +--
 src/main.rs       | 32 +++++++++++++-------------------
 src/mainloop.rs   | 10 +++++-----
 src/test_proto.rs | 41 +++++++++++++++++------------------------
 src/tracking.rs   |  3 +--
 src/util.rs       | 28 +++++++++-------------------
 7 files changed, 47 insertions(+), 72 deletions(-)

diff --git a/Cargo.toml b/Cargo.toml
index b8d0b72..ee30ccc 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -29,7 +29,7 @@ test_proto = []
 getrandom = "0.2.15"
 clap = { version = "4.5.21", features = [] }
 log = { version = "0.4.22", features = ["std"] }
-nix = { version = "0.29.0", features = ["fs", "poll", "uio", "socket", "process", "signal", "ioctl"] }
+nix = { version = "0.30.0", features = ["fs", "poll", "uio", "socket", "process", "signal", "ioctl"] }
 ash = { version = "0.38.0", optional = true }
 waypipe-ffmpeg-wrapper = { path = "wrap-ffmpeg", optional = true}
 waypipe-lz4-wrapper = { path = "wrap-lz4", optional = true}
diff --git a/src/kernel.rs b/src/kernel.rs
index 3d2c268..c54b65d 100644
--- a/src/kernel.rs
+++ b/src/kernel.rs
@@ -774,8 +774,7 @@ fn test_buffer_replication() {
 
     let local_fd = nix::sys::memfd::memfd_create(
         c"/test",
-        nix::sys::memfd::MemFdCreateFlag::MFD_CLOEXEC
-            | nix::sys::memfd::MemFdCreateFlag::MFD_ALLOW_SEALING,
+        nix::sys::memfd::MFdFlags::MFD_CLOEXEC | nix::sys::memfd::MFdFlags::MFD_ALLOW_SEALING,
     )
     .unwrap();
 
diff --git a/src/main.rs b/src/main.rs
index 84edb60..6a8c197 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -182,16 +182,12 @@ fn dir_flags() -> fcntl::OFlag {
 
 /** Get a file descriptor corresponding to a path, suitable for `fchdir()` */
 fn open_folder(p: &Path) -> Result<OwnedFd, String> {
-    let raw_fd = fcntl::open(
+    fcntl::open(
         p,
         dir_flags() | fcntl::OFlag::O_CLOEXEC | fcntl::OFlag::O_NOCTTY,
         nix::sys::stat::Mode::empty(),
     )
-    .map_err(|x| tag!("Failed to open folder '{:?}': {}", p, x))?;
-    Ok(unsafe {
-        // SAFETY: freshly created, checked valid, exclusively owned
-        OwnedFd::from_raw_fd(raw_fd)
-    })
+    .map_err(|x| tag!("Failed to open folder '{:?}': {}", p, x))
 }
 
 /** Connection information for a VSOCK socket */
@@ -464,7 +460,7 @@ fn socket_connect(
                     nix::unistd::unlink(file)
                         .map_err(|x| tag!("Failed to unlink socket: {}", x))?;
                 }
-                nix::unistd::fchdir(cwd.as_raw_fd())
+                nix::unistd::fchdir(&cwd)
                     .map_err(|x| tag!("Failed to return to original path: {}", x))?;
                 x
             } else {
@@ -539,11 +535,9 @@ impl Drop for FileCleanup {
     fn drop(&mut self) {
         let file_name = self.full_path.file_name().unwrap();
         debug!("Trying to unlink socket created at: {:?}", self.full_path);
-        if let Err(x) = unistd::unlinkat(
-            Some(self.folder.as_raw_fd()),
-            file_name,
-            unistd::UnlinkatFlags::NoRemoveDir,
-        ) {
+        if let Err(x) =
+            unistd::unlinkat(&self.folder, file_name, unistd::UnlinkatFlags::NoRemoveDir)
+        {
             error!(
                 "Failed to unlink display socket at: {:?}: {:?}",
                 self.full_path, x
@@ -579,12 +573,11 @@ fn unix_socket_create_and_bind(
     let (f, r) = if let Some(folder) = path.parent() {
         let f = open_folder(folder)?;
 
-        unistd::fchdir(f.as_raw_fd()).map_err(|x| tag!("Failed to visit folder: {}", x))?;
+        unistd::fchdir(&f).map_err(|x| tag!("Failed to visit folder: {}", x))?;
         // eventually: is a 'bindat' equivalent available?
         // can use /proc/self/fd to workaround socket path length issues
         let x = socket::bind(socket.as_raw_fd(), &addr);
-        unistd::fchdir(cwd.as_raw_fd())
-            .map_err(|x| tag!("Failed to return to original path: {}", x))?;
+        unistd::fchdir(&cwd).map_err(|x| tag!("Failed to return to original path: {}", x))?;
         (f, x)
     } else {
         let f: OwnedFd =
@@ -872,6 +865,7 @@ fn run_server_oneshot(
     Ok(())
 }
 
+
 /** Inner function for `run_server_multi`, used to ensure its cleanup always runs */
 fn run_server_inner(
     display_socket: &OwnedFd,
@@ -1411,11 +1405,11 @@ fn setup_secctx(
         connect_to_wayland_display(cwd)?
     };
 
-    let flags = fcntl::fcntl(wayland_conn.as_raw_fd(), fcntl::FcntlArg::F_GETFL)
+    let flags = fcntl::fcntl(&wayland_conn, fcntl::FcntlArg::F_GETFL)
         .map_err(|x| tag!("Failed to get wayland socket flags: {}", x))?;
     let mut flags = fcntl::OFlag::from_bits(flags).unwrap();
     flags.remove(fcntl::OFlag::O_NONBLOCK);
-    fcntl::fcntl(wayland_conn.as_raw_fd(), fcntl::FcntlArg::F_SETFL(flags))
+    fcntl::fcntl(&wayland_conn, fcntl::FcntlArg::F_SETFL(flags))
         .map_err(|x| tag!("Failed to set wayland socket flags: {}", x))?;
 
     let (close_r, close_w) = unistd::pipe2(fcntl::OFlag::O_CLOEXEC | fcntl::OFlag::O_NONBLOCK)
@@ -1788,7 +1782,7 @@ fn main() -> Result<(), String> {
     let logger = Logger {
         max_level,
         pid: std::process::id(),
-        color_output: nix::unistd::isatty(2).unwrap(),
+        color_output: nix::unistd::isatty(std::io::stderr()).unwrap(),
         anti_staircase,
         color: log_color,
         label: log_label,
@@ -1960,7 +1954,7 @@ fn main() -> Result<(), String> {
             if *loop_test && !vsock {
                 let client_path = PathBuf::from(&client_sock_path);
                 let server_path = PathBuf::from(&server_sock_path);
-                unistd::symlinkat(&client_path, None, &server_path).map_err(|x| {
+                unistd::symlinkat(&client_path, fcntl::AT_FDCWD, &server_path).map_err(|x| {
                     tag!(
                         "Failed to create symlink from {:?} to {:?}: {}",
                         client_path,
diff --git a/src/mainloop.rs b/src/mainloop.rs
index 91bb8c3..4c013cd 100644
--- a/src/mainloop.rs
+++ b/src/mainloop.rs
@@ -1380,7 +1380,7 @@ fn process_sfd_msg(
 
             let local_fd = memfd::memfd_create(
                 c"/waypipe",
-                memfd::MemFdCreateFlag::MFD_CLOEXEC | memfd::MemFdCreateFlag::MFD_ALLOW_SEALING,
+                memfd::MFdFlags::MFD_CLOEXEC | memfd::MFdFlags::MFD_ALLOW_SEALING,
             )
             .map_err(|x| tag!("Failed to create memfd: {:?}", x))?;
 
@@ -4955,7 +4955,7 @@ fn loop_inner<'a>(
         if pfd_returns[0].contains(PollFlags::POLLIN) {
             debug!("Self-pipe wakeup");
             let mut tmp: [u8; 64] = [0; 64];
-            let res = unistd::read(wake_r.as_raw_fd(), &mut tmp[..]);
+            let res = unistd::read(&wake_r, &mut tmp[..]);
             match res {
                 Ok(_) => {
                     /* worker thread may have a message */
@@ -5069,7 +5069,7 @@ fn loop_inner<'a>(
 
             if evts.contains(PollFlags::POLLIN) {
                 let mut data = [0u8; 8];
-                let r = nix::unistd::read(borrowed_fd.unwrap().as_raw_fd(), &mut data);
+                let r = nix::unistd::read(borrowed_fd.unwrap(), &mut data);
                 match r {
                     Ok(s) => {
                         /* Reads from an eventfd should always return 8 bytes; and short
@@ -5130,7 +5130,7 @@ fn loop_inner<'a>(
                 ShadowFdPipeBuffer::ReadFromWayland((ref mut buf, ref mut used_len)) => {
                     if evts.contains(PollFlags::POLLIN) {
                         /* read whatever is in buffer, append to region; fixed buffer size is OK? */
-                        let res = unistd::read(data.fd.as_raw_fd(), &mut buf[*used_len..]);
+                        let res = unistd::read(&data.fd, &mut buf[*used_len..]);
                         match res {
                             Ok(len) => {
                                 if len == 0 {
@@ -5217,7 +5217,7 @@ fn loop_inner<'a>(
             if evts.contains(PollFlags::POLLIN) {
                 let mut ret = [0u8; 8];
 
-                let r = nix::unistd::read(data.timeline.get_event_fd().as_raw_fd(), &mut ret);
+                let r = nix::unistd::read(&data.timeline.get_event_fd(), &mut ret);
                 match r {
                     Ok(s) => {
                         assert!(s == 8);
diff --git a/src/test_proto.rs b/src/test_proto.rs
index f924e27..31487cc 100644
--- a/src/test_proto.rs
+++ b/src/test_proto.rs
@@ -859,7 +859,7 @@ fn setup_vulkan(device_id: u64) -> Result<Arc<VulkanDevice>, String> {
 fn make_file_with_contents(data: &[u8]) -> Result<OwnedFd, String> {
     let local_fd = memfd::memfd_create(
         c"/waypipe",
-        memfd::MemFdCreateFlag::MFD_CLOEXEC | memfd::MemFdCreateFlag::MFD_ALLOW_SEALING,
+        memfd::MFdFlags::MFD_CLOEXEC | memfd::MFdFlags::MFD_ALLOW_SEALING,
     )
     .map_err(|x| tag!("Failed to create memfd: {:?}", x))?;
     unistd::ftruncate(&local_fd, data.len().try_into().unwrap())
@@ -1384,7 +1384,7 @@ fn check_pipe_transfer(
                     tmp.len()
                 };
 
-                match unistd::read(ord.as_ref().unwrap().as_raw_fd(), &mut tmp[..read_len]) {
+                match unistd::read(ord.as_ref().unwrap(), &mut tmp[..read_len]) {
                     Err(Errno::EINTR) | Err(Errno::EAGAIN) => { /* do nothing */ }
                     Err(Errno::ECONNRESET) | Err(Errno::ENOTCONN) => {
                         ord = None;
@@ -5349,17 +5349,12 @@ fn main() -> ExitCode {
         };
 
         let (read_out, new_stdouterr) = unistd::pipe2(fcntl::OFlag::empty()).unwrap();
-        let new_stdin = unsafe {
-            /* SAFETY: newly opened file descriptor */
-            OwnedFd::from_raw_fd(
-                fcntl::open(
-                    "/dev/null",
-                    fcntl::OFlag::O_RDONLY | fcntl::OFlag::O_NOCTTY,
-                    nix::sys::stat::Mode::empty(),
-                )
-                .unwrap(),
-            )
-        };
+        let new_stdin = fcntl::open(
+            "/dev/null",
+            fcntl::OFlag::O_RDONLY | fcntl::OFlag::O_NOCTTY,
+            nix::sys::stat::Mode::empty(),
+        )
+        .unwrap();
 
         let res = match unsafe {
             /* SAFETY: this program is not multi-threaded at this point.
@@ -5368,15 +5363,13 @@ fn main() -> ExitCode {
         } {
             unistd::ForkResult::Child => {
                 /* Blocking wait for child to complete */
-                #[allow(unused_unsafe)] /* dup2 is file-descriptor-unsafe */
-                unsafe {
-                    /* Atomically replace STDOUT, STDERR, STDIN; this may break library code which
-                     * incorrectly assumes standard io file descriptors never change properties
-                     * (e.g., by caching isatty()). */
-                    unistd::dup2(new_stdouterr.as_raw_fd(), libc::STDOUT_FILENO).unwrap();
-                    unistd::dup2(new_stdouterr.as_raw_fd(), libc::STDERR_FILENO).unwrap();
-                    unistd::dup2(new_stdin.as_raw_fd(), libc::STDIN_FILENO).unwrap();
-                }
+                /* Atomically replace STDOUT, STDERR, STDIN; this may break library code which
+                 * incorrectly assumes standard io file descriptors never change properties
+                 * (e.g., by caching isatty()). */
+                unistd::dup2_stdout(&new_stdouterr).unwrap();
+                unistd::dup2_stderr(&new_stdouterr).unwrap();
+                unistd::dup2_stdin(&new_stdin).unwrap();
+
                 drop(read_out);
 
                 if !core {
@@ -5454,7 +5447,7 @@ fn main() -> ExitCode {
                         continue;
                     }
 
-                    let eof_or_err = match unistd::read(read_out.as_raw_fd(), &mut tmp) {
+                    let eof_or_err = match unistd::read(&read_out, &mut tmp) {
                         Ok(n) => {
                             if n == 0 {
                                 true
@@ -5476,7 +5469,7 @@ fn main() -> ExitCode {
                 /* Read all remaining data in the pipe, dropping anything
                  * that was read after receipt of the information of test process death */
                 loop {
-                    match unistd::read(read_out.as_raw_fd(), &mut tmp) {
+                    match unistd::read(&read_out, &mut tmp) {
                         Ok(n) => {
                             if n == 0 {
                                 break;
diff --git a/src/tracking.rs b/src/tracking.rs
index aaed800..aa34f94 100644
--- a/src/tracking.rs
+++ b/src/tracking.rs
@@ -2958,8 +2958,7 @@ pub fn process_way_msg(
                     // Table has changed; send new fd
                     let local_fd = memfd::memfd_create(
                         c"/waypipe",
-                        memfd::MemFdCreateFlag::MFD_CLOEXEC
-                            | memfd::MemFdCreateFlag::MFD_ALLOW_SEALING,
+                        memfd::MFdFlags::MFD_CLOEXEC | memfd::MFdFlags::MFD_ALLOW_SEALING,
                     )
                     .map_err(|x| tag!("Failed to create memfd: {:?}", x))?;
                     let sz: u32 = new_table.len().try_into().unwrap();
diff --git a/src/util.rs b/src/util.rs
index 724a288..c5649fd 100644
--- a/src/util.rs
+++ b/src/util.rs
@@ -7,7 +7,7 @@ use nix::{fcntl, unistd};
 use std::fmt;
 use std::fmt::{Display, Formatter};
 use std::fs::ReadDir;
-use std::os::fd::{AsRawFd, FromRawFd, OwnedFd};
+use std::os::fd::OwnedFd;
 use std::os::unix::ffi::OsStrExt;
 use std::str::FromStr;
 
@@ -638,12 +638,8 @@ pub fn drm_open_render(dev_id: u64, rdrw: bool) -> Result<OwnedFd, String> {
                 if rdrw {
                     flags |= fcntl::OFlag::O_RDWR;
                 }
-                let raw_fd = fcntl::open(&path, flags, nix::sys::stat::Mode::empty())
-                    .map_err(|x| tag!("Failed to open drm node fd at '{:?}': {}", path, x))?;
-                return Ok(unsafe {
-                    // SAFETY: fd was just created, was checked valid, and is recorded nowhere else
-                    OwnedFd::from_raw_fd(raw_fd)
-                });
+                return fcntl::open(&path, flags, nix::sys::stat::Mode::empty())
+                    .map_err(|x| tag!("Failed to open drm node fd at '{:?}': {}", path, x));
             }
         }
     }
@@ -683,7 +679,7 @@ pub fn dmabuf_slice_get_first_stride(data: [u8; 64]) -> u32 {
 /** Set the close-on-exec flag for a file descriptor */
 pub fn set_cloexec(fd: &OwnedFd, cloexec: bool) -> Result<(), String> {
     fcntl::fcntl(
-        fd.as_raw_fd(),
+        fd,
         fcntl::FcntlArg::F_SETFD(if cloexec {
             fcntl::FdFlag::FD_CLOEXEC
         } else {
@@ -696,21 +692,15 @@ pub fn set_cloexec(fd: &OwnedFd, cloexec: bool) -> Result<(), String> {
 
 /** Set the O_NONBLOCK flag for the file description, clearing all other flags. */
 pub fn set_nonblock(fd: &OwnedFd) -> Result<(), String> {
-    fcntl::fcntl(
-        fd.as_raw_fd(),
-        fcntl::FcntlArg::F_SETFL(nix::fcntl::OFlag::O_NONBLOCK),
-    )
-    .map_err(|x| tag!("Failed to set nonblocking: {:?}", x))?;
+    fcntl::fcntl(fd, fcntl::FcntlArg::F_SETFL(nix::fcntl::OFlag::O_NONBLOCK))
+        .map_err(|x| tag!("Failed to set nonblocking: {:?}", x))?;
     Ok(())
 }
 
 /** Unset the O_NONBLOCK flag for the file description, clearing all other flags. */
 pub fn set_blocking(fd: &OwnedFd) -> Result<(), String> {
-    fcntl::fcntl(
-        fd.as_raw_fd(),
-        fcntl::FcntlArg::F_SETFL(nix::fcntl::OFlag::empty()),
-    )
-    .map_err(|x| tag!("Failed to set blocking: {:?}", x))?;
+    fcntl::fcntl(fd, fcntl::FcntlArg::F_SETFL(nix::fcntl::OFlag::empty()))
+        .map_err(|x| tag!("Failed to set blocking: {:?}", x))?;
     Ok(())
 }
 
@@ -719,7 +709,7 @@ pub fn set_blocking(fd: &OwnedFd) -> Result<(), String> {
 pub fn read_exact(fd: &OwnedFd, data: &mut [u8]) -> Result<(), Option<nix::Error>> {
     let mut offset = 0;
     while offset < data.len() {
-        match unistd::read(fd.as_raw_fd(), &mut data[offset..]) {
+        match unistd::read(&fd, &mut data[offset..]) {
             Ok(s) => {
                 if s == 0 {
                     return Err(None);