mtrace && fork

Andreas Jaeger aj@suse.de
Mon Sep 18 06:59:00 GMT 2000


Waldo reported the following problem together with a patch for mtrace:
> With some further investigation I found the problem, ksysguard use KProcess 
> to fork and start a child process. This confuses the hell out of [k/m]trace 
> because there are now suddenly two process that write to the same logfile.

What do you think of the patch?  Is it ok to apply?  Or how shall we
handle the situation?

2000-09-18  Andreas Jaeger  <aj@suse.de>

	* malloc/mtrace.c (fork): New.  Run mtrace only in the parent.
	Patch by Waldo Bastian <bastian@suse.de>.

============================================================
Index: malloc/mtrace.c
--- malloc/mtrace.c	2000/07/13 18:40:43	1.22
+++ malloc/mtrace.c	2000/09/18 13:53:26
@@ -35,6 +35,7 @@
 #include <stdlib.h>
 
 #include <stdio-common/_itoa.h>
+#include <unistd.h>
 
 #ifdef USE_IN_LIBIO
 # include <libio/iolibio.h>
@@ -300,4 +301,26 @@
   __free_hook = tr_old_free_hook;
   __malloc_hook = tr_old_malloc_hook;
   __realloc_hook = tr_old_realloc_hook;
+}
+
+int
+fork()
+{
+ int result;
+
+ if (mallstream)
+    fflush (mallstream);
+
+ result = __fork();
+ if (result == 0)
+   {
+     if (mallstream)
+       {
+	 fclose (mallstream);
+	 __free_hook = tr_old_free_hook;
+	 __malloc_hook = tr_old_malloc_hook;
+	 __realloc_hook = tr_old_realloc_hook;
+       }
+   }
+ return result;
 }

-- 
 Andreas Jaeger
  SuSE Labs aj@suse.de
   private aj@arthur.inka.de
    http://www.suse.de/~aj


More information about the Libc-alpha mailing list