diff options
author | Richard W.M. Jones <rjones@redhat.com> | 2012-03-15 15:49:22 +0000 |
---|---|---|
committer | Richard W.M. Jones <rjones@redhat.com> | 2012-03-15 16:15:45 +0000 |
commit | 7283a5a2765c0670e9dceec70e626a49a30d269c (patch) | |
tree | 7dcf253cf223ce8eb096c5a8e14e78c9467c1e6f /sparsify | |
parent | 31c26be91f855d661ccdfc3eeb7d4626f4085a12 (diff) | |
download | libguestfs-7283a5a2765c0670e9dceec70e626a49a30d269c.tar.gz libguestfs-7283a5a2765c0670e9dceec70e626a49a30d269c.tar.xz libguestfs-7283a5a2765c0670e9dceec70e626a49a30d269c.zip |
sparsify: Unlink temporary overlay file if user presses ^C.
Add a signal handler so this potentially large temporary file
is removed when the user hits ^C.
Diffstat (limited to 'sparsify')
-rw-r--r-- | sparsify/sparsify.ml | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/sparsify/sparsify.ml b/sparsify/sparsify.ml index bafaee57..1ab066eb 100644 --- a/sparsify/sparsify.ml +++ b/sparsify/sparsify.ml @@ -144,9 +144,13 @@ let () = (* Create the temporary overlay file. *) let overlaydisk = let tmp = Filename.temp_file "sparsify" ".qcow2" in + let unlink_tmp () = try unlink tmp with _ -> () in (* Unlink on exit. *) - at_exit (fun () -> try unlink tmp with _ -> ()); + at_exit unlink_tmp; + + (* Unlink on sigint. *) + Sys.set_signal Sys.sigint (Sys.Signal_handle (fun _ -> unlink_tmp ())); (* Create it with the indisk as the backing file. *) let cmd = |