+ (* Get the name of the remote bridge. *)
+ let bridge =
+ let cmd =
+ sprintf "ssh root@%s brctl show | sort" (quote hostname) in
+ if verbose then printf "%s\n%!" cmd;
+ let chan = Unix.open_process_in cmd in
+ let lines = ref [] in
+ (try while true do lines := input_line chan :: !lines done
+ with End_of_file -> ());
+ let stat = Unix.close_process_in chan in
+ (match stat with
+ | Unix.WEXITED 0 -> ()
+ | Unix.WEXITED i ->
+ eprintf "mclu: 'brctl show' exited with error %d\n" i;
+ exit 1
+ | Unix.WSIGNALED i ->
+ eprintf "mclu: 'brctl show' killed by signal %d\n" i;
+ exit 1
+ | Unix.WSTOPPED i ->
+ eprintf "mclu: 'brctl show' stopped by signal %d\n" i;
+ exit 1
+ );
+ let lines = List.rev !lines in
+ (* A heuristic: Use brX, but if none exist, try virbrX. *)
+ let brname = ref None in
+ let virbrname = ref None in
+ List.iter (
+ fun line ->
+ match Pcre.split ~rex:ws_rex line with
+ | str :: _ when Pcre.pmatch ~rex:br_rex str ->
+ if !brname = None then
+ brname := Some str
+ | str :: _ when Pcre.pmatch ~rex:virbr_rex str ->
+ if !virbrname = None then
+ virbrname := Some str
+ | _ -> ()
+ ) lines;
+
+ match !brname with
+ | Some br -> br
+ | None ->
+ match !virbrname with
+ | Some br -> br
+ | None ->
+ eprintf "mclu: Could not get remote bridge name\n";
+ exit 1 in
+