mllib: make external_command echo the command executed

Add an optional parameter to disable this behaviour, so the Curl module
in v2v won't print user-sensible data (like passwords).
This commit is contained in:
Pino Toscano
2016-05-23 13:23:00 +02:00
parent 9de9300e8b
commit 3dad36dab2
6 changed files with 9 additions and 7 deletions

View File

@@ -43,7 +43,6 @@ let verify_checksum csum filename =
in
let cmd = sprintf "%s %s" prog (quote filename) in
debug "%s" cmd;
let lines = external_command cmd in
match lines with
| [] ->

View File

@@ -99,7 +99,6 @@ and download_to t ?(progress_bar = false) ~proxy uri filename =
t.curl
(if verbose () then "" else " -s -S")
(quote uri) in
debug "%s" cmd;
let lines = external_command cmd in
if List.length lines < 1 then
error (f_"unexpected output from curl command, enable debug and look at previous messages");

View File

@@ -69,7 +69,6 @@ let import_keyfile ~gpg ~gpghome ?(trust = true) keyfile =
* fingerprint of the subkeys. *)
let cmd = sprintf "%s --homedir %s --with-colons --with-fingerprint --with-fingerprint --list-keys %s"
gpg gpghome !fingerprint in
debug "%s" cmd;
let lines = external_command cmd in
let current = ref None in
let subkeys = ref [] in

View File

@@ -649,7 +649,9 @@ let compare_lvm2_uuids uuid1 uuid2 =
loop 0 0
(* Run an external command, slurp up the output as a list of lines. *)
let external_command cmd =
let external_command ?(echo_cmd = true) cmd =
if echo_cmd then
debug "%s" cmd;
let chan = Unix.open_process_in cmd in
let lines = ref [] in
(try while true do lines := input_line chan :: !lines done

View File

@@ -239,8 +239,11 @@ val compare_version : string -> string -> int
val compare_lvm2_uuids : string -> string -> int
(** Compare two LVM2 UUIDs, ignoring '-' characters. *)
val external_command : string -> string list
(** Run an external command, slurp up the output as a list of lines. *)
val external_command : ?echo_cmd:bool -> string -> string list
(** Run an external command, slurp up the output as a list of lines.
[echo_cmd] specifies whether to output the full command on verbose
mode, and it's on by default. *)
val uuidgen : unit -> string
(** Run uuidgen to return a random UUID. *)

View File

@@ -48,7 +48,7 @@ let run curl_args =
close_out chan;
let cmd = sprintf "curl -q --config %s" (Filename.quote config_file) in
let lines = external_command cmd in
let lines = external_command ~echo_cmd:false cmd in
Unix.unlink config_file;
lines