strip_binaries.patch
  Strip the old binary.

malloc_threads.patch
  Some compiler versions have problem with declaring a variable just before
  using it, so this patch converts threads to a pointer and create it using
  malloc().

install_old_header.patch
  Make the library Makefile install old.h

acquire_on_wakeup.patch
  Unbelievable but true: the server never really locked the object when
  acquiring it due to being in a waitqueue, so two users could be told
  simultaneously that they acquired it.

malloc_check.patch
  In the library, do some malloc() checks that were missing, fix a strange but
  possible memory leak and also a segmentation fault.

extern_C.patch
  Allow the library header to be used properly in C++ programs by surrounding it
  with extern "C".

doc-old_connect_return.patch
  Document old_connect()'s return value.

lib-remove_perror.patch
  Remove perror() calls from libold.c

version-0.14.patch
  Version 0.14



unchanged:
--- cur/Makefile~strip_binaries	2004-01-17 22:59:26.000000000 -0300
+++ cur-root/Makefile	2004-01-17 22:59:49.000000000 -0300
@@ -19,7 +19,7 @@ install: all lib_install man_install
 
 $(BUILD)/old: ${OBJS}
 	$(CC) $(CFLAGS) -o $(BUILD)/old $(OBJS) $(LIBS)
-	#strip $(BUILD)/old
+	strip $(BUILD)/old
 
 .c.o:
 	$(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@
unchanged:
--- cur/main.c~malloc_threads	2004-04-20 18:40:54.000000000 -0300
+++ cur-root/main.c	2004-04-20 18:44:14.000000000 -0300
@@ -24,6 +24,7 @@ int main(int argc, char **argv)
 {
 	int i, nthreads;
 	pid_t pid;
+	pthread_t *threads;
 
 	/* parse the command line, we only have one optional parameter to tell
 	 * the number of processing threads */
@@ -72,11 +73,11 @@ int main(int argc, char **argv)
 	}
 	
 	/* create the threads */
-	pthread_t threads[nthreads];
+	threads = malloc(nthreads * sizeof(pthread_t));
 	for (i = 0; i < nthreads; i++) {
 		/* we pass the thread number as the parameter pointer, which
 		 * is used to index several arrays inside net.c */
-		pthread_create(&threads[i], NULL, &net_proc_loop, (void *) &i);
+		pthread_create(threads + i, NULL, &net_proc_loop, (void *) &i);
 	}
 
 	/* main select loop */
@@ -84,7 +85,7 @@ int main(int argc, char **argv)
 	
 	/* wait for threads to complete */
 	for (i = 0; i < nthreads; i++) {
-		pthread_join(threads[i], NULL);
+		pthread_join(*(threads + i), NULL);
 	}
 	
 	return 0;
unchanged:
--- cur/lib/Makefile~install_old_header	2004-04-20 18:54:47.000000000 -0300
+++ cur-root/lib/Makefile	2004-04-20 18:55:27.000000000 -0300
@@ -7,8 +7,8 @@ default: all
 all: pre $(BUILD)/libold.so $(BUILD)/oldtest $(BUILD)/oldtest2
 
 install: all
-	install -g root -o root -m 0755 $(BUILD)/libold.so \
-		$(PREFIX)/lib/libold.so
+	install -g root -o root -m 0755 $(BUILD)/libold.so $(PREFIX)/lib
+	install -g root -o root -m 0644 old.h $(PREFIX)/include
 	@echo "Please run 'ldconfig' to update your library cache"
 
 pre:
unchanged:
--- cur/net.c~acquire_on_wakeup	2004-04-20 19:25:15.000000000 -0300
+++ cur-root/net.c	2004-04-20 19:25:58.000000000 -0300
@@ -547,6 +547,9 @@ int net_wakeup(struct hentry *h) {
 	free(h->wq);
 	h->wq = p;
 	h->fd = fd;
+
+	/* of course, mark it locked */
+	h->locked = 1;
 	
 	/* add the open lock; the caller will take care to remove from the
 	 * other queue */
unchanged:
--- cur-root/lib/libold.c	2004-04-27 11:01:38.000000000 -0300
+++ cur-root/lib/libold.c	2004-04-27 21:27:08.000000000 -0300
@@ -7,7 +7,6 @@
  */
 
 #include <stdlib.h>
-#include <stdio.h>
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <netdb.h>
@@ -66,6 +65,9 @@
 		
 	/* parse it */
 	cmd = (struct net_cmd *) malloc(sizeof(struct net_cmd));
+	if (unlikely(cmd == NULL))
+		return NULL;
+
 	memset(cmd, 0, sizeof(struct net_cmd));
 	
 	cmd->ver = buf[0] >> 4;
@@ -74,11 +76,16 @@
 		((int) buf[2] << 8) + ((int) buf[3]);
 
 	if (unlikely(cmd->ver != 1 || cmd->len > MAX_PAYLOAD)) {
+		free(cmd);
 		return NULL;
 	}
 	
 	if (likely(cmd->len)) {
 		cmd->payload = (char *) malloc(cmd->len);
+		if (unlikely(cmd->payload == NULL)) {
+			free(cmd);
+			return NULL;
+		}
 		memset(cmd->payload, 0, cmd->len);
 	} else {
 		cmd->payload = NULL;
@@ -92,8 +99,10 @@
 	}
 	
 	s = read(fd, cmd->payload, cmd->len);
-	if (unlikely(s != cmd->len))
+	if (unlikely(s != cmd->len)) {
+		free(cmd);
 		return NULL;
+	}
 	
 	/* the command is complete! */
 	return cmd;
@@ -113,6 +122,9 @@
 		/* if we get an ACK, just wait for a definitive answer */
 		cmd = get_cmd(fd);
 
+	 if (unlikely(cmd == NULL))
+		 return -1;
+
 	if (cmd->op == REP_LOCK_ACQUIRED)
 		return 1;
 	
@@ -159,7 +171,6 @@
 
 	hinfo = gethostbyname(host);
 	if (hinfo == NULL) {
-		perror("Error resolving host");
 		return -1;
 	}
 	
@@ -171,14 +182,12 @@
 
 	rv = 1;
 	if (setsockopt(fd, SOL_TCP, TCP_NODELAY, &rv, sizeof(rv)) < 0 ) {
-		perror("Error setting socket options");
 		return -1;
 	}
 			
 	
 	rv = connect(fd, (struct sockaddr *) &sa, sizeof(sa));
 	if (rv != 0) {
-		perror("Error binding");
 		return -1;
 	}
 
unchanged:
--- cur/lib/old.h~extern_C	2004-04-27 11:15:16.000000000 -0300
+++ cur-root/lib/old.h	2004-04-27 11:15:16.000000000 -0300
@@ -8,6 +8,11 @@
 
 #include <stdint.h>
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
 /* some useful typedefs */
 typedef uint8_t         u8;
 typedef uint16_t        u16;
@@ -63,5 +68,10 @@ int old_lock(int fd, char *s);
 int old_unlock(int fd, char *s);
 int old_trylock(int fd, char *s);
 
+
+#ifdef __cplusplus
+} /* from extern "C" avobe */
+#endif
+
 #endif
 
unchanged:
--- cur/doc/libold.3~doc-old_connect_return	2004-04-27 21:23:41.000000000 -0300
+++ cur-root/doc/libold.3	2004-04-27 21:24:43.000000000 -0300
@@ -53,6 +53,7 @@ can be an IP address or the name of the 
 second one is the port to connect to, it should be the same one the server is
 expecting connections. When possible, use the default defined in
 .BR OLD_PORT .
+It returns the connection's file descriptor, or -1 if there was an error.
 .PP
 .B old_lock()
 is used to lock the given resource, and it will block until the lock is
only in patch2:
unchanged:
--- cur/Make.conf~version-0.14	2004-04-27 21:30:34.000000000 -0300
+++ cur-root/Make.conf	2004-04-27 21:30:41.000000000 -0300
@@ -1,5 +1,5 @@
 
-VERSION = "0.12"
+VERSION = "0.14"
 
 CC = gcc
 CFLAGS += -Wall -O6
