Re: [DynInst_API:] Rewriter output file naming question


Date: Thu, 29 Nov 2012 17:35:10 -0800
From: Josh Stone <jistone@xxxxxxxxxx>
Subject: Re: [DynInst_API:] Rewriter output file naming question
On 11/29/2012 03:56 PM, Andrew Bernat wrote:
> The way we're using it. 
> 
> libelf internally maps a file into memory with mmap in shared mode; this
> means that changes to the file are apparent to libelf. When we start
> modifying the file to write a new one, that ... well, it screws
> everything up. 

OK, I see.  Well disallowing the same input and output is an easy
heuristic, but it shouldn't be too bad to make it work, if you want.

Just do the writing into a mkstemp()-opened file, so you know the
destination is unique to you.  Then, do an fsync() for data consistency
and rename() to the final output filename.  Even if the old file is
still mmaped in libelf, it will refer to the old (now deleted) contents.
 This scheme should work whether or not input==output, so you don't need
to make a special case for it.

Josh
[← Prev in Thread] Current Thread [Next in Thread→]