Просмотр исходного кода

Fix reference counting in LCR code. Also fix problem with inability to compile
from the exec directory because PREFIX wasn't defined for lcr_ifact.c.


git-svn-id: http://svn.fedorahosted.org/svn/corosync/trunk@1451 fd59a12c-fef9-0310-b244-a6a79926bd2f

Steven Dake 18 лет назад
Родитель
Сommit
37e4f0f59c
5 измененных файлов с 35 добавлено и 24 удалено
  1. 1 1
      Makefile.inc
  2. 1 1
      exec/Makefile
  3. 7 1
      lcr/Makefile
  4. 24 19
      lcr/lcr_ifact.c
  5. 2 2
      lcr/test.c

+ 1 - 1
Makefile.inc

@@ -1,5 +1,5 @@
 # Common options
 # Common options
-PREFIX=/usr/local
+PREFIX=/usr
 DESTDIR=
 DESTDIR=
 
 
 # Do not modify below this line
 # Do not modify below this line

+ 1 - 1
exec/Makefile

@@ -206,7 +206,7 @@ depend:
 
 
 # - fPIC rules required for service handler shared objects
 # - fPIC rules required for service handler shared objects
 ../lcr/lcr_ifact.o: ../lcr/lcr_ifact.c
 ../lcr/lcr_ifact.o: ../lcr/lcr_ifact.c
-	$(CC) $(CFLAGS) $(CPPFLAGS) -I../lcr -c -o $@ ../lcr/lcr_ifact.c
+	$(CC) $(CFLAGS) $(CPPFLAGS) -DPREFIX='"$(PREFIX)"' -I../lcr -c -o $@ ../lcr/lcr_ifact.c
 
 
 evs.o: evs.c
 evs.o: evs.c
 	$(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $(*F).c
 	$(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $(*F).c

+ 7 - 1
lcr/Makefile

@@ -61,7 +61,7 @@ libtest_b.lcrso: libtest_b.o
 endif
 endif
 	
 	
 test: test.o uis.o lcr_ifact.o
 test: test.o uis.o lcr_ifact.o
-	$(CC) $(LDFLAGS) test.o lcr_ifact.o uis.o -lpthread -o test
+	$(CC) $(LDFLAGS) -fPIC test.o lcr_ifact.o uis.o -lpthread -o test
 
 
 test_static: test.o libtest_a.o libtest_b.o uis.o lcr_ifact.o
 test_static: test.o libtest_a.o libtest_b.o uis.o lcr_ifact.o
 	$(CC) $(LDFLAGS) test.o libtest_a.o libtest_b.o lcr_ifact.o -o test_static
 	$(CC) $(LDFLAGS) test.o libtest_a.o libtest_b.o lcr_ifact.o -o test_static
@@ -75,6 +75,12 @@ libtest_a.o: libtest_a.c
 libtest_b.o: libtest_b.c
 libtest_b.o: libtest_b.c
 	$(CC) $(CFLAGS) $(CPPFLAGS) -fPIC -c -o $@ $(*F).c
 	$(CC) $(CFLAGS) $(CPPFLAGS) -fPIC -c -o $@ $(*F).c
 
 
+lcr_ifact.o: lcr_ifact.c
+	$(CC) $(CFLAGS) $(CPPFLAGS) -fPIC -c -o $@ $(*F).c
+
+test.o: test.c
+	$(CC) $(CFLAGS) $(CPPFLAGS) -fPIC -c -o $@ $(*F).c
+
 clean:
 clean:
 	rm -f test libtest.so* *.o uic liblcr.so* liblcr.a *.lcrso *.da *.ba *.bb *.bbg \
 	rm -f test libtest.so* *.o uic liblcr.so* liblcr.a *.lcrso *.da *.ba *.bb *.bbg \
 	test_static
 	test_static

+ 24 - 19
lcr/lcr_ifact.c

@@ -47,6 +47,7 @@
 struct lcr_component_instance {
 struct lcr_component_instance {
 	struct lcr_iface *ifaces;
 	struct lcr_iface *ifaces;
 	int iface_count;
 	int iface_count;
+	unsigned int comp_handle;
 	void *dl_handle;
 	void *dl_handle;
 	int refcount;
 	int refcount;
 	char library_name[256];
 	char library_name[256];
@@ -70,7 +71,7 @@ static struct hdb_handle_database lcr_iface_instance_database = {
 	.iterator	= 0
 	.iterator	= 0
 };
 };
 
 
-static unsigned int g_component_handle;
+static unsigned int g_component_handle = 0xFFFFFFFF;
 
 
 #if defined(OPENAIS_LINUX) || defined(OPENAIS_SOLARIS)
 #if defined(OPENAIS_LINUX) || defined(OPENAIS_SOLARIS)
 static int lcr_select_so (const struct dirent *dirent)
 static int lcr_select_so (const struct dirent *dirent)
@@ -174,7 +175,6 @@ static void defaults_path_build (void)
 
 
 	res = getcwd (cwd, sizeof (cwd));
 	res = getcwd (cwd, sizeof (cwd));
 	if (res != NULL) {
 	if (res != NULL) {
-		strcat (cwd, "/");
 		path_list[0] = strdup (cwd);
 		path_list[0] = strdup (cwd);
 		path_list_entries++;
 		path_list_entries++;
 	}
 	}
@@ -386,8 +386,8 @@ static int interface_find_and_load (
 		}
 		}
 
 
 		/*
 		/*
-		 * No matching interfaces found, try next shared object
-		 */
+		* No matching interfaces found, try next shared object
+		*/
 		if (g_component_handle != 0xFFFFFFFF) {
 		if (g_component_handle != 0xFFFFFFFF) {
 			hdb_handle_destroy (&lcr_component_instance_database,
 			hdb_handle_destroy (&lcr_component_instance_database,
 				g_component_handle);
 				g_component_handle);
@@ -450,19 +450,19 @@ int lcr_ifact_reference (
 
 
 // TODO error checking in this code is weak
 // TODO error checking in this code is weak
 	/*
 	/*
-	 * Find all *.lcrso files in search paths
+	 * Search through all lcrso files for desired interface
 	 */
 	 */
 	for (i = 0; i < path_list_entries; i++) {
 	for (i = 0; i < path_list_entries; i++) {
-	res = interface_find_and_load (
-		path_list[i],
-		iface_name,
-		version,
-		&instance,
-		&iface_number);
-
-	if (res == 0) {
-		goto found;
-	}
+		res = interface_find_and_load (
+			path_list[i],
+			iface_name,
+			version,
+			&instance,
+			&iface_number);
+
+		if (res == 0) {
+			goto found;
+		}
 	}
 	}
 
 
 	/*
 	/*
@@ -480,9 +480,10 @@ found:
 		iface_handle);
 		iface_handle);
 	hdb_handle_get (&lcr_iface_instance_database,
 	hdb_handle_get (&lcr_iface_instance_database,
 		*iface_handle, (void *)&iface_instance);
 		*iface_handle, (void *)&iface_instance);
-	iface_instance->component_handle = g_component_handle;
+	iface_instance->component_handle = instance->comp_handle;
 	iface_instance->context = context;
 	iface_instance->context = context;
 	iface_instance->destructor = instance->ifaces[iface_number].destructor;
 	iface_instance->destructor = instance->ifaces[iface_number].destructor;
+	hdb_handle_put (&lcr_iface_instance_database, *iface_handle);
 	return (0);
 	return (0);
 }
 }
 
 
@@ -509,17 +510,21 @@ int lcr_ifact_release (unsigned int handle)
 void lcr_component_register (struct lcr_comp *comp)
 void lcr_component_register (struct lcr_comp *comp)
 {
 {
 	struct lcr_component_instance *instance;
 	struct lcr_component_instance *instance;
+	static unsigned int comp_handle;
 
 
 	hdb_handle_create (&lcr_component_instance_database,
 	hdb_handle_create (&lcr_component_instance_database,
 		sizeof (struct lcr_component_instance),
 		sizeof (struct lcr_component_instance),
-		&g_component_handle);
+		&comp_handle);
 	hdb_handle_get (&lcr_component_instance_database,
 	hdb_handle_get (&lcr_component_instance_database,
-		g_component_handle, (void *)&instance);
+		comp_handle, (void *)&instance);
 
 
 	instance->ifaces = comp->ifaces;
 	instance->ifaces = comp->ifaces;
 	instance->iface_count = comp->iface_count;
 	instance->iface_count = comp->iface_count;
+	instance->comp_handle = comp_handle;
 	instance->dl_handle = NULL;
 	instance->dl_handle = NULL;
 
 
 	hdb_handle_put (&lcr_component_instance_database,
 	hdb_handle_put (&lcr_component_instance_database,
-		g_component_handle);
+		comp_handle);
+
+	g_component_handle = comp_handle;
 }
 }

+ 2 - 2
lcr/test.c

@@ -85,7 +85,7 @@ int main (void) {
 		(void *)0xaaaa1111);
 		(void *)0xaaaa1111);
 	assert (res == 0);
 	assert (res == 0);
 
 
-	a_iface_ver1 = (struct iface *)a_iface_ver0_p;
+	a_iface_ver1 = (struct iface *)a_iface_ver1_p;
 
 
 	res = lcr_ifact_reference (
 	res = lcr_ifact_reference (
 		&b_ifact_handle_ver1,
 		&b_ifact_handle_ver1,
@@ -95,7 +95,7 @@ int main (void) {
 		(void *)0xbbbb1111);
 		(void *)0xbbbb1111);
 	assert (res == 0);
 	assert (res == 0);
 
 
-	b_iface_ver1 = (struct iface *)b_iface_ver0_p;
+	b_iface_ver1 = (struct iface *)b_iface_ver1_p;
 
 
 	a_iface_ver0->func1();
 	a_iface_ver0->func1();
 	a_iface_ver0->func2();
 	a_iface_ver0->func2();