summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikos Mavrogiannopoulos <nmav@redhat.com>2015-11-16 16:25:31 +0100
committerNikos Mavrogiannopoulos <nmav@gnutls.org>2015-11-19 13:48:44 +0100
commit4ceb994818846f42042fc229df104295c0087a07 (patch)
tree3080ef91131b55dca52f1c96d06c85a48c223451
parent1d33f7c03445835c14c5ef80f69243a93b1cf09b (diff)
downloadgnutls-4ceb994818846f42042fc229df104295c0087a07.tar.gz
Added GNUTLS_SKIP_GLOBAL_INIT macro to allow programs skip implicit global initialization
-rw-r--r--lib/gnutls_global.c29
-rw-r--r--lib/includes/gnutls/gnutls.h.in5
-rw-r--r--lib/libgnutls.map1
3 files changed, 35 insertions, 0 deletions
diff --git a/lib/gnutls_global.c b/lib/gnutls_global.c
index 404d1d4bd7..18fc33b4e9 100644
--- a/lib/gnutls_global.c
+++ b/lib/gnutls_global.c
@@ -49,6 +49,12 @@
# define _DESTRUCTOR __attribute__((destructor))
#endif
+int __attribute__((weak)) gnutls_global_init_skip(void);
+int gnutls_global_init_skip(void)
+{
+ return 0;
+}
+
/* created by asn1c */
extern const ASN1_ARRAY_TYPE gnutls_asn1_tab[];
extern const ASN1_ARRAY_TYPE pkix_asn1_tab[];
@@ -430,6 +436,17 @@ const char *gnutls_check_version(const char *req_version)
static void _CONSTRUCTOR lib_init(void)
{
int ret;
+const char *e;
+
+ if (gnutls_global_init_skip() != 0)
+ return;
+
+ e = getenv("GNUTLS_NO_EXPLICIT_INIT");
+ if (e != NULL) {
+ ret = atoi(e);
+ if (ret == 1)
+ return;
+ }
ret = gnutls_global_init();
if (ret < 0) {
@@ -440,5 +457,17 @@ int ret;
static void _DESTRUCTOR lib_deinit(void)
{
+ const char *e;
+
+ if (gnutls_global_init_skip() != 0)
+ return;
+
+ e = getenv("GNUTLS_NO_EXPLICIT_INIT");
+ if (e != NULL) {
+ int ret = atoi(e);
+ if (ret == 1)
+ return;
+ }
+
_gnutls_global_deinit(1);
}
diff --git a/lib/includes/gnutls/gnutls.h.in b/lib/includes/gnutls/gnutls.h.in
index addc3ab802..5ad2f8e449 100644
--- a/lib/includes/gnutls/gnutls.h.in
+++ b/lib/includes/gnutls/gnutls.h.in
@@ -67,6 +67,11 @@ extern "C" {
#define GNUTLS_CIPHER_RIJNDAEL_CBC GNUTLS_CIPHER_AES_128_CBC
#define GNUTLS_CIPHER_ARCFOUR GNUTLS_CIPHER_ARCFOUR_128
+/* Use the following definition globally in your program to disable
+ * implicit initialization of gnutls. */
+#define GNUTLS_SKIP_GLOBAL_INIT int gnutls_global_init_skip(void); \
+ int gnutls_global_init_skip(void) {return 1;}
+
/**
* gnutls_cipher_algorithm_t:
* @GNUTLS_CIPHER_UNKNOWN: Unknown algorithm.
diff --git a/lib/libgnutls.map b/lib/libgnutls.map
index 6e56004e71..dc41b1e670 100644
--- a/lib/libgnutls.map
+++ b/lib/libgnutls.map
@@ -1024,6 +1024,7 @@ GNUTLS_3_1_0 {
gnutls_x509_ext_deinit;
gnutls_x509_ext_print;
gnutls_x509_othername_to_virtual;
+ gnutls_global_init_skip;
} GNUTLS_3_0_0;
GNUTLS_FIPS140 {