Skip to content

Commit 0bbf2b1

Browse files
author
Jon Ludlam
committed
Merge pull request #25 from andyhhp/ca-121503
CA-121503 - Make use of rc and stderr in the case of an error
2 parents fce9351 + e475731 commit 0bbf2b1

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

networkd_db/networkd_db.ml

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ let name = "networkd_db"
2020
let _ =
2121
let bridge = ref "" in
2222
let iface = ref "" in
23+
let rc = ref 0 in
2324
Arg.parse (Arg.align [
2425
"-bridge", Arg.Set_string bridge, "Bridge name";
2526
"-iface", Arg.Set_string iface, "Interface name";
@@ -34,9 +35,10 @@ let _ =
3435
let bridge_config = List.assoc !bridge config.bridge_config in
3536
let ifaces = List.flatten (List.map (fun (_, port) -> port.interfaces) bridge_config.ports) in
3637
Printf.printf "interfaces=%s\n" (String.concat "," ifaces)
37-
end else
38-
print_endline ("Could not find bridge " ^ !bridge);
39-
38+
end else begin
39+
rc := 1;
40+
Printf.fprintf stderr "Could not find bridge %s\n" !bridge;
41+
end;
4042
if !iface <> "" then
4143
if List.mem_assoc !iface config.interface_config then begin
4244
let interface_config = List.assoc !iface config.interface_config in
@@ -92,8 +94,10 @@ let _ =
9294
in
9395
let data = datav4 @ datav6 in
9496
List.iter (fun (k, v) -> Printf.printf "%s=%s\n" k v) data
95-
end else
96-
print_endline ("Could not find interface " ^ !iface);
97+
end else begin
98+
rc := 1;
99+
Printf.fprintf stderr "Could not find interface %s\n" !iface;
100+
end;
97101
with Network_config.Read_error ->
98-
print_endline ("Failed to read " ^ name)
99-
102+
Printf.fprintf stderr "Failed to read %s\n" name;
103+
exit !rc;

0 commit comments

Comments
 (0)