Skip to content

Commit

Permalink
Merge pull request dorssel#817 from dorssel/docker
Browse files Browse the repository at this point in the history
Improve docker-desktop support
  • Loading branch information
dorssel authored Dec 28, 2023
2 parents 80d0ee6 + 988ffd0 commit c76e3e7
Showing 1 changed file with 11 additions and 29 deletions.
40 changes: 11 additions & 29 deletions Usbipd/Wsl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -281,36 +281,13 @@ public static async Task<ExitCode> Attach(BusId busId, bool autoAttach, string?
console.ReportError($"Option '--wsl' requires that this software is installed on a local drive.");
return ExitCode.Failure;
}
string wslLinuxMountPoint;
var wslResult = await RunWslAsync((distribution, "/"), null, cancellationToken, "/bin/wslpath", "-u", wslWindowsPath);
if (wslResult.ExitCode != 0)
{
var wslResult = await RunWslAsync((distribution, "/"), null, cancellationToken, "cat", "/proc/self/mountinfo");
// Example output:
//
// 46 51 0:26 / /mnt/wsl rw,relatime shared:1 - tmpfs none rw
// 47 51 0:28 / /usr/lib/wsl/drivers ro,nosuid,nodev,noatime - 9p none ro,dirsync,aname=drivers;fmask=222;dmask=222,mmap,access=client,msize=65536,trans=fd,rfd=7,wfd=7
// 51 38 8:32 / / rw,relatime - ext4 /dev/sdc rw,discard,errors=remount-ro,data=ordered
// ...
// 82 68 0:56 / /sys/fs/cgroup/rdma rw,nosuid,nodev,noexec,relatime shared:25 - cgroup cgroup rw,rdma
// 83 68 0:57 / /sys/fs/cgroup/misc rw,nosuid,nodev,noexec,relatime shared:26 - cgroup cgroup rw,misc
// 84 51 0:58 / /mnt/c rw,noatime - 9p drvfs rw,dirsync,aname=drvfs;path=C:\;uid=1000;gid=1000;symlinkroot=/mnt/,mmap,access=client,msize=262144,trans=virtio
//
// NOTE: The final backslash (\) is optional, and the drive letter is not case sensitive.
if (wslResult.ExitCode != 0)
{
console.ReportError($"Unable to parse the WSL mount points. Please report this at https://github.com/dorssel/usbipd-win/issues.");
return ExitCode.Failure;
}
if ((wslResult.StandardOutput.Split('\n')
.FirstOrDefault(line => line.Split(" - ").Skip(1).FirstOrDefault()?.Split(' ').Skip(2).FirstOrDefault()?.Split(';').Any(
o => o.ToLowerInvariant().TrimEnd('\\') == $"path={wslWindowsPathRoot.ToLowerInvariant().TrimEnd('\\')}") ?? false) is not string mountLine)
|| (mountLine.Split(' ').Skip(4).FirstOrDefault() is not string mountPoint))
{
console.ReportError($"Option '--wsl' requires that drive {wslWindowsPathRoot} is mounted in WSL; see {AutomountWslUrl}.");
return ExitCode.Failure;
}
wslLinuxMountPoint = mountPoint;
console.ReportError($"Option '--wsl' requires that drive {wslWindowsPathRoot} is mounted in WSL; see {AutomountWslUrl}.");
return ExitCode.Failure;
}
wslLinuxPath = Path.Combine(wslLinuxMountPoint, Path.GetRelativePath(wslWindowsPathRoot, wslWindowsPath)).Replace('\\', '/');
wslLinuxPath = wslResult.StandardOutput.TrimEnd('\n');
}

console.ReportInfo($"Using client tools located at {wslLinuxPath}");
Expand All @@ -328,7 +305,7 @@ public static async Task<ExitCode> Attach(BusId busId, bool autoAttach, string?
// Now find out the IP address of the host.
IPAddress hostAddress;
{
var wslResult = await RunWslAsync((distribution, "/"), null, cancellationToken, "/usr/bin/wslinfo", "--networking-mode");
var wslResult = await RunWslAsync((distribution, "/"), null, cancellationToken, "/bin/wslinfo", "--networking-mode");
if (wslResult.ExitCode == 0 && wslResult.StandardOutput.Trim() == "mirrored")
{
// mirrored networking mode ... we're done
Expand Down Expand Up @@ -578,6 +555,11 @@ internal static bool IsOnSameIPv4Network(IPAddress hostAddress, IPAddress hostMa
var name = match.Groups[2].Value.TrimEnd();
var isRunning = match.Groups[3].Value == "Running";
var version = uint.Parse(match.Groups[4].Value, CultureInfo.InvariantCulture);
if (name == "docker-desktop-data")
{
// NOTE: docker-desktop-data is unusable
continue;
}
distributions.Add(new(name, isDefault, version, isRunning));
}
break;
Expand Down

0 comments on commit c76e3e7

Please sign in to comment.