Clean up patch to make handling of constructor cleanup more portable

This commit is contained in:
Dan Walsh 2011-04-06 11:19:19 -04:00
parent 8723500e16
commit 3d499ceb03
2 changed files with 64 additions and 13 deletions

View File

@ -288,7 +288,7 @@ index 36ce029..83d2143 100644
/*
* If we failed to disable, SELinux will still be
diff --git a/libselinux/src/matchpathcon.c b/libselinux/src/matchpathcon.c
index f3e45af..1333aa0 100644
index f3e45af..da5cab9 100644
--- a/libselinux/src/matchpathcon.c
+++ b/libselinux/src/matchpathcon.c
@@ -2,6 +2,7 @@
@ -299,16 +299,15 @@ index f3e45af..1333aa0 100644
#include "selinux_internal.h"
#include "label_internal.h"
#include "callbacks.h"
@@ -16,7 +17,7 @@ static __thread int con_array_size;
static __thread int con_array_used;
@@ -17,6 +18,7 @@ static __thread int con_array_used;
static pthread_once_t once = PTHREAD_ONCE_INIT;
-static pthread_key_t destructor_key;
+static pthread_key_t destructor_key = -1;
static pthread_key_t destructor_key;
+static int destructor_key_initialized = 0;
static int add_array_elt(char *con)
{
@@ -60,7 +61,7 @@ static void
@@ -60,7 +62,7 @@ static void
{
va_list ap;
va_start(ap, fmt);
@ -317,6 +316,23 @@ index f3e45af..1333aa0 100644
va_end(ap);
}
@@ -292,12 +294,14 @@ static void matchpathcon_thread_destructor(void __attribute__((unused)) *ptr)
void __attribute__((destructor)) matchpathcon_lib_destructor(void)
{
- __selinux_key_delete(destructor_key);
+ if (destructor_key_initialized)
+ __selinux_key_delete(destructor_key);
}
static void matchpathcon_init_once(void)
{
- __selinux_key_create(&destructor_key, matchpathcon_thread_destructor);
+ if (__selinux_key_create(&destructor_key, matchpathcon_thread_destructor) == 0)
+ destructor_key_initialized = 1;
}
int matchpathcon_init_prefix(const char *path, const char *subset)
diff --git a/libselinux/src/selinux.py b/libselinux/src/selinux.py
index fd63a4f..705012c 100644
--- a/libselinux/src/selinux.py
@ -406,7 +422,7 @@ index e040959..f4c33df 100644
{
return get_path(SEPGSQL_CONTEXTS);
diff --git a/libselinux/src/selinux_internal.h b/libselinux/src/selinux_internal.h
index fdddfaf..c67c102 100644
index fdddfaf..806e87c 100644
--- a/libselinux/src/selinux_internal.h
+++ b/libselinux/src/selinux_internal.h
@@ -3,6 +3,7 @@
@ -425,6 +441,18 @@ index fdddfaf..c67c102 100644
hidden_proto(selinux_file_context_subs_path)
hidden_proto(selinux_netfilter_context_path)
hidden_proto(selinux_homedir_context_path)
@@ -114,10 +116,7 @@ extern int selinux_page_size hidden;
/* Pthread key macros */
#define __selinux_key_create(KEY, DESTRUCTOR) \
- do { \
- if (pthread_key_create != NULL) \
- pthread_key_create(KEY, DESTRUCTOR); \
- } while (0)
+ (pthread_key_create != NULL ? pthread_key_create(KEY, DESTRUCTOR) : -1)
#define __selinux_key_delete(KEY) \
do { \
diff --git a/libselinux/src/selinuxswig_python.i b/libselinux/src/selinuxswig_python.i
index dea0e80..bb227e9 100644
--- a/libselinux/src/selinuxswig_python.i
@ -1510,15 +1538,35 @@ index e0884f6..b131d2e 100644
SWIG_Python_SetConstant(d, "SELINUX_CB_LOG",SWIG_From_int((int)(0)));
SWIG_Python_SetConstant(d, "SELINUX_CB_AUDIT",SWIG_From_int((int)(1)));
diff --git a/libselinux/src/setrans_client.c b/libselinux/src/setrans_client.c
index 4bdbe08..eb18ca0 100644
index 4bdbe08..e074142 100644
--- a/libselinux/src/setrans_client.c
+++ b/libselinux/src/setrans_client.c
@@ -34,7 +34,7 @@ static __thread char *prev_r2c_trans = NULL;
static __thread security_context_t prev_r2c_raw = NULL;
@@ -35,6 +35,7 @@ static __thread security_context_t prev_r2c_raw = NULL;
static pthread_once_t once = PTHREAD_ONCE_INIT;
-static pthread_key_t destructor_key;
+static pthread_key_t destructor_key = -1;
static pthread_key_t destructor_key;
+static int destructor_key_initialized = 0;
static __thread char destructor_initialized;
/*
@@ -254,7 +255,8 @@ static void setrans_thread_destructor(void __attribute__((unused)) *unused)
void __attribute__((destructor)) setrans_lib_destructor(void)
{
- __selinux_key_delete(destructor_key);
+ if (destructor_key_initialized)
+ __selinux_key_delete(destructor_key);
}
static inline void init_thread_destructor(void)
@@ -267,7 +269,9 @@ static inline void init_thread_destructor(void)
static void init_context_translations(void)
{
- __selinux_key_create(&destructor_key, setrans_thread_destructor);
+ if (__selinux_key_create(&destructor_key, setrans_thread_destructor) == 0)
+ destructor_key_initialized = 1;
+
mls_enabled = is_selinux_mls_enabled();
}

View File

@ -7,7 +7,7 @@
Summary: SELinux library and simple utilities
Name: libselinux
Version: 2.0.99
Release: 5%{?dist}
Release: 6%{?dist}
License: Public Domain
Group: System Environment/Libraries
Source: http://www.nsa.gov/research/selinux/%{name}-%{version}.tgz
@ -236,6 +236,9 @@ exit 0
%{ruby_sitearch}/selinux.so
%changelog
* Wed Apr 5 2011 Dan Walsh <dwalsh@redhat.com> - 2.0.99-6
- Clean up patch to make handling of constructor cleanup more portable
* Tue Apr 5 2011 Dan Walsh <dwalsh@redhat.com> - 2.0.99-5
- Add distribution subs path