Skip to content

Commit a9e5390

Browse files
committed
Fixed formatting issues, added conditional compilation to fix musl and armv7 issues
1 parent c5c5598 commit a9e5390

File tree

2 files changed

+32
-10
lines changed

2 files changed

+32
-10
lines changed

src/sys/fanotify.rs

+11-2
Original file line numberDiff line numberDiff line change
@@ -250,15 +250,15 @@ impl FanotifyFidRecord {
250250
/// The filesystem id where this event occurred. The value this method returns
251251
/// differs depending on the host system. Please read the statfs(2) documentation
252252
/// for more information:
253-
/// https://man7.org/linux/man-pages/man2/statfs.2.html#VERSIONS
253+
/// <https://man7.org/linux/man-pages/man2/statfs.2.html#VERSIONS>
254254
pub fn filesystem_id(&self) -> libc::__kernel_fsid_t {
255255
self.0.fsid
256256
}
257257

258258
/// The file handle for the filesystem object where the event occurred. The handle is
259259
/// represented as a 0-length u8 array, but it actually points to variable-length
260260
/// file_handle struct.For more information:
261-
/// https://man7.org/linux/man-pages/man2/open_by_handle_at.2.html
261+
/// <https://man7.org/linux/man-pages/man2/open_by_handle_at.2.html>
262262
pub fn handle(&self) -> [u8; 0] {
263263
self.0.handle
264264
}
@@ -270,8 +270,10 @@ impl FanotifyFidRecord {
270270
#[derive(Debug, Eq, Hash, PartialEq)]
271271
#[repr(transparent)]
272272
#[allow(missing_copy_implementations)]
273+
#[cfg(target_env = "gnu")]
273274
pub struct FanotifyErrorRecord(libc::fanotify_event_info_error);
274275

276+
#[cfg(target_env = "gnu")]
275277
impl FanotifyErrorRecord {
276278
/// Errno of the FAN_FS_ERROR that occurred.
277279
pub fn err(&self) -> Errno {
@@ -292,8 +294,10 @@ impl FanotifyErrorRecord {
292294
#[derive(Debug, Eq, Hash, PartialEq)]
293295
#[repr(transparent)]
294296
#[allow(missing_copy_implementations)]
297+
#[cfg(target_env = "gnu")]
295298
pub struct FanotifyPidfdRecord(libc::fanotify_event_info_pidfd);
296299

300+
#[cfg(target_env = "gnu")]
297301
impl FanotifyPidfdRecord {
298302
/// The process file descriptor that refers to the process responsible for
299303
/// generating this event. If the underlying pidfd_create fails, `None` is returned.
@@ -310,6 +314,7 @@ impl FanotifyPidfdRecord {
310314
}
311315
}
312316

317+
#[cfg(target_env = "gnu")]
313318
impl Drop for FanotifyPidfdRecord {
314319
fn drop(&mut self) {
315320
if self.0.pidfd == libc::FAN_NOFD {
@@ -339,12 +344,14 @@ pub enum FanotifyInfoRecord {
339344
/// A [`libc::fanotify_event_info_error`] event was recieved.
340345
/// This occurs when a FAN_FS_ERROR occurs, indicating an error with
341346
/// the watch filesystem object. (such as a bad file or bad link lookup)
347+
#[cfg(target_env = "gnu")]
342348
Error(FanotifyErrorRecord),
343349

344350
/// A [`libc::fanotify_event_info_pidfd`] event was recieved, usually as
345351
/// a result of passing [`InitFlags::FAN_REPORT_PIDFD`] into [`Fanotify::init`].
346352
/// The containing struct includes a `pidfd` for reliably determining
347353
/// whether the process responsible for generating an event has been recycled or terminated
354+
#[cfg(target_env = "gnu")]
348355
Pidfd(FanotifyPidfdRecord),
349356
}
350357

@@ -610,6 +617,7 @@ impl Fanotify {
610617
);
611618
Some(FanotifyInfoRecord::Fid(FanotifyFidRecord(record)))
612619
}
620+
#[cfg(target_env = "gnu")]
613621
libc::FAN_EVENT_INFO_TYPE_ERROR => {
614622
let record = self
615623
.get_struct::<libc::fanotify_event_info_error>(
@@ -621,6 +629,7 @@ impl Fanotify {
621629
record,
622630
)))
623631
}
632+
#[cfg(target_env = "gnu")]
624633
libc::FAN_EVENT_INFO_TYPE_PIDFD => {
625634
let record = self
626635
.get_struct::<libc::fanotify_event_info_pidfd>(

test/sys/test_fanotify.rs

+21-8
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ use crate::*;
22
use nix::errno::Errno;
33
use nix::fcntl::AT_FDCWD;
44
use nix::sys::fanotify::{
5-
EventFFlags, Fanotify, FanotifyResponse, InitFlags, MarkFlags, MaskFlags,
6-
Response, FanotifyInfoRecord
5+
EventFFlags, Fanotify, FanotifyInfoRecord, FanotifyResponse, InitFlags,
6+
MarkFlags, MaskFlags, Response,
77
};
88
use std::fs::{read_link, read_to_string, File, OpenOptions};
99
use std::io::ErrorKind;
@@ -86,9 +86,11 @@ fn test_fanotify_notifications() {
8686
}
8787

8888
fn test_fanotify_notifications_with_info_records() {
89-
let group =
90-
Fanotify::init(InitFlags::FAN_CLASS_NOTIF | InitFlags::FAN_REPORT_FID, EventFFlags::O_RDONLY)
91-
.unwrap();
89+
let group = Fanotify::init(
90+
InitFlags::FAN_CLASS_NOTIF | InitFlags::FAN_REPORT_FID,
91+
EventFFlags::O_RDONLY,
92+
)
93+
.unwrap();
9294
let tempdir = tempfile::tempdir().unwrap();
9395
let tempfile = tempdir.path().join("test");
9496
OpenOptions::new()
@@ -115,7 +117,11 @@ fn test_fanotify_notifications_with_info_records() {
115117
let mut events = group.read_events_with_info_records().unwrap();
116118
assert_eq!(events.len(), 1, "should have read exactly one event");
117119
let (event, info_records) = events.pop().unwrap();
118-
assert_eq!(info_records.len(), 1, "should have read exactly one info record");
120+
assert_eq!(
121+
info_records.len(),
122+
1,
123+
"should have read exactly one info record"
124+
);
119125
assert!(event.check_version());
120126
assert_eq!(
121127
event.mask(),
@@ -124,7 +130,10 @@ fn test_fanotify_notifications_with_info_records() {
124130
| MaskFlags::FAN_CLOSE_WRITE
125131
);
126132

127-
assert!(matches!(info_records[0], FanotifyInfoRecord::Fid { .. }), "info record should be an fid record");
133+
assert!(
134+
matches!(info_records[0], FanotifyInfoRecord::Fid { .. }),
135+
"info record should be an fid record"
136+
);
128137

129138
// read test file
130139
{
@@ -136,7 +145,11 @@ fn test_fanotify_notifications_with_info_records() {
136145
let mut events = group.read_events_with_info_records().unwrap();
137146
assert_eq!(events.len(), 1, "should have read exactly one event");
138147
let (event, info_records) = events.pop().unwrap();
139-
assert_eq!(info_records.len(), 1, "should have read exactly one info record");
148+
assert_eq!(
149+
info_records.len(),
150+
1,
151+
"should have read exactly one info record"
152+
);
140153
assert!(event.check_version());
141154
assert_eq!(
142155
event.mask(),

0 commit comments

Comments
 (0)