Blame SOURCES/ElectricFence-2.2.2-pthread.patch

94c734
--- ElectricFence-2.2.2/efence.c.jj	1999-04-12 21:00:49.000000000 -0400
94c734
+++ ElectricFence-2.2.2/efence.c	2003-02-03 11:20:18.000000000 -0500
94c734
@@ -174,6 +174,15 @@ static int		internalUse = 0;
94c734
 static int		noAllocationListProtection = 0;
94c734
 
94c734
 #ifdef USE_SEMAPHORE
94c734
+
94c734
+#include <stdbool.h>
94c734
+
94c734
+#pragma weak sem_init
94c734
+#pragma weak sem_post
94c734
+#pragma weak sem_wait
94c734
+
94c734
+static int		pthread_initialization = 0;
94c734
+
94c734
 /*
94c734
  * EF_sem is a semaphore used to allow one thread at a time into
94c734
  * these routines.
94c734
@@ -274,7 +283,7 @@ initialize(void)
94c734
 	EF_Print(version);
94c734
 
94c734
 #ifdef USE_SEMAPHORE
94c734
-	if (sem_init(&EF_sem, 0, 1) >= 0) {
94c734
+	if (sem_init != NULL && !pthread_initialization && sem_init(&EF_sem, 0, 1) >= 0) {
94c734
 		semEnabled = 1;
94c734
 	}
94c734
 #endif
94c734
@@ -397,6 +406,21 @@ initialize(void)
94c734
 	release();
94c734
 }
94c734
 
94c734
+#ifdef USE_SEMAPHORE
94c734
+void
94c734
+__libc_malloc_pthread_startup (bool first_time)
94c734
+{
94c734
+	if (first_time) {
94c734
+		pthread_initialization = 1;
94c734
+		initialize ();
94c734
+	} else {
94c734
+		pthread_initialization = 0;
94c734
+		if (!semEnabled && sem_init != NULL && sem_init(&EF_sem, 0, 1) >= 0)
94c734
+			semEnabled = 1;
94c734
+	}
94c734
+}
94c734
+#endif
94c734
+
94c734
 /*
94c734
  * allocateMoreSlots is called when there are only enough slot structures
94c734
  * left to support the allocation of a single malloc buffer.
94c734
--- ElectricFence-2.2.2/Makefile.jj	1999-04-13 13:22:49.000000000 -0400
94c734
+++ ElectricFence-2.2.2/Makefile	2003-02-03 11:27:06.000000000 -0500
94c734
@@ -1,6 +1,6 @@
94c734
 PIC= -fPIC
94c734
 CFLAGS= -g -DUSE_SEMAPHORE $(PIC)
94c734
-LIBS= -lpthread
94c734
+LIBS=
94c734
 
94c734
 prefix=/usr
94c734
 BIN_INSTALL_DIR= $(prefix)/bin
94c734
@@ -54,8 +54,8 @@ libefence.a: $(OBJECTS)
94c734
 	$(AR) crv libefence.a $(OBJECTS)
94c734
 
94c734
 libefence.so.0.0: $(OBJECTS)
94c734
-	gcc -g -shared -Wl,-soname,libefence.so.0 -o libefence.so.0.0 \
94c734
-		$(OBJECTS) -lpthread -lc 
94c734
+	gcc -shared -Wl,-soname,libefence.so.0 -o libefence.so.0.0 \
94c734
+		$(CFLAGS) $(OBJECTS) 
94c734
 
94c734
 tstheap: libefence.a tstheap.o
94c734
 	- rm -f tstheap