Skip to content

Commit

Permalink
lib: Update to reflect better functionality on WSL 2
Browse files Browse the repository at this point in the history
  • Loading branch information
cptpcrd committed Aug 14, 2020
1 parent 80b1c07 commit d604757
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,10 @@ pub unsafe fn close_open_fds(mut minfd: libc::c_int, mut keep_fds: &[libc::c_int
}

#[cfg(target_os = "linux")]
fn is_wsl() -> bool {
fn is_wsl_1() -> bool {
// It seems that on WSL 1 the kernel "release name" ends with "-Microsoft", and on WSL 2 the
// release name ends with "-microsoft-standard". So we look for "Microsoft" at the end.

let mut uname: libc::utsname = unsafe { core::mem::zeroed() };

if unsafe { libc::uname(&mut uname) } == 0 {
Expand Down Expand Up @@ -198,8 +201,8 @@ fn iter_fds(mut minfd: libc::c_int, possible: bool) -> FdIter {
let dirfd = unsafe {
// Try /proc/self/fd on Linux

if is_wsl() {
// On WSL, getdents64() doesn't always return the entries in order.
if is_wsl_1() {
// On WSL 1, getdents64() doesn't always return the entries in order.
// It also seems to skip some file descriptors.
// We can't trust it.

Expand Down

0 comments on commit d604757

Please sign in to comment.