Repair two build failures on older host
cover Repair two build failures on older host
I was building from source today on one of my older (Ubuntu 12.04.3) installations and ran into a couple of minor issues. The former wouldn't show up on any host with a reasonable modern libpcre, but I don't know how the combination of flags (-Werror -Wshadow) builds elsewhere. I suspect I'm missing something.
Signature · 7 lines
-Joe. -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
PATCH 1/2 libselinux: support building on older PCRE libs
Versions of PCRE prior to 8.20 did not have pcre_free_study(). In its absence, use pcre_free() instead.
--- libselinux/src/label_file.c | 4 ++++ libselinux/utils/sefcontext_compile.c | 4 ++++ 2 files changed, 8 insertions(+)
libselinux/src/label_file.c +4 -0
@@ -561,7 +561,11 @@ static void closef(struct selabel_handle *rec)free (spec->type_str);if (spec->regcomp) {pcre_free (spec->regex); +#if (PCRE_MAJOR >=8 &&PCRE_MINOR >=20 )pcre_free_study (spec->sd); +#else +pcre_free (spec->sd); +#endif } }
libselinux/utils/sefcontext_compile.c +4 -0
@@ -301,7 +301,11 @@ static int free_specs(struct saved_data *data)free (specs[i].lr.ctx_trans);free (specs[i].regex_str);pcre_free (specs[i].regex); +#if (PCRE_MAJOR >=8 &&PCRE_MINOR >=20 )pcre_free_study (specs[i].sd); +#else +pcre_free (specs[i].sd); +#endif }free (specs);
Signature · 7 lines
1.7.9.5 -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
PATCH 2/2 libselinux: avoid shadowing 'stat' in load_mmap
label_file.c: In function ‘load_mmap’:
label_file.c:238:81: error: declaration of ‘stat’ shadows a global declaration [-Werror=shadow]
cc1: all warnings being treated as errors
--- libselinux/src/label_file.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
libselinux/src/label_file.c +4 -4
@@ -235,7 +235,7 @@ static int process_line(struct selabel_handle *rec,return 0 ; } -static int load_mmap (struct selabel_handle *rec,const char *path,struct stat *stat) +static int load_mmap (struct selabel_handle *rec,const char *path,struct stat *sb) {struct saved_data *data = (struct saved_data *)rec->data;char mmap_path[PATH_MAX +1 ];
@@ -266,13 +266,13 @@ static int load_mmap(struct selabel_handle *rec, const char *path, struct stat * }/* if mmap is old, ignore it */ -if (mmap_stat.st_mtime < stat->st_mtime) { +if (mmap_stat.st_mtime < sb->st_mtime) {close (mmapfd);return -1 ; } -if (mmap_stat.st_mtime == stat->st_mtime && - mmap_stat.st_mtim.tv_nsec < stat->st_mtim.tv_nsec) { +if (mmap_stat.st_mtime == sb->st_mtime && + mmap_stat.st_mtim.tv_nsec < sb->st_mtim.tv_nsec) {close (mmapfd);return -1 ; }
Signature · 7 lines
1.7.9.5 -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Re: [PATCH 2/2] libselinux: avoid shadowing 'stat' in load_mmap
Quoted 3 lines · Joe MacDonald
label_file.c: In function ‘load_mmap’:
label_file.c:238:81: error: declaration of ‘stat’ shadows a global declaration [-Werror=shadow]
cc1: all warnings being treated as errors
I don't particularly mind the change, but I neither see this warning nor see the underlying issue in the source code - where is the global stat declaration? Is it in some system header file you have on your system?
Quoted 27 lines
Signed-off-by Joe MacDonald <[email protected]>--- libselinux/src/label_file.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)libselinux/src/label_file.c +2
-2@@ -235,7 +235,7 @@ static int process_line(struct selabel_handle *rec,return 0 ; } -static int load_mmap (struct selabel_handle *rec,const char *path,struct stat *stat) +static int load_mmap (struct selabel_handle *rec,const char *path,struct stat *sb) {struct saved_data *data = (struct saved_data *)rec->data;char mmap_path[PATH_MAX +1 ];@@ -266,13 +266,13 @@ static int load_mmap(struct selabel_handle *rec, const char *path, struct stat * }/* if mmap is old, ignore it */ -if (mmap_stat.st_mtime < stat->st_mtime) { +if (mmap_stat.st_mtime < sb->st_mtime) {close (mmapfd);
libselinux/src/label_file.c static int load_mmap(struct selabel_handle *rec, const char *path, struct stat * · line 278
Quoted 10 lines
libselinux/src/label_file.c +2
-2return -1 ; } -if (mmap_stat.st_mtime == stat->st_mtime && - mmap_stat.st_mtim.tv_nsec < stat->st_mtim.tv_nsec) { +if (mmap_stat.st_mtime == sb->st_mtime && + mmap_stat.st_mtim.tv_nsec < sb->st_mtim.tv_nsec) {close (mmapfd);return -1 ; }
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Re: [PATCH 2/2] libselinux: avoid shadowing 'stat' in load_mmap
Hi Stephen,
Quoted 8 lines · [Re: [PATCH 2/2] libselinux: avoid shadowing 'stat' in load_mmap] On 13.10.21…
Quoted 3 lines · Joe MacDonald
label_file.c: In function ‘load_mmap’:
label_file.c:238:81: error: declaration of ‘stat’ shadows a global declaration [-Werror=shadow]
cc1: all warnings being treated as errorsI don't particularly mind the change, but I neither see this warning nor see the underlying issue in the source code - where is the global stat declaration? Is it in some system header file you have on your system?
I'm honestly not sure:
~/external/selinux cscope -L -1 stat/usr/include/glob.h stat 82 struct stat;/usr/include/sys/stat.h stat 211 extern int stat (__const char *__restrict __file, /usr/include/sys/stat.h stat 225 #define stat stat64/usr/include/sys/stat.h stat 455 __NTH (stat (__const char *__path, struct stat *__statbuf)) /usr/include/bits/stat.h stat 46 struct stat
glob.h is probably implicated, but this test case:
------------------------------------------------------------------------
#include <glob.h>
#include <sys/stat.h>
void testfunc(struct stat *stat)
{
;
}int main (int argc, char *argv)
{
struct stat sb;
testfunc(&sb); }
------------------------------------------------------------------------
Compiled with 'gcc -Wshadow foo.c -o foo' builds without warning on my more recent setup (Debian GNU/Linux 7.2 (wheezy)) but produces the warning on the older one:
------------------------------------------------------------------------
/tmp gcc -Wshadow foo.c -o foofoo.c: In function ‘testfunc’:
foo.c:4:28: warning: declaration of ‘stat’ shadows a global declaration [-Wshadow] /tmp lsb_release -d
Description: Ubuntu 12.04.3 LTS
------------------------------------------------------------------------
Removing #include <glob.h> doesn't help, though, which I wouldn't really expect anyway since label_file.c doesn't include it directly anyway. Maybe it's a gcc version thing? The failing machine is "gcc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3" whereas the happy one is "gcc (Debian 4.7.2-5) 4.7.2".
Anyway, as I said in 0/2, I'm confident I'm missing something, I shouldn't be the first one to trip over this, but I don't know what the missing piece is, exactly.
-J.
Quoted 39 lines
Quoted 38 lines
Signed-off-by Joe MacDonald <[email protected]>--- libselinux/src/label_file.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)libselinux/src/label_file.c +4
-4@@ -235,7 +235,7 @@ static int process_line(struct selabel_handle *rec,return 0 ; } -static int load_mmap (struct selabel_handle *rec,const char *path,struct stat *stat) +static int load_mmap (struct selabel_handle *rec,const char *path,struct stat *sb) {struct saved_data *data = (struct saved_data *)rec->data;char mmap_path[PATH_MAX +1 ];@@ -266,13 +266,13 @@ static int load_mmap(struct selabel_handle *rec, const char *path, struct stat * }/* if mmap is old, ignore it */ -if (mmap_stat.st_mtime < stat->st_mtime) { +if (mmap_stat.st_mtime < sb->st_mtime) {close (mmapfd);return -1 ; } -if (mmap_stat.st_mtime == stat->st_mtime && - mmap_stat.st_mtim.tv_nsec < stat->st_mtim.tv_nsec) { +if (mmap_stat.st_mtime == sb->st_mtime && + mmap_stat.st_mtim.tv_nsec < sb->st_mtim.tv_nsec) {close (mmapfd);return -1 ; }
Signature · 2 lines
-Joe MacDonald. :wq
Re: [PATCH 1/2] libselinux: support building on older PCRE libs
In reply to Joe MacDonaldQuoted 14 lines · Joe MacDonald
Versions of PCRE prior to 8.20 did not have
pcre_free_study(). In its absence, usepcre_free()instead.Signed-off-by Joe MacDonald <[email protected]>--- libselinux/src/label_file.c | 4 ++++ libselinux/utils/sefcontext_compile.c | 4 ++++ 2 files changed, 8 insertions(+)libselinux/src/label_file.c +0
-0
libselinux/src/label_file.c static void closef(struct selabel_handle *rec) · line 567
Quoted 7 lines
libselinux/src/label_file.c +3
-0@@ -561,7 +561,11 @@ static void closef(struct selabel_handle *rec)free (spec->type_str);if (spec->regcomp) {pcre_free (spec->regex); +#if (PCRE_MAJOR >=8 &&PCRE_MINOR >=20 )pcre_free_study (spec->sd); +#else +pcre_free (spec->sd);
We try to avoid #if / #ifdef scattered throughout the code. The preferred approach is to conditionally define pcre_free_study() to pcre_free() if building with the older libpcre.
Quoted 11 lines
libselinux/src/label_file.c +1
-0+#endif } }libselinux/utils/sefcontext_compile.c +0
-0@@ -301,7 +301,11 @@ static int free_specs(struct saved_data *data)free (specs[i].lr.ctx_trans);
libselinux/utils/sefcontext_compile.c static int free_specs(struct saved_data *data) · line 311
Quoted 10 lines
libselinux/utils/sefcontext_compile.c +4
-0free (specs[i].regex_str);pcre_free (specs[i].regex); +#if (PCRE_MAJOR >=8 &&PCRE_MINOR >=20 )pcre_free_study (specs[i].sd); +#else +pcre_free (specs[i].sd); +#endif }free (specs);
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Re: [PATCH 1/2] libselinux: support building on older PCRE libs
Quoted 10 lines · [Re: [PATCH 1/2] libselinux: support building on older PCRE libs] On 13.10.21…
Quoted 9 lines · Joe MacDonald
Versions of PCRE prior to 8.20 did not have
pcre_free_study(). In its absence, usepcre_free()instead.Signed-off-by Joe MacDonald <[email protected]>--- libselinux/src/label_file.c | 4 ++++ libselinux/utils/sefcontext_compile.c | 4 ++++ 2 files changed, 8 insertions(+)
Quoted 16 lines
libselinux/src/label_file.c static void closef(struct selabel_handle *rec) · line 567
Quoted 12 lines
libselinux/src/label_file.c +3
-0@@ -561,7 +561,11 @@ static void closef(struct selabel_handle *rec)free (spec->type_str);if (spec->regcomp) {pcre_free (spec->regex); +#if (PCRE_MAJOR >=8 &&PCRE_MINOR >=20 )pcre_free_study (spec->sd); +#else +pcre_free (spec->sd);We try to avoid #if / #ifdef scattered throughout the code. The preferred approach is to conditionally define
pcre_free_study()topcre_free()if building with the older libpcre.
Sure thing. I'll resubmit. Given that this is present in only two files with the only obvious common #include (within the selinux repo itself) being label_file.h, I'll put the #define there. Does that seem reasonable?
-J.
Quoted 24 lines
Quoted 23 lines
libselinux/src/label_file.c +1
-0+#endif } }libselinux/utils/sefcontext_compile.c +4
-0@@ -301,7 +301,11 @@ static int free_specs(struct saved_data *data)free (specs[i].lr.ctx_trans);free (specs[i].regex_str);pcre_free (specs[i].regex); +#if (PCRE_MAJOR >=8 &&PCRE_MINOR >=20 )pcre_free_study (specs[i].sd); +#else +pcre_free (specs[i].sd); +#endif }free (specs);
Signature · 2 lines
-Joe MacDonald. :wq
Re: [PATCH 1/2] libselinux: support building on older PCRE libs
Quoted 29 lines · Joe MacDonald
Quoted 10 lines · [Re: [PATCH 1/2] libselinux: support building on older PCRE libs] On 13.10.21…
Quoted 9 lines · Joe MacDonald
Versions of PCRE prior to 8.20 did not have
pcre_free_study(). In its absence, usepcre_free()instead.Signed-off-by Joe MacDonald <[email protected]>--- libselinux/src/label_file.c | 4 ++++ libselinux/utils/sefcontext_compile.c | 4 ++++ 2 files changed, 8 insertions(+)Quoted 16 lines
libselinux/src/label_file.c static void closef(struct selabel_handle *rec) · line 567
Quoted 12 lines
libselinux/src/label_file.c +3
-0@@ -561,7 +561,11 @@ static void closef(struct selabel_handle *rec)free (spec->type_str);if (spec->regcomp) {pcre_free (spec->regex); +#if (PCRE_MAJOR >=8 &&PCRE_MINOR >=20 )pcre_free_study (spec->sd); +#else +pcre_free (spec->sd);We try to avoid #if / #ifdef scattered throughout the code. The preferred approach is to conditionally define
pcre_free_study()topcre_free()if building with the older libpcre.
Quoted 4 lines
Sure thing. I'll resubmit. Given that this is present in only two files with the only obvious common #include (within the selinux repo itself) being
label_file.h, I'll put the #define there. Does that seem reasonable?
Yes, that looks right to me.
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.