80c334b
diff --git a/libselinux/include/selinux/avc.h b/libselinux/include/selinux/avc.h
80c334b
index da18e41..9655957 100644
80c334b
--- a/libselinux/include/selinux/avc.h
80c334b
+++ b/libselinux/include/selinux/avc.h
80c334b
@@ -130,7 +130,7 @@ struct avc_memory_callback {
80c334b
 
80c334b
 struct avc_log_callback {
80c334b
 	/* log the printf-style format and arguments. */
80c334b
-	void (*func_log) (const char *fmt, ...);
80c334b
+	void (*func_log) (const char *fmt, ...) __attribute__((__format__(printf, 1, 2)));
80c334b
 	/* store a string representation of auditdata (corresponding
80c334b
 	   to the given security class) into msgbuf. */
80c334b
 	void (*func_audit) (void *auditdata, security_class_t cls,
5cb2893
diff --git a/libselinux/include/selinux/label.h b/libselinux/include/selinux/label.h
5cb2893
index 1a54307..f6eeb21 100644
5cb2893
--- a/libselinux/include/selinux/label.h
5cb2893
+++ b/libselinux/include/selinux/label.h
5cb2893
@@ -46,8 +46,10 @@ struct selabel_handle;
5cb2893
 #define SELABEL_OPT_PATH	3
5cb2893
 /* select a subset of the search space as an optimization (file backend) */
5cb2893
 #define SELABEL_OPT_SUBSET	4
5cb2893
+/* like subset, but an array of subsets */
5cb2893
+#define SELABEL_OPT_PREFIXES	5
5cb2893
 /* total number of options */
5cb2893
-#define SELABEL_NOPT		5
5cb2893
+#define SELABEL_NOPT		6
5cb2893
 
5cb2893
 /*
5cb2893
  * Label operations
a8fa875
diff --git a/libselinux/include/selinux/selinux.h b/libselinux/include/selinux/selinux.h
80c334b
index 2985f6f..e0b2dd4 100644
a8fa875
--- a/libselinux/include/selinux/selinux.h
a8fa875
+++ b/libselinux/include/selinux/selinux.h
5cb2893
@@ -139,7 +139,10 @@ struct av_decision {
5cb2893
 /* Structure for passing options, used by AVC and label subsystems */
5cb2893
 struct selinux_opt {
5cb2893
 	int type;
5cb2893
-	const char *value;
5cb2893
+	union {
5cb2893
+		const char *value;
5cb2893
+		const char **values;
5cb2893
+	};
5cb2893
 };
5cb2893
 
5cb2893
 /* Callback facilities */
5cb2893
@@ -410,6 +413,11 @@ extern int matchpathcon_init(const char *path);
5cb2893
    regexes that have stems that are prefixes of 'prefix'. */
5cb2893
 extern int matchpathcon_init_prefix(const char *path, const char *prefix);
a8fa875
 
5cb2893
+/* Same as matchpathcon_init, but only load entries with
5cb2893
+ * regexes that have stems that are prefixes of the 'prefixes'
5cb2893
+ * array of entries.  The last entry must be NULL. */
5cb2893
+extern int matchpathcon_init_prefixes(const char *patch, const char **prefixes);
a8fa875
+
5cb2893
 /* Free the memory allocated by matchpathcon_init. */
5cb2893
 extern void matchpathcon_fini(void);
5cb2893
 
80c334b
@@ -537,7 +545,7 @@ extern int selinux_check_securetty_context(const security_context_t tty_context)
80c334b
    Normally, this is determined automatically during libselinux 
80c334b
    initialization, but this is not always possible, e.g. for /sbin/init
80c334b
    which performs the initial mount of selinuxfs. */
80c334b
-void set_selinuxmnt(char *mnt);
80c334b
+void set_selinuxmnt(const char *mnt);
80c334b
 
80c334b
 /* Check if selinuxfs exists as a kernel filesystem */
80c334b
 int selinuxfs_exists(void);
10e77a8
diff --git a/libselinux/man/man3/matchpathcon.3 b/libselinux/man/man3/matchpathcon.3
5cb2893
index cdbb252..b6814ed 100644
10e77a8
--- a/libselinux/man/man3/matchpathcon.3
10e77a8
+++ b/libselinux/man/man3/matchpathcon.3
5cb2893
@@ -8,7 +8,9 @@ matchpathcon, matchpathcon_index \- get the default SELinux security context for
10e77a8
 
10e77a8
 .BI "int matchpathcon_init(const char *" path ");"
10e77a8
 
10e77a8
-.BI "int matchpathcon_init_prefix(const char *" path ", const char *" subset ");"
10e77a8
+.BI "int matchpathcon_init_prefix(const char *" path ", const char *" prefix ");"
5cb2893
+
5cb2893
+.BI "int matchpathcon_init_prefixes(const char *" path ", const char **" prefixes ");"
10e77a8
 
10e77a8
 .BI "int matchpathcon_fini(void);"
10e77a8
 .sp
5cb2893
@@ -50,6 +52,14 @@ by
10e77a8
 .I prefix.
5cb2893
 
10e77a8
 .sp
5cb2893
+.B matchpathcon_init_prefixes
5cb2893
+is the same as
5cb2893
+.B matchpathcon_init_prefix
5cb2893
+but takes an array of
5cb2893
+.I prefixes
5cb2893
+instead of a single prefix.  The last entry in the array must be NULL.
5cb2893
+
5cb2893
+.sp
10e77a8
 .B matchpathcon_fini
10e77a8
 frees the memory allocated by a prior call to
5cb2893
 .B matchpathcon_init.
10e77a8
diff --git a/libselinux/man/man3/selabel_open.3 b/libselinux/man/man3/selabel_open.3
ad8477f
index 8674e37..fc5b120 100644
10e77a8
--- a/libselinux/man/man3/selabel_open.3
10e77a8
+++ b/libselinux/man/man3/selabel_open.3
ad8477f
@@ -37,8 +37,11 @@ structures of length
ad8477f
 .ta 4n 16n 24n
ad8477f
 .nf
ad8477f
 struct selinux_opt {
ad8477f
-	int	type;
ad8477f
-	const char	*value;
ad8477f
+	int type;
ad8477f
+	union {
ad8477f
+		const char *value;
ad8477f
+		const char **values;
ad8477f
+	};
ad8477f
 };
ad8477f
 .fi
ad8477f
 .ta
ad8477f
@@ -66,6 +69,13 @@ A non-null value for this option enables context validation.  By default,
10e77a8
 is used; a custom validation function can be provided via
10e77a8
 .BR selinux_set_callback (3).
10e77a8
 Note that an invalid context may not be treated as an error unless it is actually encountered during a lookup operation.
10e77a8
+.TP
10e77a8
+.B SELABEL_OPT_SUBSET
5113c75
+A ":" separates string of path prefixes that tell the system to only loads entries with regular expressions that could match this strings. For example "/dev:/var/run:/tmp".  This option can cause the system to use less memory and work faster, but you should only use paths that begin with a prefix.
10e77a8
+.TP
10e77a8
+.B SELABEL_OPT_PATH
10e77a8
+A string representing an alternate path the the regular expressions.
10e77a8
+.sp
10e77a8
 
10e77a8
 .SH "BACKENDS"
10e77a8
 
ad8477f
@@ -99,4 +109,3 @@ Eamon Walsh <ewalsh@tycho.nsa.gov>
10e77a8
 .BR selabel_stats (3),
10e77a8
 .BR selinux_set_callback (3),
10e77a8
 .BR selinux (8)
10e77a8
-
80c334b
diff --git a/libselinux/man/man8/selinux.8 b/libselinux/man/man8/selinux.8
80c334b
index 1fc5b95..9f16f77 100644
80c334b
--- a/libselinux/man/man8/selinux.8
80c334b
+++ b/libselinux/man/man8/selinux.8
80c334b
@@ -12,7 +12,7 @@ enforcement of many kinds of mandatory access control policies,
80c334b
 including those based on the concepts of Type EnforcementĀ®, Role-
80c334b
 Based Access Control, and Multi-Level Security.  Background
80c334b
 information and technical documentation about SELinux can be found at
80c334b
-http://www.nsa.gov/selinux.
80c334b
+http://www.nsa.gov/research/selinux.
80c334b
 
80c334b
 The
80c334b
 .I /etc/selinux/config
80c334b
diff --git a/libselinux/src/Makefile b/libselinux/src/Makefile
80c334b
index 1ddddb0..985842d 100644
80c334b
--- a/libselinux/src/Makefile
80c334b
+++ b/libselinux/src/Makefile
80c334b
@@ -51,9 +51,29 @@ endif
80c334b
 GENERATED=$(SWIGCOUT) $(SWIGRUBYCOUT) selinuxswig_python_exception.i
80c334b
 SRCS= $(filter-out $(UNUSED_SRCS) $(GENERATED) audit2why.c, $(wildcard *.c))
80c334b
 
80c334b
+MAX_STACK_SIZE=32768
80c334b
+
80c334b
 OBJS= $(patsubst %.c,%.o,$(SRCS))
80c334b
 LOBJS= $(patsubst %.c,%.lo,$(SRCS))
80c334b
-CFLAGS ?= -Werror -Wall -W -Wundef -Wshadow -Wmissing-noreturn -Wmissing-format-attribute
80c334b
+CFLAGS ?= -Wall -W -Wundef -Wformat-y2k -Wformat-security -Winit-self -Wmissing-include-dirs \
80c334b
+          -Wunused -Wunknown-pragmas -Wstrict-aliasing -Wshadow -Wpointer-arith \
80c334b
+          -Wbad-function-cast -Wcast-align -Wwrite-strings -Wlogical-op -Waggregate-return \
80c334b
+          -Wstrict-prototypes -Wold-style-definition -Wmissing-prototypes \
80c334b
+          -Wmissing-declarations -Wmissing-noreturn -Wmissing-format-attribute \
80c334b
+          -Wredundant-decls -Wnested-externs -Winline -Winvalid-pch -Wvolatile-register-var \
80c334b
+          -Wdisabled-optimization -Wbuiltin-macro-redefined -Wmudflap -Wpacked-bitfield-compat \
80c334b
+          -Wsync-nand -Wattributes -Wcoverage-mismatch -Wmultichar -Wcpp \
80c334b
+          -Wdeprecated-declarations -Wdiv-by-zero -Wdouble-promotion -Wendif-labels -Wextra \
80c334b
+          -Wformat-contains-nul -Wformat-extra-args -Wformat-zero-length -Wformat=2 -Wmultichar \
80c334b
+          -Wnormalized=nfc -Woverflow -Wpointer-to-int-cast -Wpragmas -Wsuggest-attribute=const \
80c334b
+          -Wsuggest-attribute=noreturn -Wsuggest-attribute=pure -Wtrampolines \
80c334b
+          -Wno-missing-field-initializers -Wno-sign-compare -Wjump-misses-init \
80c334b
+          -Wno-format-nonliteral -Wframe-larger-than=$(MAX_STACK_SIZE) -Wp,-D_FORTIFY_SOURCE=2 \
80c334b
+          -fstack-protector-all --param=ssp-buffer-size=4 -fexceptions \
80c334b
+          -fasynchronous-unwind-tables -fdiagnostics-show-option -funit-at-a-time \
80c334b
+          -fipa-pure-const -Wno-suggest-attribute=pure -Wno-suggest-attribute=const \
80c334b
+          -Werror -Wno-aggregate-return -Wno-redundant-decls
80c334b
+
80c334b
 override CFLAGS += -I../include -I$(INCLUDEDIR) -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 $(EMFLAGS)
80c334b
 RANLIB=ranlib
80c334b
 
80c334b
diff --git a/libselinux/src/avc_internal.h b/libselinux/src/avc_internal.h
80c334b
index 53610e8..f851659 100644
80c334b
--- a/libselinux/src/avc_internal.h
80c334b
+++ b/libselinux/src/avc_internal.h
80c334b
@@ -20,7 +20,7 @@
80c334b
 extern void *(*avc_func_malloc) (size_t) hidden;
80c334b
 extern void (*avc_func_free) (void *)hidden;
80c334b
 
80c334b
-extern void (*avc_func_log) (const char *, ...)hidden;
80c334b
+extern void (*avc_func_log) (const char *, ...) __attribute__((__format__(printf,1,2))) hidden;
80c334b
 extern void (*avc_func_audit) (void *, security_class_t, char *, size_t)hidden;
80c334b
 
80c334b
 extern int avc_using_threads hidden;
ca9cea7
diff --git a/libselinux/src/callbacks.c b/libselinux/src/callbacks.c
ca9cea7
index b245364..7c47222 100644
ca9cea7
--- a/libselinux/src/callbacks.c
ca9cea7
+++ b/libselinux/src/callbacks.c
ca9cea7
@@ -16,6 +16,7 @@ default_selinux_log(int type __attribute__((unused)), const char *fmt, ...)
ee77868
 {
d0a06b2
 	int rc;
d0a06b2
 	va_list ap;
d0a06b2
+	if (is_selinux_enabled() == 0) return 0;
d0a06b2
 	va_start(ap, fmt);
d0a06b2
 	rc = vfprintf(stderr, fmt, ap);
d0a06b2
 	va_end(ap);
80c334b
diff --git a/libselinux/src/get_default_type.c b/libselinux/src/get_default_type.c
80c334b
index ca3d291..27f2ae5 100644
80c334b
--- a/libselinux/src/get_default_type.c
80c334b
+++ b/libselinux/src/get_default_type.c
80c334b
@@ -27,7 +27,8 @@ int get_default_type(const char *role, char **type)
80c334b
 static int find_default_type(FILE * fp, const char *role, char **type)
80c334b
 {
80c334b
 	char buf[250];
80c334b
-	char *ptr = "", *end, *t;
80c334b
+	const char *ptr = "", *end;
80c334b
+	char *t;
80c334b
 	size_t len;
80c334b
 	int found = 0;
80c334b
 
80c334b
diff --git a/libselinux/src/init.c b/libselinux/src/init.c
80c334b
index 00afde7..6d1ef33 100644
80c334b
--- a/libselinux/src/init.c
80c334b
+++ b/libselinux/src/init.c
80c334b
@@ -28,7 +28,7 @@ int obj_class_compat = 1;
80c334b
    * The file system is read/write
80c334b
    * then set this as the default file system.
80c334b
 */
80c334b
-static int verify_selinuxmnt(char *mnt)
80c334b
+static int verify_selinuxmnt(const char *mnt)
80c334b
 {
80c334b
 	struct statfs sfbuf;
80c334b
 	int rc;
80c334b
@@ -139,7 +139,7 @@ void fini_selinuxmnt(void)
80c334b
 
80c334b
 hidden_def(fini_selinuxmnt)
80c334b
 
80c334b
-void set_selinuxmnt(char *mnt)
80c334b
+void set_selinuxmnt(const char *mnt)
80c334b
 {
80c334b
 	selinux_mnt = strdup(mnt);
80c334b
 }
10e77a8
diff --git a/libselinux/src/label_file.c b/libselinux/src/label_file.c
7959ef1
index 7bc46cc..82a608c 100644
10e77a8
--- a/libselinux/src/label_file.c
10e77a8
+++ b/libselinux/src/label_file.c
10e77a8
@@ -27,6 +27,7 @@
10e77a8
  * Internals, mostly moved over from matchpathcon.c
10e77a8
  */
10e77a8
 
10e77a8
+#define MAX_PREFIX 100
10e77a8
 /* A file security context specification. */
10e77a8
 typedef struct spec {
10e77a8
 	struct selabel_lookup_rec lr;	/* holds contexts for lookup result */
5cb2893
@@ -276,7 +277,7 @@ static int compile_regex(struct saved_data *data, spec_t *spec, char **errbuf)
10e77a8
 
10e77a8
 
10e77a8
 static int process_line(struct selabel_handle *rec,
10e77a8
-			const char *path, const char *prefix,
10e77a8
+			const char *path, const char **prefix_array,
10e77a8
 			char *line_buf, int pass, unsigned lineno)
10e77a8
 {
10e77a8
 	int items, len;
5cb2893
@@ -310,12 +311,24 @@ static int process_line(struct selabel_handle *rec,
10e77a8
 	}
10e77a8
 
10e77a8
 	len = get_stem_from_spec(regex);
10e77a8
-	if (len && prefix && strncmp(prefix, regex, len)) {
10e77a8
-		/* Stem of regex does not match requested prefix, discard. */
10e77a8
-		free(regex);
10e77a8
-		free(type);
10e77a8
-		free(context);
10e77a8
-		return 0;
10e77a8
+	if (len && prefix_array[0]) {
10e77a8
+		int i = 0;
10e77a8
+		int found = 0;
10e77a8
+		while (i < MAX_PREFIX && prefix_array[i]) {
10e77a8
+			if (strncmp(prefix_array[i], regex, len) == 0) {
10e77a8
+				found = 1;
10e77a8
+				break;
10e77a8
+			}
10e77a8
+			i++;
10e77a8
+		}
10e77a8
+
10e77a8
+		if (! found) {
10e77a8
+			/* Stem of regex does not match requested prefix, discard. */
10e77a8
+			free(regex);
10e77a8
+			free(type);
10e77a8
+			free(context);
10e77a8
+			return 0;
10e77a8
+		}
10e77a8
 	}
10e77a8
 
10e77a8
 	if (pass == 1) {
5cb2893
@@ -397,7 +410,8 @@ static int init(struct selabel_handle *rec, struct selinux_opt *opts,
10e77a8
 {
10e77a8
 	struct saved_data *data = (struct saved_data *)rec->data;
10e77a8
 	const char *path = NULL;
10e77a8
-	const char *prefix = NULL;
5cb2893
+	const char *static_prefix_array[2] = {NULL, };
5cb2893
+	const char **prefix_array = static_prefix_array;
10e77a8
 	FILE *fp;
10e77a8
 	FILE *localfp = NULL;
10e77a8
 	FILE *homedirfp = NULL;
5cb2893
@@ -418,7 +432,10 @@ static int init(struct selabel_handle *rec, struct selinux_opt *opts,
10e77a8
 			path = opts[n].value;
10e77a8
 			break;
10e77a8
 		case SELABEL_OPT_SUBSET:
10e77a8
-			prefix = opts[n].value;
5cb2893
+			static_prefix_array[0] = opts[n].value;
5cb2893
+			break;
5cb2893
+		case SELABEL_OPT_PREFIXES:
5cb2893
+			prefix_array = opts[n].values;
10e77a8
 			break;
10e77a8
 		case SELABEL_OPT_BASEONLY:
10e77a8
 			baseonly = !!opts[n].value;
7959ef1
@@ -481,7 +498,7 @@ static int init(struct selabel_handle *rec, struct selinux_opt *opts,
5cb2893
 		while (getline(&line_buf, &line_len, fp) > 0) {
5cb2893
 			if (data->nspec >= maxnspec)
5cb2893
 				break;
5cb2893
-			status = process_line(rec, path, prefix, line_buf, pass, ++lineno);
5cb2893
+			status = process_line(rec, path, prefix_array, line_buf, pass, ++lineno);
5cb2893
 			if (status)
10e77a8
 				goto finish;
10e77a8
 		}
7959ef1
@@ -497,7 +514,7 @@ static int init(struct selabel_handle *rec, struct selinux_opt *opts,
5cb2893
 			while (getline(&line_buf, &line_len, homedirfp) > 0) {
5cb2893
 				if (data->nspec >= maxnspec)
5cb2893
 					break;
5cb2893
-				status = process_line(rec, homedir_path, prefix, line_buf, pass, ++lineno);
5cb2893
+				status = process_line(rec, homedir_path, prefix_array, line_buf, pass, ++lineno);
5cb2893
 				if (status)
10e77a8
 					goto finish;
10e77a8
 			}
7959ef1
@@ -507,7 +524,7 @@ static int init(struct selabel_handle *rec, struct selinux_opt *opts,
5cb2893
 			while (getline(&line_buf, &line_len, localfp) > 0) {
5cb2893
 				if (data->nspec >= maxnspec)
5cb2893
 					break;
5cb2893
-				status = process_line(rec, local_path, prefix, line_buf, pass, ++lineno);
5cb2893
+				status = process_line(rec, local_path, prefix_array, line_buf, pass, ++lineno);
5cb2893
 				if (status)
10e77a8
 					goto finish;
10e77a8
 			}
80c334b
diff --git a/libselinux/src/load_policy.c b/libselinux/src/load_policy.c
80c334b
index f569664..10e29b9 100644
80c334b
--- a/libselinux/src/load_policy.c
80c334b
+++ b/libselinux/src/load_policy.c
80c334b
@@ -369,7 +369,7 @@ int selinux_init_load_policy(int *enforce)
80c334b
 	 * Check for the existence of SELinux via selinuxfs, and 
80c334b
 	 * mount it if present for use in the calls below.  
80c334b
 	 */
80c334b
-	char *mntpoint = NULL;
80c334b
+	const char *mntpoint = NULL;
80c334b
 	if (mount(SELINUXFS, SELINUXMNT, SELINUXFS, 0, 0) == 0 || errno == EBUSY) {
80c334b
 		mntpoint = SELINUXMNT;
80c334b
 	} else {
ca9cea7
diff --git a/libselinux/src/matchpathcon.c b/libselinux/src/matchpathcon.c
80c334b
index 48f7a11..ca87bd2 100644
ca9cea7
--- a/libselinux/src/matchpathcon.c
ca9cea7
+++ b/libselinux/src/matchpathcon.c
495b754
@@ -2,6 +2,7 @@
974a6e4
 #include <string.h>
974a6e4
 #include <errno.h>
974a6e4
 #include <stdio.h>
974a6e4
+#include <syslog.h>
974a6e4
 #include "selinux_internal.h"
974a6e4
 #include "label_internal.h"
974a6e4
 #include "callbacks.h"
495b754
@@ -62,7 +63,7 @@ static void
974a6e4
 {
974a6e4
 	va_list ap;
974a6e4
 	va_start(ap, fmt);
974a6e4
-	vfprintf(stderr, fmt, ap);
974a6e4
+	vsyslog(LOG_ERR, fmt, ap);
974a6e4
 	va_end(ap);
974a6e4
 }
b5b41bc
 
80c334b
@@ -292,6 +293,8 @@ static void matchpathcon_thread_destructor(void __attribute__((unused)) *ptr)
80c334b
 	matchpathcon_fini();
80c334b
 }
80c334b
 
80c334b
+void __attribute__((destructor)) matchpathcon_lib_destructor(void);
80c334b
+
80c334b
 void __attribute__((destructor)) matchpathcon_lib_destructor(void)
80c334b
 {
80c334b
 	if (destructor_key_initialized)
80c334b
@@ -304,7 +307,7 @@ static void matchpathcon_init_once(void)
5cb2893
 		destructor_key_initialized = 1;
5cb2893
 }
8075466
 
5cb2893
-int matchpathcon_init_prefix(const char *path, const char *subset)
5cb2893
+int matchpathcon_init_prefixes(const char *path, const char **prefixes)
5cb2893
 {
5cb2893
 	if (!mycanoncon)
5cb2893
 		mycanoncon = default_canoncon;
80c334b
@@ -312,15 +315,22 @@ int matchpathcon_init_prefix(const char *path, const char *subset)
5cb2893
 	__selinux_once(once, matchpathcon_init_once);
5cb2893
 	__selinux_setspecific(destructor_key, (void *)1);
5cb2893
 
5cb2893
-	options[SELABEL_OPT_SUBSET].type = SELABEL_OPT_SUBSET;
5cb2893
-	options[SELABEL_OPT_SUBSET].value = subset;
5cb2893
+	options[SELABEL_OPT_PREFIXES].type = SELABEL_OPT_PREFIXES;
5cb2893
+	options[SELABEL_OPT_PREFIXES].values = prefixes;
5cb2893
 	options[SELABEL_OPT_PATH].type = SELABEL_OPT_PATH;
5cb2893
 	options[SELABEL_OPT_PATH].value = path;
5cb2893
 
5cb2893
 	hnd = selabel_open(SELABEL_CTX_FILE, options, SELABEL_NOPT);
5cb2893
 	return hnd ? 0 : -1;
5cb2893
 }
5cb2893
+hidden_def(matchpathcon_init_prefixes)
80c334b
+
5cb2893
+int matchpathcon_init_prefix(const char *path, const char *prefix)
5cb2893
+{
5cb2893
+	const char *prefixes[2] = { prefix, NULL };
80c334b
 
5cb2893
+	return matchpathcon_init_prefixes(path, prefixes);
5cb2893
+}
5cb2893
 hidden_def(matchpathcon_init_prefix)
8075466
 
5cb2893
 int matchpathcon_init(const char *path)
80c334b
diff --git a/libselinux/src/selinux_config.c b/libselinux/src/selinux_config.c
80c334b
index f4c33df..f42cb7c 100644
80c334b
--- a/libselinux/src/selinux_config.c
80c334b
+++ b/libselinux/src/selinux_config.c
80c334b
@@ -246,172 +246,172 @@ static const char *get_path(int idx)
80c334b
 	return file_paths[idx];
80c334b
 }
80c334b
 
80c334b
-const char *selinux_default_type_path()
80c334b
+const char *selinux_default_type_path(void)
80c334b
 {
80c334b
 	return get_path(DEFAULT_TYPE);
80c334b
 }
80c334b
 
80c334b
 hidden_def(selinux_default_type_path)
80c334b
 
80c334b
-const char *selinux_policy_root()
80c334b
+const char *selinux_policy_root(void)
80c334b
 {
80c334b
 	__selinux_once(once, init_selinux_config);
80c334b
 	return selinux_policyroot;
80c334b
 }
80c334b
 
80c334b
-const char *selinux_path()
80c334b
+const char *selinux_path(void)
80c334b
 {
80c334b
 	return selinux_rootpath;
80c334b
 }
80c334b
 
80c334b
 hidden_def(selinux_path)
80c334b
 
80c334b
-const char *selinux_default_context_path()
80c334b
+const char *selinux_default_context_path(void)
80c334b
 {
80c334b
 	return get_path(DEFAULT_CONTEXTS);
80c334b
 }
80c334b
 
80c334b
 hidden_def(selinux_default_context_path)
80c334b
 
80c334b
-const char *selinux_securetty_types_path()
80c334b
+const char *selinux_securetty_types_path(void)
80c334b
 {
80c334b
 	return get_path(SECURETTY_TYPES);
80c334b
 }
80c334b
 
80c334b
 hidden_def(selinux_securetty_types_path)
80c334b
 
80c334b
-const char *selinux_failsafe_context_path()
80c334b
+const char *selinux_failsafe_context_path(void)
80c334b
 {
80c334b
 	return get_path(FAILSAFE_CONTEXT);
80c334b
 }
80c334b
 
80c334b
 hidden_def(selinux_failsafe_context_path)
80c334b
 
80c334b
-const char *selinux_removable_context_path()
80c334b
+const char *selinux_removable_context_path(void)
80c334b
 {
80c334b
 	return get_path(REMOVABLE_CONTEXT);
80c334b
 }
80c334b
 
80c334b
 hidden_def(selinux_removable_context_path)
80c334b
 
80c334b
-const char *selinux_binary_policy_path()
80c334b
+const char *selinux_binary_policy_path(void)
80c334b
 {
80c334b
 	return get_path(BINPOLICY);
80c334b
 }
80c334b
 
80c334b
 hidden_def(selinux_binary_policy_path)
80c334b
 
80c334b
-const char *selinux_file_context_path()
80c334b
+const char *selinux_file_context_path(void)
80c334b
 {
80c334b
 	return get_path(FILE_CONTEXTS);
80c334b
 }
80c334b
 
80c334b
 hidden_def(selinux_file_context_path)
80c334b
 
80c334b
-const char *selinux_homedir_context_path()
80c334b
+const char *selinux_homedir_context_path(void)
80c334b
 {
80c334b
 	return get_path(HOMEDIR_CONTEXTS);
80c334b
 }
80c334b
 
80c334b
 hidden_def(selinux_homedir_context_path)
80c334b
 
80c334b
-const char *selinux_media_context_path()
80c334b
+const char *selinux_media_context_path(void)
80c334b
 {
80c334b
 	return get_path(MEDIA_CONTEXTS);
80c334b
 }
80c334b
 
80c334b
 hidden_def(selinux_media_context_path)
80c334b
 
80c334b
-const char *selinux_customizable_types_path()
80c334b
+const char *selinux_customizable_types_path(void)
80c334b
 {
80c334b
 	return get_path(CUSTOMIZABLE_TYPES);
80c334b
 }
80c334b
 
80c334b
 hidden_def(selinux_customizable_types_path)
80c334b
 
80c334b
-const char *selinux_contexts_path()
80c334b
+const char *selinux_contexts_path(void)
80c334b
 {
80c334b
 	return get_path(CONTEXTS_DIR);
80c334b
 }
80c334b
 
80c334b
-const char *selinux_user_contexts_path()
80c334b
+const char *selinux_user_contexts_path(void)
80c334b
 {
80c334b
 	return get_path(USER_CONTEXTS);
80c334b
 }
80c334b
 
80c334b
 hidden_def(selinux_user_contexts_path)
80c334b
 
80c334b
-const char *selinux_booleans_path()
80c334b
+const char *selinux_booleans_path(void)
80c334b
 {
80c334b
 	return get_path(BOOLEANS);
80c334b
 }
80c334b
 
80c334b
 hidden_def(selinux_booleans_path)
80c334b
 
80c334b
-const char *selinux_users_path()
80c334b
+const char *selinux_users_path(void)
80c334b
 {
80c334b
 	return get_path(USERS_DIR);
80c334b
 }
80c334b
 
80c334b
 hidden_def(selinux_users_path)
80c334b
 
80c334b
-const char *selinux_usersconf_path()
80c334b
+const char *selinux_usersconf_path(void)
80c334b
 {
80c334b
 	return get_path(SEUSERS);
80c334b
 }
80c334b
 
80c334b
 hidden_def(selinux_usersconf_path)
80c334b
 
80c334b
-const char *selinux_translations_path()
80c334b
+const char *selinux_translations_path(void)
80c334b
 {
80c334b
 	return get_path(TRANSLATIONS);
80c334b
 }
80c334b
 
80c334b
 hidden_def(selinux_translations_path)
80c334b
 
80c334b
-const char *selinux_colors_path()
80c334b
+const char *selinux_colors_path(void)
80c334b
 {
80c334b
 	return get_path(COLORS);
80c334b
 }
80c334b
 
80c334b
 hidden_def(selinux_colors_path)
80c334b
 
80c334b
-const char *selinux_netfilter_context_path()
80c334b
+const char *selinux_netfilter_context_path(void)
80c334b
 {
80c334b
 	return get_path(NETFILTER_CONTEXTS);
80c334b
 }
80c334b
 
80c334b
 hidden_def(selinux_netfilter_context_path)
80c334b
 
80c334b
-const char *selinux_file_context_homedir_path()
80c334b
+const char *selinux_file_context_homedir_path(void)
80c334b
 {
80c334b
 	return get_path(FILE_CONTEXTS_HOMEDIR);
80c334b
 }
80c334b
 
80c334b
 hidden_def(selinux_file_context_homedir_path)
80c334b
 
80c334b
-const char *selinux_file_context_local_path()
80c334b
+const char *selinux_file_context_local_path(void)
80c334b
 {
80c334b
 	return get_path(FILE_CONTEXTS_LOCAL);
80c334b
 }
80c334b
 
80c334b
 hidden_def(selinux_file_context_local_path)
80c334b
 
80c334b
-const char *selinux_x_context_path()
80c334b
+const char *selinux_x_context_path(void)
80c334b
 {
80c334b
 	return get_path(X_CONTEXTS);
80c334b
 }
80c334b
 
80c334b
 hidden_def(selinux_x_context_path)
80c334b
 
80c334b
-const char *selinux_virtual_domain_context_path()
80c334b
+const char *selinux_virtual_domain_context_path(void)
80c334b
 {
80c334b
 	return get_path(VIRTUAL_DOMAIN);
80c334b
 }
80c334b
 
80c334b
 hidden_def(selinux_virtual_domain_context_path)
80c334b
 
80c334b
-const char *selinux_virtual_image_context_path()
80c334b
+const char *selinux_virtual_image_context_path(void)
80c334b
 {
80c334b
 	return get_path(VIRTUAL_IMAGE);
80c334b
 }
80c334b
@@ -430,7 +430,7 @@ const char * selinux_file_context_subs_dist_path(void) {
80c334b
 
80c334b
 hidden_def(selinux_file_context_subs_dist_path)
80c334b
 
80c334b
-const char *selinux_sepgsql_context_path()
80c334b
+const char *selinux_sepgsql_context_path(void)
80c334b
 {
80c334b
 	return get_path(SEPGSQL_CONTEXTS);
80c334b
 }
5cb2893
diff --git a/libselinux/src/selinux_internal.h b/libselinux/src/selinux_internal.h
5cb2893
index 710396a..9a3fc14 100644
5cb2893
--- a/libselinux/src/selinux_internal.h
5cb2893
+++ b/libselinux/src/selinux_internal.h
5cb2893
@@ -80,6 +80,7 @@ hidden_proto(selinux_mkload_policy)
5cb2893
     hidden_proto(selinux_path)
5cb2893
     hidden_proto(selinux_check_passwd_access)
5cb2893
     hidden_proto(selinux_check_securetty_context)
5cb2893
+    hidden_proto(matchpathcon_init_prefixes)
5cb2893
     hidden_proto(matchpathcon_init_prefix)
5cb2893
     hidden_proto(selinux_users_path)
5cb2893
     hidden_proto(selinux_usersconf_path);
80c334b
diff --git a/libselinux/src/setrans_client.c b/libselinux/src/setrans_client.c
80c334b
index e074142..9432f49 100644
80c334b
--- a/libselinux/src/setrans_client.c
80c334b
+++ b/libselinux/src/setrans_client.c
80c334b
@@ -253,6 +253,8 @@ static void setrans_thread_destructor(void __attribute__((unused)) *unused)
80c334b
 	free(prev_r2c_raw);
80c334b
 }
80c334b
 
80c334b
+void __attribute__((destructor)) setrans_lib_destructor(void);
80c334b
+
80c334b
 void __attribute__((destructor)) setrans_lib_destructor(void)
80c334b
 {
80c334b
 	if (destructor_key_initialized)
80c334b
diff --git a/libselinux/src/seusers.c b/libselinux/src/seusers.c
80c334b
index b653cad..5cdf6c0 100644
80c334b
--- a/libselinux/src/seusers.c
80c334b
+++ b/libselinux/src/seusers.c
80c334b
@@ -269,9 +269,10 @@ int getseuser(const char *username, const char *service,
80c334b
 	size_t lineno = 0;
80c334b
 	char *rec = NULL;
80c334b
 	char *path=NULL;
80c334b
+	FILE *fp = NULL;
80c334b
 	if (asprintf(&path,"%s/logins/%s", selinux_policy_root(), username) <  0)
80c334b
 		goto err;
80c334b
-	FILE *fp = fopen(path, "r");
80c334b
+	fp = fopen(path, "r");
80c334b
 	free(path);
80c334b
 	if (fp == NULL) goto err;
80c334b
 	__fsetlocking(fp, FSETLOCKING_BYCALLER);
80c334b
diff --git a/libselinux/src/stringrep.c b/libselinux/src/stringrep.c
80c334b
index f0167e7..176ac34 100644
80c334b
--- a/libselinux/src/stringrep.c
80c334b
+++ b/libselinux/src/stringrep.c
80c334b
@@ -305,28 +305,6 @@ err1:
80c334b
 	return NULL;
80c334b
 }
80c334b
 
80c334b
-void flush_class_cache(void)
80c334b
-{
80c334b
-	struct discover_class_node *cur = discover_class_cache, *prev = NULL;
80c334b
-	size_t i;
80c334b
-
80c334b
-	while (cur != NULL) {
80c334b
-		free(cur->name);
80c334b
-
80c334b
-		for (i=0 ; i
80c334b
-			free(cur->perms[i]);
80c334b
-
80c334b
-		free(cur->perms);
80c334b
-
80c334b
-		prev = cur;
80c334b
-		cur = cur->next;
80c334b
-
80c334b
-		free(prev);
80c334b
-	}
80c334b
-
80c334b
-	discover_class_cache = NULL;
80c334b
-}
80c334b
-
80c334b
 static security_class_t string_to_security_class_compat(const char *s)
80c334b
 {
80c334b
 	unsigned int val;
80c334b
diff --git a/libselinux/utils/Makefile b/libselinux/utils/Makefile
80c334b
index 6f5aa52..4b2f348 100644
80c334b
--- a/libselinux/utils/Makefile
80c334b
+++ b/libselinux/utils/Makefile
80c334b
@@ -4,7 +4,25 @@ LIBDIR ?= $(PREFIX)/lib
80c334b
 BINDIR ?= $(PREFIX)/sbin
80c334b
 _BINDIR ?= $(DESTDIR)/sbin
80c334b
 
80c334b
-CFLAGS ?= -Werror -Wall -W
80c334b
+MAX_STACK_SIZE=8192
80c334b
+CFLAGS ?= -Wall -W -Wundef -Wformat-y2k -Wformat-security -Winit-self -Wmissing-include-dirs \
80c334b
+          -Wunused -Wunknown-pragmas -Wstrict-aliasing -Wshadow -Wpointer-arith \
80c334b
+          -Wbad-function-cast -Wcast-align -Wwrite-strings -Wlogical-op -Waggregate-return \
80c334b
+          -Wstrict-prototypes -Wold-style-definition -Wmissing-prototypes \
80c334b
+          -Wmissing-declarations -Wmissing-noreturn -Wmissing-format-attribute \
80c334b
+          -Wredundant-decls -Wnested-externs -Winline -Winvalid-pch -Wvolatile-register-var \
80c334b
+          -Wdisabled-optimization -Wbuiltin-macro-redefined -Wmudflap -Wpacked-bitfield-compat \
80c334b
+          -Wsync-nand -Wattributes -Wcoverage-mismatch -Wmultichar -Wcpp \
80c334b
+          -Wdeprecated-declarations -Wdiv-by-zero -Wdouble-promotion -Wendif-labels -Wextra \
80c334b
+          -Wformat-contains-nul -Wformat-extra-args -Wformat-zero-length -Wformat=2 -Wmultichar \
80c334b
+          -Wnormalized=nfc -Woverflow -Wpointer-to-int-cast -Wpragmas -Wsuggest-attribute=const \
80c334b
+          -Wsuggest-attribute=noreturn -Wsuggest-attribute=pure -Wtrampolines \
80c334b
+          -Wno-missing-field-initializers -Wno-sign-compare -Wjump-misses-init \
80c334b
+          -Wno-format-nonliteral -Wframe-larger-than=$(MAX_STACK_SIZE) -Wp,-D_FORTIFY_SOURCE=2 \
80c334b
+          -fstack-protector-all --param=ssp-buffer-size=4 -fexceptions \
80c334b
+          -fasynchronous-unwind-tables -fdiagnostics-show-option -funit-at-a-time \
80c334b
+          -fipa-pure-const -Wno-suggest-attribute=pure -Wno-suggest-attribute=const \
80c334b
+          -Werror -Wno-aggregate-return -Wno-redundant-decls
80c334b
 override CFLAGS += -I../include -D_GNU_SOURCE $(EMFLAGS)
80c334b
 LDLIBS += -L../src -lselinux -L$(LIBDIR)
80c334b
 
80c334b
diff --git a/libselinux/utils/avcstat.c b/libselinux/utils/avcstat.c
80c334b
index 772118a..7239ef2 100644
80c334b
--- a/libselinux/utils/avcstat.c
80c334b
+++ b/libselinux/utils/avcstat.c
80c334b
@@ -43,7 +43,7 @@ static char buf[DEF_BUF_SIZE];
80c334b
 /* selinuxfs mount point */
80c334b
 extern char *selinux_mnt;
80c334b
 
80c334b
-static void die(const char *msg, ...)
80c334b
+static __attribute__((__format__(printf,1,2))) void die(const char *msg, ...)
80c334b
 {
80c334b
 	va_list args;
80c334b
 
80c334b
@@ -118,7 +118,7 @@ int main(int argc, char **argv)
80c334b
 			exit(0);
80c334b
 		default:
80c334b
 			usage();
80c334b
-			die("unrecognized parameter", i);
80c334b
+			die("unrecognized parameter '%c'", i);
80c334b
 		}
80c334b
 	}
80c334b
 
80c334b
diff --git a/libselinux/utils/getconlist.c b/libselinux/utils/getconlist.c
80c334b
index 4f473e4..94c9bff 100644
80c334b
--- a/libselinux/utils/getconlist.c
80c334b
+++ b/libselinux/utils/getconlist.c
80c334b
@@ -9,7 +9,7 @@
80c334b
 #include <selinux/selinux.h>
80c334b
 #include <selinux/get_context_list.h>
80c334b
 
80c334b
-void usage(char *name, char *detail, int rc)
80c334b
+static void usage(const char *name, const char *detail, int rc)
80c334b
 {
80c334b
 	fprintf(stderr, "usage:  %s [-l level] user [context]\n", name);
80c334b
 	if (detail)
80c334b
diff --git a/libselinux/utils/getdefaultcon.c b/libselinux/utils/getdefaultcon.c
80c334b
index e6eb98b..049e75c 100644
80c334b
--- a/libselinux/utils/getdefaultcon.c
80c334b
+++ b/libselinux/utils/getdefaultcon.c
80c334b
@@ -9,7 +9,7 @@
80c334b
 #include <selinux/selinux.h>
80c334b
 #include <selinux/get_context_list.h>
80c334b
 
80c334b
-void usage(char *name, char *detail, int rc)
80c334b
+static void usage(const char *name, const char *detail, int rc)
80c334b
 {
80c334b
 	fprintf(stderr, "usage:  %s [-l level] user fromcon\n", name);
80c334b
 	if (detail)
80c334b
diff --git a/libselinux/utils/getsebool.c b/libselinux/utils/getsebool.c
80c334b
index cab2bb9..3a90449 100644
80c334b
--- a/libselinux/utils/getsebool.c
80c334b
+++ b/libselinux/utils/getsebool.c
80c334b
@@ -6,7 +6,7 @@
80c334b
 #include <string.h>
80c334b
 #include <selinux/selinux.h>
80c334b
 
80c334b
-void usage(const char *progname)
80c334b
+static void usage(const char *progname)
80c334b
 {
80c334b
 	fprintf(stderr, "usage:  %s -a or %s boolean...\n", progname, progname);
80c334b
 	exit(1);
80c334b
diff --git a/libselinux/utils/matchpathcon.c b/libselinux/utils/matchpathcon.c
80c334b
index 5f0a4c2..b1adadd 100644
80c334b
--- a/libselinux/utils/matchpathcon.c
80c334b
+++ b/libselinux/utils/matchpathcon.c
80c334b
@@ -13,7 +13,7 @@
80c334b
 #include <stdlib.h>
80c334b
 
80c334b
 
80c334b
-void usage(const char *progname)
80c334b
+static void usage(const char *progname)
80c334b
 {
80c334b
 	fprintf(stderr,
80c334b
 		"usage:  %s [-N] [-n] [-f file_contexts] [-p prefix] [-Vq] path...\n",
80c334b
@@ -21,7 +21,7 @@ void usage(const char *progname)
80c334b
 	exit(1);
80c334b
 }
80c334b
 
80c334b
-int printmatchpathcon(char *path, int header, int mode)
80c334b
+static int printmatchpathcon(const char *path, int header, int mode)
80c334b
 {
80c334b
 	char *buf;
80c334b
 	int rc = matchpathcon(path, mode, &buf;;
80c334b
diff --git a/libselinux/utils/selinux_check_securetty_context.c b/libselinux/utils/selinux_check_securetty_context.c
80c334b
index 95bfb7f..b158eb3 100644
80c334b
--- a/libselinux/utils/selinux_check_securetty_context.c
80c334b
+++ b/libselinux/utils/selinux_check_securetty_context.c
80c334b
@@ -9,7 +9,7 @@
80c334b
 #include <sys/errno.h>
80c334b
 #include <selinux/selinux.h>
80c334b
 
80c334b
-void usage(const char *progname)
80c334b
+static void usage(const char *progname)
80c334b
 {
80c334b
 	fprintf(stderr, "usage:  %s tty_context...\n", progname);
80c334b
 	exit(1);
80c334b
diff --git a/libselinux/utils/selinuxexeccon.c b/libselinux/utils/selinuxexeccon.c
80c334b
index c55fde9..476f564 100644
80c334b
--- a/libselinux/utils/selinuxexeccon.c
80c334b
+++ b/libselinux/utils/selinuxexeccon.c
80c334b
@@ -9,7 +9,7 @@
80c334b
 #include <selinux/flask.h>
80c334b
 #include <selinux/selinux.h>
80c334b
 
80c334b
-void usage(char *name, char *detail, int rc)
80c334b
+static void usage(const char *name, const char *detail, int rc)
80c334b
 {
80c334b
 	fprintf(stderr, "usage:  %s command [ fromcon ]\n", name);
80c334b
 	if (detail)
80c334b
diff --git a/libselinux/utils/setenforce.c b/libselinux/utils/setenforce.c
80c334b
index e45b804..df58597 100644
80c334b
--- a/libselinux/utils/setenforce.c
80c334b
+++ b/libselinux/utils/setenforce.c
80c334b
@@ -6,7 +6,7 @@
80c334b
 #include <strings.h>
80c334b
 #include <selinux/selinux.h>
80c334b
 
80c334b
-void usage(const char *progname)
80c334b
+static void usage(const char *progname)
80c334b
 {
80c334b
 	fprintf(stderr, "usage:  %s [ Enforcing | Permissive | 1 | 0 ]\n",
80c334b
 		progname);
80c334b
diff --git a/libselinux/utils/togglesebool.c b/libselinux/utils/togglesebool.c
80c334b
index 680ed8d..ad0d2a2 100644
80c334b
--- a/libselinux/utils/togglesebool.c
80c334b
+++ b/libselinux/utils/togglesebool.c
80c334b
@@ -10,7 +10,7 @@
80c334b
 
80c334b
 /* Attempt to rollback the transaction. No need to check error
80c334b
    codes since this is rolling back something that blew up. */
80c334b
-void rollback(int argc, char **argv)
80c334b
+static void rollback(int argc, char **argv)
80c334b
 {
80c334b
 	int i;
80c334b