Author: Armin Rigo <[email protected]>
Branch: reverse-debugger
Changeset: r85512:d23597283e75
Date: 2016-07-02 09:27 +0200
http://bitbucket.org/pypy/pypy/changeset/d23597283e75/
Log: Test and fix: fork() creates children which also continue to write
to the same log file, corrupting it
diff --git a/rpython/translator/revdb/src-revdb/revdb.c
b/rpython/translator/revdb/src-revdb/revdb.c
--- a/rpython/translator/revdb/src-revdb/revdb.c
+++ b/rpython/translator/revdb/src-revdb/revdb.c
@@ -127,6 +127,14 @@
}
}
+static void close_revdb_fileno_in_fork_child(void)
+{
+ if (rpy_rev_fileno >= 0) {
+ close(rpy_rev_fileno);
+ rpy_rev_fileno = -1;
+ }
+}
+
static void setup_record_mode(int argc, char *argv[])
{
char *filename = getenv("PYPYRDB");
@@ -169,6 +177,8 @@
rpy_revdb.buf_p = rpy_rev_buffer + sizeof(int16_t);
rpy_revdb.buf_limit = rpy_rev_buffer + sizeof(rpy_rev_buffer) - 32;
rpy_revdb.unique_id_seen = 1;
+
+ pthread_atfork(NULL, NULL, close_revdb_fileno_in_fork_child);
}
static void flush_buffer(void)
@@ -221,10 +231,11 @@
{
/* ===== FINALIZERS =====
- When the GC wants to invoke some finalizers, it causes this
- to be called at the stop point. The new-style finalizers
- are only enqueued at this point. The old-style finalizers
- run immediately, conceptually just *after* the stop point.
+ When the GC wants to invoke some finalizers, it causes this to
+ be called at the stop point. (This is not called at *every*
+ stop point.) The new-style finalizers are only enqueued at
+ this point. The old-style finalizers run immediately,
+ conceptually just *after* the stop point.
*/
int i;
char *p = rpy_rev_buffer;
diff --git a/rpython/translator/revdb/test/test_basic.py
b/rpython/translator/revdb/test/test_basic.py
--- a/rpython/translator/revdb/test/test_basic.py
+++ b/rpython/translator/revdb/test/test_basic.py
@@ -369,6 +369,10 @@
dbstate.stuff.x = i + 1000
revdb.stop_point()
print op
+ if i == 1:
+ if os.fork() == 0: # child
+ os.write(2, "this line is from the fork child.\n")
+ return 0
return 9
compile(cls, main, backendopt=False)
assert run(cls, 'abc d ef') == 'abc\nd\nef\n'
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit