[Gnucash-changes] r14235 - gnucash/trunk - Add wait_for_gzip to
avoid reading from a file that is still being
Andreas Köhler
andi5 at cvs.gnucash.org
Mon May 29 03:08:28 EDT 2006
Author: andi5
Date: 2006-05-29 03:08:28 -0400 (Mon, 29 May 2006)
New Revision: 14235
Trac: http://svn.gnucash.org/trac/changeset/14235
Modified:
gnucash/trunk/ChangeLog
gnucash/trunk/src/backend/file/io-gncxml-v2.c
Log:
Add wait_for_gzip to avoid reading from a file that is still being
written to by a child process, a race condition at the end of the xml
import druid.
Modified: gnucash/trunk/ChangeLog
===================================================================
--- gnucash/trunk/ChangeLog 2006-05-29 06:02:00 UTC (rev 14234)
+++ gnucash/trunk/ChangeLog 2006-05-29 07:08:28 UTC (rev 14235)
@@ -1,3 +1,9 @@
+2006-05-29 Andreas Köhler <andi5.py at gmx.net>
+
+ * src/backend/file/io-gncxml-v2.c: Add wait_for_gzip to avoid
+ reading from a file that is still being written to by a child
+ process, a race condition at the end of the xml import druid.
+
2006-05-28 David Hampton <hampton at employees.org>
* src/pixmaps/gnucash_splash.png: New splash screen from Joshua
Modified: gnucash/trunk/src/backend/file/io-gncxml-v2.c
===================================================================
--- gnucash/trunk/src/backend/file/io-gncxml-v2.c 2006-05-29 06:02:00 UTC (rev 14234)
+++ gnucash/trunk/src/backend/file/io-gncxml-v2.c 2006-05-29 07:08:28 UTC (rev 14235)
@@ -28,6 +28,7 @@
#include <unistd.h>
#include <zlib.h>
#include <errno.h>
+#include <sys/wait.h>
#include "gnc-engine.h"
#include "gnc-pricedb-p.h"
@@ -51,6 +52,8 @@
static QofLogModule log_module = GNC_MOD_IO;
+static pid_t gzip_child_pid = 0;
+
/* Callback structure */
struct file_backend {
gboolean ok;
@@ -1282,6 +1285,10 @@
int filedes[2];
pid_t pid;
+ /* avoid reading from file that is still being written to
+ by a child process */
+ g_assert(gzip_child_pid == 0);
+
if (pipe(filedes) < 0) {
PWARN("Pipe call failed. Opening uncompressed file.");
return fopen(filename, perms);
@@ -1320,6 +1327,10 @@
}
default: /* parent */
+ if (compress) {
+ /* the calling code must wait_for_gzip() */
+ gzip_child_pid = pid;
+ }
sleep(2);
if (compress) {
close(filedes[0]);
@@ -1335,6 +1346,20 @@
#endif
}
+static gboolean
+wait_for_gzip()
+{
+ pid_t retval;
+
+ if (gzip_child_pid == 0)
+ return TRUE;
+
+ retval = waitpid(gzip_child_pid, NULL, WUNTRACED);
+ gzip_child_pid = 0;
+
+ return retval != -1;
+}
+
gboolean
gnc_book_write_to_xml_file_v2(
QofBook *book,
@@ -1358,6 +1383,9 @@
return FALSE;
}
+ if (compress)
+ return wait_for_gzip();
+
return TRUE;
}
More information about the gnucash-changes
mailing list