Tools: hv: fix file overwriting of hv_fcopy_daemon
authorYue Zhang <yuezha@microsoft.com>
Sat, 28 Jun 2014 01:19:48 +0000 (18:19 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 9 Jul 2014 21:21:26 +0000 (14:21 -0700)
hv_fcopy_daemon fails to overwrite a file if the target file already
exits.

Add O_TRUNC flag on opening.

Signed-off-by: Yue Zhang <yuezha@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
tools/hv/hv_fcopy_daemon.c

index fba1c75aa484f6923ac562f5402f3bad4b2f1a0d..8f96b3ee0724c88e537c1b9f19e051d37ff45564 100644 (file)
@@ -88,7 +88,8 @@ static int hv_start_fcopy(struct hv_start_fcopy *smsg)
                }
        }
 
-       target_fd = open(target_fname, O_RDWR | O_CREAT | O_CLOEXEC, 0744);
+       target_fd = open(target_fname,
+                        O_RDWR | O_CREAT | O_TRUNC | O_CLOEXEC, 0744);
        if (target_fd == -1) {
                syslog(LOG_INFO, "Open Failed: %s", strerror(errno));
                goto done;