[SCM] NSS Wrapper Repository - branch master updated

Andreas Schneider asn at samba.org
Fri Dec 20 02:36:28 MST 2013


The branch, master has been updated
       via  83948bc nwrap: Add a destructor to free resources.
       via  50b0fd9 cmake: Check for printf format attribute.
      from  4ad5d31 cmake: Fix the env name for the module variables.

http://gitweb.samba.org/?p=nss_wrapper.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit 83948bc7c16bbb4ceefaf4e1f4634e8510c2d3ad
Author: Andreas Schneider <asn at samba.org>
Date:   Fri Dec 20 10:35:38 2013 +0100

    nwrap: Add a destructor to free resources.

commit 50b0fd9153dd2ffe7ec5428e5b64d87406a76130
Author: Andreas Schneider <asn at samba.org>
Date:   Fri Dec 20 09:33:00 2013 +0100

    cmake: Check for printf format attribute.

-----------------------------------------------------------------------

Summary of changes:
 ConfigureChecks.cmake |   19 +++++++++++
 config.h.cmake        |    3 ++
 src/nss_wrapper.c     |   87 +++++++++++++++++++++++++++++++++++++++++++++++-
 3 files changed, 107 insertions(+), 2 deletions(-)


Changeset truncated at 500 lines:

diff --git a/ConfigureChecks.cmake b/ConfigureChecks.cmake
index 8c7539a..afee1f8 100644
--- a/ConfigureChecks.cmake
+++ b/ConfigureChecks.cmake
@@ -218,6 +218,25 @@ int main(void) {
     return 0;
 }" HAVE_IPV6)
 
+check_c_source_compiles("
+void log_fn(const char *format, ...) __attribute__ ((format (printf, 1, 2)));
+
+int main(void) {
+    return 0;
+}" HAVE_ATTRIBUTE_PRINTF_FORMAT)
+
+check_c_source_compiles("
+void test_destructor_attribute(void) __attribute__ ((destructor));
+
+void test_destructor_attribute(void)
+{
+    return;
+}
+
+int main(void) {
+    return 0;
+}" HAVE_DESTRUCTOR_ATTRIBUTE)
+
 check_library_exists(dl dlopen "" HAVE_LIBDL)
 if (HAVE_LIBDL)
     find_library(DLFCN_LIBRARY dl)
diff --git a/config.h.cmake b/config.h.cmake
index 1fd9281..06e5738 100644
--- a/config.h.cmake
+++ b/config.h.cmake
@@ -78,6 +78,9 @@
 #cmakedefine HAVE_STRUCT_SOCKADDR_SA_LEN 1
 #cmakedefine HAVE_IPV6 1
 
+#cmakedefine HAVE_ATTRIBUTE_PRINTF_FORMAT 1
+#cmakedefine HAVE_DESTRUCTOR_ATTRIBUTE 1
+
 /*************************** ENDIAN *****************************/
 
 /* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most
diff --git a/src/nss_wrapper.c b/src/nss_wrapper.c
index 3e6d072..6b50c68 100644
--- a/src/nss_wrapper.c
+++ b/src/nss_wrapper.c
@@ -122,11 +122,17 @@ typedef nss_status_t NSS_STATUS;
 #endif
 
 /* GCC have printf type attribute check. */
-#ifdef __GNUC__
+#ifdef HAVE_ATTRIBUTE_PRINTF_FORMAT
 #define PRINTF_ATTRIBUTE(a,b) __attribute__ ((__format__ (__printf__, a, b)))
 #else
 #define PRINTF_ATTRIBUTE(a,b)
-#endif /* __GNUC__ */
+#endif /* HAVE_ATTRIBUTE_PRINTF_FORMAT */
+
+#ifdef HAVE_DESTRUCTOR_ATTRIBUTE
+#define DESTRUCTOR_ATTRIBUTE __attribute__ ((destructor))
+#else
+#define DESTRUCTOR_ATTRIBUTE
+#endif /* HAVE_DESTRUCTOR_ATTRIBUTE */
 
 #define ZERO_STRUCTP(x) do { if ((x) != NULL) memset((char *)(x), 0, sizeof(*(x))); } while(0)
 
@@ -505,9 +511,15 @@ struct nwrap_he {
 struct nwrap_cache __nwrap_cache_he;
 struct nwrap_he nwrap_he_global;
 
+
+/*********************************************************
+ * NWRAP PROTOTYPES
+ *********************************************************/
+
 static void nwrap_init(void);
 static bool nwrap_gr_parse_line(struct nwrap_cache *nwrap, char *line);
 static void nwrap_gr_unload(struct nwrap_cache *nwrap);
+void nwrap_destructor(void) DESTRUCTOR_ATTRIBUTE;
 
 /*********************************************************
  * NWRAP LIBC LOADER FUNCTIONS
@@ -4127,3 +4139,74 @@ int gethostname(char *name, size_t len)
 
 	return nwrap_gethostname(name, len);
 }
+
+/****************************
+ * DESTRUCTOR
+ ***************************/
+
+/*
+ * This function is called when the library is unloaded and makes sure that
+ * sockets get closed and the unix file for the socket are unlinked.
+ */
+void nwrap_destructor(void)
+{
+	int i;
+
+	if (nwrap_main_global != NULL) {
+		struct nwrap_main *m = nwrap_main_global;
+
+		/* libc */
+		SAFE_FREE(m->libc->fns);
+		if (m->libc->handle != NULL) {
+			dlclose(m->libc->handle);
+		}
+		if (m->libc->nsl_handle != NULL) {
+			dlclose(m->libc->nsl_handle);
+		}
+		if (m->libc->sock_handle != NULL) {
+			dlclose(m->libc->sock_handle);
+		}
+		SAFE_FREE(m->libc);
+
+		/* backends */
+		for (i = 0; i < m->num_backends; i++) {
+			struct nwrap_backend *b = &(m->backends[i]);
+
+			if (b->so_handle != NULL) {
+				dlclose(b->so_handle);
+			}
+			SAFE_FREE(b->fns);
+		}
+		SAFE_FREE(m->backends);
+	}
+
+	if (nwrap_pw_global.cache != NULL) {
+		struct nwrap_cache *c = nwrap_pw_global.cache;
+
+		nwrap_files_cache_unload(c);
+		close(c->fd);
+
+		SAFE_FREE(nwrap_pw_global.list);
+		nwrap_pw_global.num = 0;
+	}
+
+	if (nwrap_gr_global.cache != NULL) {
+		struct nwrap_cache *c = nwrap_gr_global.cache;
+
+		nwrap_files_cache_unload(c);
+		close(c->fd);
+
+		SAFE_FREE(nwrap_gr_global.list);
+		nwrap_pw_global.num = 0;
+	}
+
+	if (nwrap_he_global.cache != NULL) {
+		struct nwrap_cache *c = nwrap_he_global.cache;
+
+		nwrap_files_cache_unload(c);
+		close(c->fd);
+
+		SAFE_FREE(nwrap_he_global.list);
+		nwrap_he_global.num = 0;
+	}
+}


-- 
NSS Wrapper Repository


More information about the samba-cvs mailing list