[sysprof] capture-writer: ftruncate() when creating capture



commit 71e1134cbce95ecf8b9dee1d3a1c4328419a2aec
Author: Christian Hergert <chergert redhat com>
Date:   Sun Oct 16 13:23:16 2016 -0700

    capture-writer: ftruncate() when creating capture
    
    We risk overwriting existing data leaving our file in a somewhat broken
    state. So first ftruncate() to zero so we are starting from scratch.

 lib/sp-capture-writer.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
---
diff --git a/lib/sp-capture-writer.c b/lib/sp-capture-writer.c
index 564437d..15dcfbb 100644
--- a/lib/sp-capture-writer.c
+++ b/lib/sp-capture-writer.c
@@ -375,6 +375,9 @@ sp_capture_writer_new_from_fd (int   fd,
   g_assert (fd != -1);
   g_assert (buffer_size % getpagesize() == 0);
 
+  if (ftruncate (fd, 0) != 0)
+    return NULL;
+
   self = g_new0 (SpCaptureWriter, 1);
   self->ref_count = 1;
   self->fd = fd;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]