From ee3e5c10464b31f8911a3574f4420b383ecb3f05 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fredrik=20H=C3=BCbinette=20=28Hubbe=29?= <hubbe@hubbe.net>
Date: Wed, 17 Sep 1997 03:31:52 -0700
Subject: [PATCH] fork_child callback added

Rev: src/callback.c:1.10
Rev: src/callback.h:1.5
Rev: src/modules/files/efuns.c:1.36
Rev: src/modules/system/system.c:1.28
---
 src/callback.c              |  3 ++-
 src/callback.h              |  2 ++
 src/modules/files/efuns.c   |  4 ++++
 src/modules/system/system.c | 17 +++++++++++++++--
 4 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/src/callback.c b/src/callback.c
index 14f52f86cf..021b2fd07c 100644
--- a/src/callback.c
+++ b/src/callback.c
@@ -7,6 +7,8 @@
 #include "callback.h"
 #include "error.h"
 
+struct callback_list fork_child_callback;
+
 /*
  * This file is used to simplify the management of callbacks when certain
  * events occur. The callbacks are managed as linked lists, allocated in
@@ -160,7 +162,6 @@ void call_callback(struct callback_list *lst, void *arg)
       l->call(l,l->arg, arg);
       if(lst->num_calls != this_call) return;
     }
-    check_callback_chain(lst);
 
     if(!l->call)
     {
diff --git a/src/callback.h b/src/callback.h
index 051aaea88c..388d4a761e 100644
--- a/src/callback.h
+++ b/src/callback.h
@@ -16,6 +16,8 @@ struct callback_list
   int num_calls;
 };
 
+extern struct callback_list fork_child_callback;
+
 typedef void (*callback_func)(struct callback *, void *,void *);
 
 /* Prototypes begin here */
diff --git a/src/modules/files/efuns.c b/src/modules/files/efuns.c
index 66c0fff91c..e8f1c09a46 100644
--- a/src/modules/files/efuns.c
+++ b/src/modules/files/efuns.c
@@ -517,6 +517,10 @@ void f_fork(INT32 args)
 #else
   push_int(res=fork());
 #endif
+  if(!res && res!=-1)
+  {
+    call_callback(&fork_child_callback, 0);
+  }
 #if defined(_REENTRANT)
   if(!res)
   {
diff --git a/src/modules/system/system.c b/src/modules/system/system.c
index f8523c07e9..ed18986046 100644
--- a/src/modules/system/system.c
+++ b/src/modules/system/system.c
@@ -1,5 +1,5 @@
 /*
- * $Id: system.c,v 1.27 1997/09/11 19:36:21 grubba Exp $
+ * $Id: system.c,v 1.28 1997/09/17 10:31:52 hubbe Exp $
  *
  * System-call module for Pike
  *
@@ -14,7 +14,7 @@
 #include "system.h"
 
 #include <global.h>
-RCSID("$Id: system.c,v 1.27 1997/09/11 19:36:21 grubba Exp $");
+RCSID("$Id: system.c,v 1.28 1997/09/17 10:31:52 hubbe Exp $");
 #include <module_support.h>
 #include <las.h>
 #include <interpret.h>
@@ -604,6 +604,7 @@ int my_isipnr(char *s)
 
 #else /* HAVE_OSF1_GETHOSTBYNAME_R */
 static MUTEX_T gethostbyname_mutex;
+#define GETHOSTBYNAME_MUTEX_EXISTS
 
 #define GETHOST_DECLARE struct hostent *ret
 
@@ -761,6 +762,14 @@ void f_gethostbyname(INT32 args)
 }  
 #endif /* HAVE_GETHOSTBYNAME */
 
+
+#ifdef GETHOSTBYNAME_MUTEX_EXISTS
+static void cleanup_after_fork()
+{
+  mt_init(&gethostbyname_mutex);
+}
+#endif
+
 /*
  * Module linkage
  */
@@ -864,6 +873,10 @@ void pike_module_init(void)
 #ifdef HAVE_SETPWENT
   add_efun("setpwent", f_setpwent, "function(void:int)", OPT_EXTERNAL_DEPEND);
 #endif
+
+#ifdef GETHOSTBYNAME_MUTEX_EXISTS
+  add_to_callback(& fork_child_callback, cleanup_after_fork, 0, 0);
+#endif
 }
 
 void pike_module_exit(void)
-- 
GitLab