Commits

Jimmy Li [Atlassian] committed e7cf05a

Restored constructor and destructor methods, previous technique is broken on CentOS 5

Comments (0)

Files changed (3)

src/crowd_client.c

 /**
  * Must be called before the first use of the Crowd Client.
  */
-void crowd_init(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s) {
+void crowd_init() {
     user_xml_name = xml_string("user");
     groups_xml_name = xml_string("groups");
     group_xml_name = xml_string("group");
     email_xml_name = xml_string("email");
     link_xml_name = xml_string("link");
     if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
-        ap_log_error(APLOG_MARK, APLOG_CRIT, 0, s, PACKAGE_STRING " failed to initialise libcurl.");
+        fprintf(stderr, PACKAGE_STRING " failed to initialise libcurl.");
         exit(1);
     }
     xmlInitParser();

src/crowd_client.h

 /**
  * Must be called before the first use of the Crowd Client.
  */
-void crowd_init(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s);
+void crowd_init();
 
 bool crowd_cache_create(apr_pool_t *pool, apr_time_t max_age, unsigned int max_entries);
 

src/crowdsso/mod_auth_crowdsso.c

             ap_log_error(APLOG_MARK, APLOG_INFO, 0, s, "Memcached host not configured, using in-process cache.");
         }
     }
-    
-    
+
     return OK;
 }
 
 {
     static const char * const pre_auth_checker[]={ "mod_authz_user.c", NULL };
     ap_hook_post_config(post_config, NULL, NULL, APR_HOOK_MIDDLE);
-    ap_hook_post_config(crowd_init, NULL, NULL, APR_HOOK_LAST);
     ap_hook_check_user_id(check_user_id, NULL, NULL, APR_HOOK_FIRST);
-
-    // There is no shutdown hook but we can run the crowd_cleanup with p's cleanup (which lasts for the lifetime of the module)
-    apr_pool_cleanup_register(p, NULL, crowd_cleanup, apr_pool_cleanup_null);
-
     ap_log_perror(APLOG_MARK, APLOG_NOTICE, 0, p, "mod_auth_crowdsso " PACKAGE_VERSION " installed.");
 }
 
     commands,
     register_hooks
 };
+
+/* Library initialisation and termination functions */
+/* TODO: Another solution will likely be required for non-GCC platforms, e.g. Windows */
+
+void init() __attribute__ ((constructor));
+
+void init()
+{
+    crowd_init();
+}
+
+void term() __attribute__ ((destructor));
+
+void term()
+{
+    crowd_cleanup();
+}