libselinux: drop obsolete optimization flag
PATCH 1/3 libselinux: drop obsolete optimization flag
The optimization flag -funit-at-a-time is enabled by default in GCC[1] and not supported by Clang:
clang: error: optimization flag '-funit-at-a-time' is not supported [-Werror,-Wignored-optimization-argument]
[1]: https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html
--- libselinux/src/Makefile | 2 +- libselinux/utils/Makefile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
libselinux/src/Makefile +1 -1
@@ -86,7 +86,7 @@ CFLAGS ?= -O -Wall -W -Wundef -Wformat-y2k -Wformat-security -Winit-self -Wmissi -Wno-missing-field-initializers -Wno-sign-compare \ -Wno-format-nonliteral -Wframe-larger-than=$(MAX_STACK_SIZE) \ -fstack-protector-all --param=ssp-buffer-size=4 -fexceptions \ - -fasynchronous-unwind-tables -fdiagnostics-show-option -funit-at-a-time \ + -fasynchronous-unwind-tables -fdiagnostics-show-option \ -Werror -Wno-aggregate-return -Wno-redundant-decls \ $(EXTRA_CFLAGS)
libselinux/utils/Makefile +1 -1
@@ -32,7 +32,7 @@ CFLAGS ?= -O -Wall -W -Wundef -Wformat-y2k -Wformat-security -Winit-self -Wmissi -Wno-missing-field-initializers -Wno-sign-compare \ -Wno-format-nonliteral -Wframe-larger-than=$(MAX_STACK_SIZE) -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 \ -fstack-protector-all --param=ssp-buffer-size=4 -fexceptions \ - -fasynchronous-unwind-tables -fdiagnostics-show-option -funit-at-a-time \ + -fasynchronous-unwind-tables -fdiagnostics-show-option \ -Werror -Wno-aggregate-return -Wno-redundant-decls -Wstrict-overflow=5 \ $(EXTRA_CFLAGS)
Signature · 1 line
2.39.1
PATCH 2/3 libselinux: restore: misc tweaks
Add const qualifier to read-only state struct.
Minimize scope of function local variables, to reduce complexity.
Pass only the file type related file flags to selabel_lookup(3).
--- libselinux/src/selinux_restorecon.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
libselinux/src/selinux_restorecon.c +7 -7
@@ -432,7 +432,7 @@ static pthread_mutex_t fl_mutex = PTHREAD_MUTEX_INITIALIZER;* that matched. */ static int filespec_add (ino_t ino,const char *con,const char *file, -struct rest_flags *flags) +const struct rest_flags *flags) {file_spec_t *prevfl, *fl;int h, ret;
@@ -624,15 +624,13 @@ out: }static int restorecon_sb (const char *pathname,const struct stat *sb, -struct rest_flags *flags,bool first) +const struct rest_flags *flags,bool first) {char *newcon =NULL ;char *curcon =NULL ;char *newtypecon =NULL ;int rc; -bool updated = false;const char *lookup_path = pathname; -float pc;if (rootpath) {if (strncmp (rootpath, lookup_path, rootpathlen) !=0 ) {
@@ -647,10 +645,10 @@ static int restorecon_sb(const char *pathname, const struct stat *sb,if (rootpath !=NULL && lookup_path[0 ] =='\0' )/* this is actually the root dir of the alt root. */ rc =selabel_lookup_raw (fc_sehandle, &newcon,"/" , - sb->st_mode); + sb->st_mode &S_IFMT );else rc =selabel_lookup_raw (fc_sehandle, &newcon, lookup_path, - sb->st_mode); + sb->st_mode &S_IFMT );if (rc <0 ) {if (errno ==ENOENT ) {
@@ -670,7 +668,7 @@ static int restorecon_sb(const char *pathname, const struct stat *sb, fc_count++;if (fc_count %STAR_COUNT ==0 ) {if (flags->mass_relabel && efile_count >0 ) { - pc = (fc_count < efile_count) ? (100.0 * +float pc = (fc_count < efile_count) ? (100.0 * fc_count / efile_count) :100 ;fprintf (stdout,"\r%-.1f%%" , (double )pc); }else {
@@ -710,6 +708,8 @@ static int restorecon_sb(const char *pathname, const struct stat *sb, }if (curcon ==NULL ||strcmp (curcon, newcon) !=0 ) { +bool updated = false; +if (!flags->set_specctx && curcon && (is_context_customizable (curcon) >0 )) {if (flags->verbose) {
Signature · 1 line
2.39.1
PATCH 3/3 libselinux: restore: use fixed sized integer for hash index
In reply to Christian GöttscheThe hash mask is set to 2^16 - 1, which does not fit into a signed 16 bit integer. Use uint32_t to be on the safe side. Also use size_t for counting in debug function.
--- libselinux/src/selinux_restorecon.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
libselinux/src/selinux_restorecon.c +6 -4
@@ -435,7 +435,8 @@ static int filespec_add(ino_t ino, const char *con, const char *file, const struct rest_flags *flags) {file_spec_t *prevfl, *fl; -int h, ret; +uint32_t h; +int ret;struct stat64 sb;__pthread_mutex_lock (&fl_mutex);
@@ -524,7 +525,8 @@ unlock_1:static void filespec_eval (void ) {file_spec_t *fl; -int h, used, nel, len, longest; +uint32_t h; +size_t used, nel, len, longest;if (!fl_head)return ;
@@ -544,7 +546,7 @@ static void filespec_eval(void) }selinux_log (SELINUX_INFO , -"filespec hash table stats: %d elements, %d/%d buckets used, longest chain length %d\n" , +"filespec hash table stats: %zu elements, %zu/%zu buckets used, longest chain length %zu\n" , nel, used,HASH_BUCKETS , longest); }#else
@@ -559,7 +561,7 @@ static void filespec_eval(void)static void filespec_destroy (void ) {file_spec_t *fl, *tmp; -int h; +uint32_t h;if (!fl_head)return ;
Signature · 1 line
2.39.1
Quoted 8 lines · Christian Göttsche
The optimization flag -funit-at-a-time is enabled by default in GCC[1] and not supported by Clang:
clang: error: optimization flag '-funit-at-a-time' is not supported [-Werror,-Wignored-optimization-argument]
[1]: https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html
Signed-off-by Christian Göttsche <[email protected]>
This whole series:
And merged, thanks!
Quoted 34 lines
--- libselinux/src/Makefile | 2 +- libselinux/utils/Makefile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)libselinux/src/Makefile +1
-1@@ -86,7 +86,7 @@ CFLAGS ?= -O -Wall -W -Wundef -Wformat-y2k -Wformat-security -Winit-self -Wmissi -Wno-missing-field-initializers -Wno-sign-compare \ -Wno-format-nonliteral -Wframe-larger-than=$(MAX_STACK_SIZE) \ -fstack-protector-all --param=ssp-buffer-size=4 -fexceptions \ - -fasynchronous-unwind-tables -fdiagnostics-show-option -funit-at-a-time \ + -fasynchronous-unwind-tables -fdiagnostics-show-option \ -Werror -Wno-aggregate-return -Wno-redundant-decls \ $(EXTRA_CFLAGS)libselinux/utils/Makefile +1
-1@@ -32,7 +32,7 @@ CFLAGS ?= -O -Wall -W -Wundef -Wformat-y2k -Wformat-security -Winit-self -Wmissi -Wno-missing-field-initializers -Wno-sign-compare \ -Wno-format-nonliteral -Wframe-larger-than=$(MAX_STACK_SIZE) -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 \ -fstack-protector-all --param=ssp-buffer-size=4 -fexceptions \ - -fasynchronous-unwind-tables -fdiagnostics-show-option -funit-at-a-time \ + -fasynchronous-unwind-tables -fdiagnostics-show-option \ -Werror -Wno-aggregate-return -Wno-redundant-decls -Wstrict-overflow=5 \ $(EXTRA_CFLAGS)Signature · 1 line
2.39.1