wgctrl-rs: create /var/run/wireguard if it's not there

wireguard-go wasn't writing the name file if the directory didn't
already exist.
pull/48/head
Jake McGinty 2021-04-11 13:30:38 +09:00
parent c15db6f833
commit dde58c8f45
1 changed files with 2 additions and 1 deletions

View File

@ -267,7 +267,7 @@ pub fn apply(builder: DeviceConfigBuilder, iface: &InterfaceName) -> io::Result<
// If we can't open a configuration socket to an existing interface, try starting it. // If we can't open a configuration socket to an existing interface, try starting it.
let mut sock = match open_socket(iface) { let mut sock = match open_socket(iface) {
Err(_) => { Err(_) => {
// TODO(jake): allow other userspace wireguard implementations fs::create_dir_all(VAR_RUN_PATH)?;
let output = Command::new(&get_userspace_implementation()) let output = Command::new(&get_userspace_implementation())
.env( .env(
"WG_TUN_NAME_FILE", "WG_TUN_NAME_FILE",
@ -278,6 +278,7 @@ pub fn apply(builder: DeviceConfigBuilder, iface: &InterfaceName) -> io::Result<
if !output.status.success() { if !output.status.success() {
return Err(io::ErrorKind::AddrNotAvailable.into()); return Err(io::ErrorKind::AddrNotAvailable.into());
} }
std::thread::sleep(Duration::from_millis(100));
open_socket(iface)? open_socket(iface)?
}, },
Ok(sock) => sock, Ok(sock) => sock,