Skip to content

Commit a495619

Browse files
committed
Merge pull request #8 from djs55/master
Fix interaction with /sbin/ip and execute_command_get_output
2 parents 290fa56 + 84ca0f3 commit a495619

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

lib/network_utils.ml

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,17 @@ let call_script ?(log_successful_output=false) script args =
3939
Unix.access script [ Unix.X_OK ];
4040
(* Use the same $PATH as xapi *)
4141
let env = [| "PATH=" ^ (Sys.getenv "PATH") |] in
42-
let output, _ = Forkhelpers.execute_command_get_output ~env script args in
43-
if log_successful_output then
44-
debug "Call '%s %s' succeeded [output = '%s']" script (String.concat " " args) output;
45-
output
42+
info "%s %s" script (String.concat " " args);
43+
44+
let readme, writeme = Unix.pipe () in
45+
let pid = Forkhelpers.safe_close_and_exec ~env None (Some writeme) None [] script args in
46+
Unix.close writeme;
47+
(* assume output is never larger than a pipe buffer *)
48+
Forkhelpers.waitpid pid;
49+
let output = String.make 16384 '\000' in
50+
let n = Unix.read readme output 0 (String.length output) in
51+
Unix.close readme;
52+
String.sub output 0 n
4653
with
4754
| Unix.Unix_error (e, a, b) ->
4855
error "Caught unix error: %s [%s, %s]" (Unix.error_message e) a b;
@@ -161,8 +168,10 @@ module Ip = struct
161168
call_script ~log_successful_output:log iproute2 args
162169

163170
let find output attr =
171+
info "Looking for %s in [%s]" attr output;
164172
let args = String.split_f String.isspace output in
165173
let indices = (List.position (fun s -> s = attr) args) in
174+
info "Found at [ %s ]" (String.concat ", " (List.map string_of_int indices));
166175
List.map (fun i -> List.nth args (succ i)) indices
167176

168177
let get_link_flags dev =

0 commit comments

Comments
 (0)