dlopen should read the constructors in the shared object and execute
them at the linking of the shared object into the binary.  On Solaris
this doesn't happen.

Instead, for Solaris platforms, we use dlsym to find an initializer
function and execute it.  Other platforms work as they did previously.
Index: lcr/lcr_ifact.c
===================================================================
--- lcr/lcr_ifact.c	(revision 2215)
+++ lcr/lcr_ifact.c	(working copy)
@@ -99,8 +99,7 @@
 	return (0);
 }
 
-#ifndef COROSYNC_SOLARIS
-#ifdef COROSYNC_LINUX
+#if defined(COROSYNC_LINUX) || defined(COROSYNC_SOLARIS)
 static int pathlist_select (const struct dirent *dirent)
 #else
 static int pathlist_select (struct dirent *dirent)
@@ -112,7 +111,6 @@
 
 	return (0);
 }
-#endif
 
 static inline struct lcr_component_instance *lcr_comp_find (
 	const char *iface_name,
@@ -219,7 +217,6 @@
 
 static int ldso_path_build (const char *path, const char *filename)
 {
-#ifndef COROSYNC_SOLARIS
 	FILE *fp;
 	char string[1024];
 	char filename_cat[1024];
@@ -278,7 +275,6 @@
 		}
 	}
 	fclose(fp);
-#endif
 	return (0);
 }
 
@@ -369,6 +365,7 @@
 	int scandir_entries;
 	unsigned int libs_to_scan;
 	char dl_name[1024];
+	void (*comp_reg)(void);
 
 	scandir_entries = scandir (path,  &scandir_list, lcr_select_so, alphasort);
 	if (scandir_entries > 0)
@@ -387,12 +384,20 @@
 		if (lcr_lib_loaded (dl_name)) {
 			continue;
 		}
-		dl_handle = dlopen (dl_name, RTLD_LAZY);
+		dl_handle = dlopen (dl_name, RTLD_NOW);
 		if (dl_handle == NULL) {
 			fprintf(stderr, "%s: open failed: %s\n",
 				dl_name, dlerror());
 			continue;
 		}
+/*
+ * constructors don't work in Solaris dlopen, so we have to specifically call
+ * a function to register the component
+ */
+#ifdef COROSYNC_SOLARIS
+		comp_reg = dlsym (dl_handle, "corosync_lcr_component_register");
+		comp_reg ();
+#endif
 		instance = lcr_comp_find (iface_name, version, iface_number);
 		if (instance) {
 			instance->dl_handle = dl_handle;
Index: services/cfg.c
===================================================================
--- services/cfg.c	(revision 2215)
+++ services/cfg.c	(working copy)
@@ -314,7 +314,13 @@
 	return (&cfg_service_engine);
 }
 
-__attribute__ ((constructor)) static void register_this_component (void) {
+#ifdef COROSYNC_SOLARIS
+void corosync_lcr_component_register (void);
+
+void corosync_lcr_component_register (void) {
+#else
+__attribute__ ((constructor)) static void corosync_lcr_component_register (void) {
+#endif
 	lcr_interfaces_set (&corosync_cfg_ver0[0], &cfg_service_engine_iface);
 
 	lcr_component_register (&cfg_comp_ver0);
Index: services/pload.c
===================================================================
--- services/pload.c	(revision 2215)
+++ services/pload.c	(working copy)
@@ -198,7 +198,13 @@
 	return (&pload_service_engine);
 }
 
-__attribute__ ((constructor)) static void pload_comp_register (void) {
+#ifdef COROSYNC_SOLARIS
+void corosync_lcr_component_register (void);
+
+void corosync_lcr_component_register (void) {
+#else
+__attribute__ ((constructor)) static void corosync_lcr_component_register (void) {
+#endif
 	lcr_interfaces_set (&corosync_pload_ver0[0], &pload_service_engine_iface);
 
 	lcr_component_register (&pload_comp_ver0);
Index: services/votequorum.c
===================================================================
--- services/votequorum.c	(revision 2215)
+++ services/votequorum.c	(working copy)
@@ -363,7 +363,13 @@
 	return (&quorum_service_handler);
 }
 
-__attribute__ ((constructor)) static void quorum_comp_register (void) {
+#ifdef COROSYNC_SOLARIS
+void corosync_lcr_component_register (void);
+
+void corosync_lcr_component_register (void) {
+#else
+__attribute__ ((constructor)) static void corosync_lcr_component_register (void) {
+#endif
         lcr_interfaces_set (&corosync_quorum_ver0[0], &votequorum_iface_ver0);
 	lcr_interfaces_set (&corosync_quorum_ver0[1], &quorum_service_handler_iface);
 	lcr_component_register (&quorum_comp_ver0);
Index: services/testquorum.c
===================================================================
--- services/testquorum.c	(revision 2215)
+++ services/testquorum.c	(working copy)
@@ -95,7 +95,13 @@
 	.ifaces				= corosync_test_quorum_ver0
 };
 
-__attribute__ ((constructor)) static void test_quorum_comp_register (void) {
+#ifdef COROSYNC_SOLARIS
+void corosync_lcr_component_register (void);
+
+void corosync_lcr_component_register (void) {
+#else
+__attribute__ ((constructor)) static void corosync_lcr_component_register (void) {
+#endif
 	lcr_interfaces_set (&corosync_test_quorum_ver0[0], &test_quorum_iface_ver0);
 	lcr_component_register (&test_quorum_comp_ver0);
 }
Index: services/cpg.c
===================================================================
--- services/cpg.c	(revision 2215)
+++ services/cpg.c	(working copy)
@@ -316,7 +316,13 @@
 	return (&cpg_service_engine);
 }
 
-__attribute__ ((constructor)) static void cpg_comp_register (void) {
+#ifdef COROSYNC_SOLARIS
+void corosync_lcr_component_register (void);
+
+void corosync_lcr_component_register (void) {
+#else
+__attribute__ ((constructor)) static void corosync_lcr_component_register (void) {
+#endif
         lcr_interfaces_set (&corosync_cpg_ver0[0], &cpg_service_engine_iface);
 
 	lcr_component_register (&cpg_comp_ver0);
Index: services/confdb.c
===================================================================
--- services/confdb.c	(revision 2215)
+++ services/confdb.c	(working copy)
@@ -254,7 +254,13 @@
 	return (&confdb_service_engine);
 }
 
-__attribute__ ((constructor)) static void confdb_comp_register (void) {
+#ifdef COROSYNC_SOLARIS
+void corosync_lcr_component_register (void);
+
+void corosync_lcr_component_register (void) {
+#else
+__attribute__ ((constructor)) static void corosync_lcr_component_register (void) {
+#endif
         lcr_interfaces_set (&corosync_confdb_ver0[0], &confdb_service_engine_iface);
 
 	lcr_component_register (&confdb_comp_ver0);
Index: services/evs.c
===================================================================
--- services/evs.c	(revision 2215)
+++ services/evs.c	(working copy)
@@ -188,7 +188,13 @@
 	return (&evs_service_engine);
 }
 
-__attribute__ ((constructor)) static void evs_comp_register (void) {
+#ifdef COROSYNC_SOLARIS
+void corosync_lcr_component_register (void);
+
+void corosync_lcr_component_register (void) {
+#else
+__attribute__ ((constructor)) static void corosync_lcr_component_register (void) {
+#endif
 	lcr_interfaces_set (&corosync_evs_ver0[0], &evs_service_engine_iface);
 
 	lcr_component_register (&evs_comp_ver0);
Index: exec/vsf_quorum.c
===================================================================
--- exec/vsf_quorum.c	(revision 2215)
+++ exec/vsf_quorum.c	(working copy)
@@ -191,7 +191,13 @@
 	.corosync_get_service_engine_ver0 = quorum_get_service_handler_ver0
 };
 
-__attribute__ ((constructor)) static void quorum_comp_register (void) {
+#ifdef COROSYNC_SOLARIS
+void corosync_lcr_component_register (void);
+
+void corosync_lcr_component_register (void) {
+#else
+__attribute__ ((constructor)) static void corosync_lcr_component_register (void) {
+#endif
 	lcr_component_register (&quorum_comp_ver0);
 	lcr_interfaces_set (&corosync_quorum_ver0[0], &quorum_service_handler_iface);
 }
Index: exec/objdb.c
===================================================================
--- exec/objdb.c	(revision 2215)
+++ exec/objdb.c	(working copy)
@@ -1601,9 +1601,13 @@
 	.ifaces				= objdb_iface_ver0
 };
 
+#ifdef COROSYNC_SOLARIS
+void corosync_lcr_component_register (void);
 
-
-__attribute__ ((constructor)) static void objdb_comp_register (void) {
+void corosync_lcr_component_register (void) {
+#else
+__attribute__ ((constructor)) static void corosync_lcr_component_register (void) {
+#endif
         lcr_interfaces_set (&objdb_iface_ver0[0], &objdb_iface);
 
 	lcr_component_register (&objdb_comp_ver0);
Index: exec/coroparse.c
===================================================================
--- exec/coroparse.c	(revision 2215)
+++ exec/coroparse.c	(working copy)
@@ -317,8 +318,13 @@
 	.ifaces					= corosync_aisparser_ver0
 };
 
+#ifdef COROSYNC_SOLARIS
+void corosync_lcr_component_register (void);
 
-__attribute__ ((constructor)) static void aisparser_comp_register (void) {
+void corosync_lcr_component_register (void) {
+#else
+__attribute__ ((constructor)) static void corosync_lcr_component_register (void) {
+#endif
         lcr_interfaces_set (&corosync_aisparser_ver0[0], &aisparser_iface_ver0);
 	lcr_component_register (&aisparser_comp_ver0);
 }
Index: exec/vsf_ykd.c
===================================================================
--- exec/vsf_ykd.c	(revision 2215)
+++ exec/vsf_ykd.c	(working copy)
@@ -545,6 +545,12 @@
 	.ifaces				= corosync_vsf_ykd_ver0
 };
 
-__attribute__ ((constructor)) static void vsf_ykd_comp_register (void) {
+#ifdef COROSYNC_SOLARIS
+void corosync_lcr_component_register (void);
+
+void corosync_lcr_component_register (void) {
+#else 
+__attribute__ ((constructor)) static void corosync_lcr_component_register (void) {
+#endif
 	lcr_component_register (&vsf_ykd_comp_ver0);
 }
_______________________________________________
Openais mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/openais

Reply via email to