Skip to content

Commit

Permalink
Update freedesktop.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
0323pin committed Oct 17, 2023
1 parent 1562113 commit aa7b7fd
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/freedesktop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -737,8 +737,14 @@ fn get_mount_points() -> Result<Vec<MountPoint>, Error> {
use once_cell::sync::Lazy;
use std::sync::Mutex;

// The same as above applies to getmntinfo() function.
// NetBSD does not support statfs since 2005, so we need to use statvfs.
// The getmntinfo() function writes the array of structures to an internal
// static object and returns a pointer to that object. Subsequent calls to
// getmntinfo() will modify the same object. This means that the function is
// not threadsafe. To help prevent multiple threads using it concurrently
// via get_mount_points a Mutex is used.
// We understand that threads can still call `libc::getmntinfo(…)` directly
// to bypass the lock and trigger UB.
// NetBSD does not support statfs since 2005, so we need to use statvfs instead.
static LOCK: Lazy<Mutex<()>> = Lazy::new(|| Mutex::new(()));
let _lock = LOCK.lock().unwrap();

Expand Down

0 comments on commit aa7b7fd

Please sign in to comment.