diff --git a/wireguard-control/src/backends/userspace.rs b/wireguard-control/src/backends/userspace.rs index 2a8a648..befde96 100644 --- a/wireguard-control/src/backends/userspace.rs +++ b/wireguard-control/src/backends/userspace.rs @@ -273,19 +273,31 @@ fn get_userspace_implementation() -> String { } fn start_userspace_wireguard(iface: &InterfaceName) -> io::Result { - let mut command = Command::new(get_userspace_implementation()); - let output = if cfg!(target_os = "linux") { - command.args(&[iface.to_string()]).output()? + let userspace_implementation = get_userspace_implementation(); + let mut command = Command::new(&userspace_implementation); + + let output_res = if cfg!(target_os = "linux") { + command.args(&[iface.to_string()]).output() } else { command .env("WG_TUN_NAME_FILE", &format!("{VAR_RUN_PATH}/{iface}.name")) .args(["utun"]) - .output()? + .output() }; - if !output.status.success() { - Err(io::ErrorKind::AddrNotAvailable.into()) - } else { - Ok(output) + + match output_res { + Ok(output) => { + if output.status.success() { + Ok(output) + } else { + Err(io::ErrorKind::AddrNotAvailable.into()) + } + }, + Err(e) if e.kind() == io::ErrorKind::NotFound => Err(io::Error::new( + io::ErrorKind::NotFound, + format!("Cannot find \"{userspace_implementation}\". Specify a custom path with WG_USERSPACE_IMPLEMENTATION."), + )), + Err(e) => Err(e), } }