aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib.rs
diff options
context:
space:
mode:
authorSascha Grunert <mail@saschagrunert.de>2017-04-01 11:25:48 +0200
committerYin Guanhao <sopium@users.noreply.github.com>2017-04-05 18:48:29 +0800
commit4cb80ab1fbb66072bb6920383a2cbe134c766547 (patch)
tree11a470697e48edaeb2474afd93e065fd927adcc0 /src/lib.rs
parentWrap `UdpSocket` in `RwLock`, so that it is possible to change it (diff)
downloadwireguard-rs-sg/master.tar.xz
wireguard-rs-sg/master.zip
Added API function for retrieving the 'run path'sg/master
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs16
1 files changed, 10 insertions, 6 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 6075f9b..74b9239 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -74,12 +74,7 @@ impl WireGuard {
debug!("Created local socket.");
// Create the socket directory if not existing
- let mut socket_path = if Path::new("/run").exists() {
- PathBuf::from("/run")
- } else {
- PathBuf::from("/var").join("run")
- };
- socket_path = socket_path.join("wireguard");
+ let mut socket_path = Self::get_run_path().join("wireguard");
if !socket_path.exists() {
debug!("Creating socket path: {}", socket_path.display());
@@ -235,4 +230,13 @@ impl WireGuard {
fn chmod(_path: &Path, _perms: u32) -> Result<()> {
Ok(())
}
+
+ /// Returns the path where the socket and pid file will be stored
+ pub fn get_run_path() -> PathBuf {
+ if Path::new("/run").exists() {
+ PathBuf::from("/run")
+ } else {
+ PathBuf::from("/var").join("run")
+ }
+ }
}