[Libguestfs] [PATCH 1/2] common/mlstdutils: Add with_open_in and with_open_out functions.
Pino Toscano
ptoscano at redhat.com
Thu Nov 16 12:19:23 UTC 2017
On Sunday, 5 November 2017 20:42:40 CET Richard W.M. Jones wrote:
> These safe wrappers around Pervasives.open_in and Pervasives.open_out
> ensure that exceptions escaping cannot leave unclosed files.
> ---
Mostly LGTM, just one note/improvement.
> diff --git a/v2v/input_libvirt_vddk.ml b/v2v/input_libvirt_vddk.ml
> index 63e76a5aa..e29fbc2b7 100644
> --- a/v2v/input_libvirt_vddk.ml
> +++ b/v2v/input_libvirt_vddk.ml
> @@ -240,10 +240,11 @@ object
> "password=-"
> | Some password ->
> let password_file = tmpdir // "password" in
> - let chan = open_out password_file in
> - chmod password_file 0o600;
> - output_string chan password;
> - close_out chan;
> + with_open_out password_file (
> + fun chan ->
> + chmod password_file 0o600;
> + output_string chan password
> + );
Now that I see this, the chmod could be directly on the fd of the open
channel, to be sure to perform it on the actual file:
fchmod (descr_of_out_channel chan) 0o600;
Thanks,
--
Pino Toscano
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: This is a digitally signed message part.
URL: <http://listman.redhat.com/archives/libguestfs/attachments/20171116/0fe8030e/attachment.sig>
More information about the Libguestfs
mailing list