diff options
author | HimbeerserverDE <himbeerserverde@gmail.com> | 2023-03-19 19:09:08 +0100 |
---|---|---|
committer | HimbeerserverDE <himbeerserverde@gmail.com> | 2023-03-19 19:09:08 +0100 |
commit | 00d06a7035f81670ac0bdf71ff803bee5dd8668d (patch) | |
tree | c5d2e5dae4a1af431b4453b85e37b5a5c8d0fab2 /src | |
parent | e943e912729bcb6eb3af398028812752491a37f0 (diff) |
wait for rsdsl_pppoe 'lease' file
Diffstat (limited to 'src')
-rw-r--r-- | src/main.rs | 32 |
1 files changed, 21 insertions, 11 deletions
diff --git a/src/main.rs b/src/main.rs index bff0edf..f3b228d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,6 +4,8 @@ use rsdsl_netlinkd::{addr, link, route}; use std::fs::File; use std::net::{IpAddr, Ipv4Addr}; use std::path::Path; +use std::thread; +use std::time::Duration; use notify::event::{CreateKind, ModifyKind}; use notify::{Event, EventKind, RecursiveMode, Watcher}; @@ -13,18 +15,26 @@ fn main() -> Result<()> { link::up("eth0".into())?; link::up("eth1".into())?; - let mut watcher = notify::recommended_watcher(|res: notify::Result<Event>| match res { - Ok(event) => match event.kind { - EventKind::Create(kind) if kind == CreateKind::File => { - configure_wan(); + let mut watcher = loop { + match notify::recommended_watcher(|res: notify::Result<Event>| match res { + Ok(event) => match event.kind { + EventKind::Create(kind) if kind == CreateKind::File => { + configure_wan(); + } + EventKind::Modify(kind) if matches!(kind, ModifyKind::Data(_)) => { + configure_wan(); + } + _ => {} + }, + Err(e) => println!("[netlinkd] watch error: {}", e), + }) { + Ok(v) => break v, + Err(_) => { + println!("[netlinkd] waiting for rsdsl_pppoe"); + thread::sleep(Duration::from_secs(8)); } - EventKind::Modify(kind) if matches!(kind, ModifyKind::Data(_)) => { - configure_wan(); - } - _ => {} - }, - Err(e) => println!("[netlinkd] watch error: {}", e), - })?; + } + }; watcher.watch( Path::new("/data/pppoe.ip_config"), |