Skip to content

Commit 105b935

Browse files
authored
Merge pull request #160 from cheese/master
Restart 'ip monitor address' process if it quitted
2 parents 0ac76e5 + 16839bf commit 105b935

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

networkd/network_monitor_thread.ml

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ let clear_input fd =
278278
loop ();
279279
Unix.clear_nonblock fd
280280

281-
let ip_watcher () =
281+
let rec ip_watcher () =
282282
let cmd = Network_utils.iproute2 in
283283
let args = ["monitor"; "address"] in
284284
let readme, writeme = Unix.pipe () in
@@ -299,12 +299,26 @@ let ip_watcher () =
299299
end;
300300
loop ()
301301
in
302+
let restart_ip_watcher () = begin
303+
Unix.close readme;
304+
Thread.delay 5.0;
305+
ip_watcher ();
306+
end
307+
in
302308
while true do
303309
try
304310
info "(Re)started IP watcher thread";
305311
loop ()
306312
with e ->
307-
warn "Error in IP watcher: %s\n%s" (Printexc.to_string e) (Printexc.get_backtrace ())
313+
warn "Error in IP watcher: %s\n%s" (Printexc.to_string e) (Printexc.get_backtrace ());
314+
match !watcher_pid with
315+
| None -> restart_ip_watcher ()
316+
| Some pid ->
317+
let quitted, _ = Forkhelpers.waitpid_nohang pid in
318+
if quitted <> 0 then begin
319+
warn "address monitoring process quitted, try to restart it";
320+
restart_ip_watcher ()
321+
end
308322
done
309323

310324
let start () =

0 commit comments

Comments
 (0)