From ae5895c3f7c30da1d1aaace0988cd236791dbc7a Mon Sep 17 00:00:00 2001 From: Steven Dake Date: Sun, 7 Jun 2009 07:47:10 +0000 Subject: [PATCH] Call initializer directly for broken platforms which don't honor ctors in the shared object on dlopen. This could probably be more tidy to detect those OS platforms which don't do this instead of hardcoding to a specific platform we intend to port to. git-svn-id: http://svn.fedorahosted.org/svn/corosync/trunk@2221 fd59a12c-fef9-0310-b244-a6a79926bd2f --- exec/coroparse.c | 7 ++++++- exec/objdb.c | 8 ++++++-- exec/vsf_quorum.c | 8 +++++++- exec/vsf_ykd.c | 8 +++++++- lcr/lcr_ifact.c | 17 +++++++++++------ services/cfg.c | 8 +++++++- services/confdb.c | 8 +++++++- services/cpg.c | 8 +++++++- services/evs.c | 8 +++++++- services/pload.c | 8 +++++++- services/testquorum.c | 8 +++++++- services/votequorum.c | 8 +++++++- 12 files changed, 86 insertions(+), 18 deletions(-) diff --git a/exec/coroparse.c b/exec/coroparse.c index ace9c010..08919179 100644 --- a/exec/coroparse.c +++ b/exec/coroparse.c @@ -318,8 +318,13 @@ struct lcr_comp aisparser_comp_ver0 = { .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); } diff --git a/exec/objdb.c b/exec/objdb.c index 33309c8e..2e0e3296 100644 --- a/exec/objdb.c +++ b/exec/objdb.c @@ -1601,9 +1601,13 @@ struct lcr_comp objdb_comp_ver0 = { .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); diff --git a/exec/vsf_quorum.c b/exec/vsf_quorum.c index 4b75997e..79e4aba3 100644 --- a/exec/vsf_quorum.c +++ b/exec/vsf_quorum.c @@ -191,7 +191,13 @@ static struct corosync_service_engine_iface_ver0 quorum_service_handler_iface = .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); } diff --git a/exec/vsf_ykd.c b/exec/vsf_ykd.c index c364a639..4646651f 100644 --- a/exec/vsf_ykd.c +++ b/exec/vsf_ykd.c @@ -545,6 +545,12 @@ static struct lcr_comp vsf_ykd_comp_ver0 = { .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); } diff --git a/lcr/lcr_ifact.c b/lcr/lcr_ifact.c index bb087d78..8fade97d 100644 --- a/lcr/lcr_ifact.c +++ b/lcr/lcr_ifact.c @@ -99,8 +99,7 @@ static int lcr_select_so (struct dirent *dirent) 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 @@ static int pathlist_select (struct dirent *dirent) return (0); } -#endif static inline struct lcr_component_instance *lcr_comp_find ( const char *iface_name, @@ -219,7 +217,6 @@ static void ld_library_path_build (void) 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 @@ static int ldso_path_build (const char *path, const char *filename) } } fclose(fp); -#endif return (0); } @@ -369,6 +365,7 @@ static int interface_find_and_load ( 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 @@ static int interface_find_and_load ( 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; diff --git a/services/cfg.c b/services/cfg.c index d77966ca..c9cfbb47 100644 --- a/services/cfg.c +++ b/services/cfg.c @@ -314,7 +314,13 @@ static struct corosync_service_engine *cfg_get_service_engine_ver0 (void) 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); diff --git a/services/confdb.c b/services/confdb.c index e2b5fecf..6e5902df 100644 --- a/services/confdb.c +++ b/services/confdb.c @@ -254,7 +254,13 @@ static struct corosync_service_engine *confdb_get_service_engine_ver0 (void) 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); diff --git a/services/cpg.c b/services/cpg.c index b4c664c9..c852da03 100644 --- a/services/cpg.c +++ b/services/cpg.c @@ -316,7 +316,13 @@ static struct corosync_service_engine *cpg_get_service_engine_ver0 (void) 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); diff --git a/services/evs.c b/services/evs.c index d2cf3349..af85fd2b 100644 --- a/services/evs.c +++ b/services/evs.c @@ -188,7 +188,13 @@ static struct corosync_service_engine *evs_get_service_engine_ver0 (void) 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); diff --git a/services/pload.c b/services/pload.c index 60347054..78835fdf 100644 --- a/services/pload.c +++ b/services/pload.c @@ -198,7 +198,13 @@ static struct corosync_service_engine *pload_get_service_engine_ver0 (void) 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); diff --git a/services/testquorum.c b/services/testquorum.c index 2e84056f..9db90d59 100644 --- a/services/testquorum.c +++ b/services/testquorum.c @@ -95,7 +95,13 @@ static struct lcr_comp test_quorum_comp_ver0 = { .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); } diff --git a/services/votequorum.c b/services/votequorum.c index a4f79e5e..2bfa8102 100644 --- a/services/votequorum.c +++ b/services/votequorum.c @@ -363,7 +363,13 @@ static struct corosync_service_engine *quorum_get_service_handler_ver0 (void) 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);