git » libfiu » commit fad96ca

Run a function at fork time

author Alberto Bertogli
2009-05-22 02:23:31 UTC
committer Alberto Bertogli
2009-05-22 02:23:31 UTC
parent 62178a1b8d487f074c8efaa61c49f6dcd507f76c

Run a function at fork time

Not really used at the moment, but it will in following patches.

Signed-off-by: Alberto Bertogli <albertito@blitiri.com.ar>

libfiu/fiu.c +12 -0

diff --git a/libfiu/fiu.c b/libfiu/fiu.c
index ef06c17..f00ef8f 100644
--- a/libfiu/fiu.c
+++ b/libfiu/fiu.c
@@ -183,6 +183,13 @@ static double randd(void)
 	return (double) randd_xn / UINT_MAX;
 }
 
+/* Function that runs after the process has been forked, at the child. It's
+ * registered via pthread_atfork() in fiu_init(). */
+static void atfork_child(void)
+{
+
+}
+
 
 /*
  * Core API
@@ -206,6 +213,11 @@ int fiu_init(unsigned int flags)
 	enabled_fails_len = 0;
 	enabled_fails_nfree = 0;
 
+	if (pthread_atfork(NULL, NULL, atfork_child) != 0) {
+		ef_wunlock();
+		return -1;
+	}
+
 	initialized = 1;
 
 	ef_wunlock();