Log file with mkstemp() suffix or not? Re: r15435
Christian Stimming
stimming at tuhh.de
Mon Mar 1 08:12:40 EST 2010
Can someone explain to me the intention of the following code that
initialiizes the trace file output file descriptor (from
src/libqof/qof/qoflog.c:157ff)
fname = g_strconcat(log_filename, ".XXXXXX", NULL);
if ((fd = g_mkstemp(fname)) != -1)
{
g_rename(fname, log_filename);
fout = fdopen(fd, "w");
}
where log_filename=="/tmp/gnucash.trace", so that fname will be
something like "/tmp/gnucash.trace.KSHDJS". From reading the code, I
guess it should mean "Open gnucash.trace.KSHDJS as trace file and
immediately after opening it, rename it back into gnucash.trace".
That's at least what the introduction of this code in
http://svn.gnucash.org/trac/changeset/15435 suggests.
However, this isn't what is happening. Instead, the trace files keep
their suffix so that in /tmp, plenty of .gnucash.trace.ABCDEF files
will accumulate over time. Doesn't this mean this code is wrong?
I'm asking because on win32/MSVC, I get a failed runtime assertion in
libc at the g_rename. This might be because on Windows, the OS does
not allow opened files to be renamed, but in any case
g_file_open_tmp() is probably the better choice for win32 anyway.
But for Linux, the question is still what this code should have
achieved and why it doesn't achieve this?
Puzzled,
Christian
More information about the gnucash-devel
mailing list