Makefile: fix cleaning files that starts with "-"
PATCH 1/3 Makefile: fix cleaning files that starts with "-"
libselinux/src/exception.sh creates a file named "-.o". This file is usually removed at the end of this script, but some failures in it could left it on the filesystem. "make clean" is then supposed to remove this file, but fails instead with:
rm: invalid option -- '.'
Try 'rm ./-.o' to remove the file '-.o'.
Try 'rm --help' for more information.
This is due to "rm -f *.o" being expanded to "rm -f -.o". Prevent this buggy expansion by using "./*.o" in the command line. While at it, do so for other patterns like "*~".
--- checkpolicy/test/Makefile | 2 +- libselinux/src/Makefile | 4 ++-- libselinux/utils/Makefile | 2 +- libsemanage/src/Makefile | 2 +- libsepol/utils/Makefile | 2 +- mcstrans/Makefile | 2 +- mcstrans/man/Makefile | 2 +- mcstrans/src/Makefile | 2 +- mcstrans/utils/Makefile | 2 +- policycoreutils/load_policy/Makefile | 2 +- policycoreutils/newrole/Makefile | 2 +- policycoreutils/po/Makefile | 2 +- policycoreutils/run_init/Makefile | 2 +- policycoreutils/secon/Makefile | 2 +- policycoreutils/semodule/Makefile | 2 +- policycoreutils/sestatus/Makefile | 2 +- policycoreutils/setfiles/Makefile | 2 +- policycoreutils/setsebool/Makefile | 2 +- python/audit2allow/Makefile | 2 +- python/sepolgen/Makefile | 2 +- python/sepolgen/src/Makefile | 2 +- python/sepolgen/src/sepolgen/Makefile | 2 +- python/sepolgen/src/share/Makefile | 2 +- python/sepolgen/tests/Makefile | 2 +- python/sepolicy/Makefile | 2 +- restorecond/Makefile | 2 +- sandbox/Makefile | 2 +- semodule-utils/semodule_expand/Makefile | 2 +- semodule-utils/semodule_link/Makefile | 2 +- semodule-utils/semodule_package/Makefile | 2 +- 30 files changed, 31 insertions(+), 31 deletions(-)
checkpolicy/test/Makefile +1 -1
@@ -19,4 +19,4 @@ dismod: dismod.o $(LIBSEPOLA) $(CC) $(LDFLAGS) -o $@ $^ $(LDLIBS_LIBSEPOLA) clean: - -rm -f dispol dismod *.o + -rm -f dispol dismod ./*.o
libselinux/src/Makefile +2 -2
@@ -187,13 +187,13 @@ relabel: clean-pywrap: -rm -f $(SWIGLOBJ) $(SWIGSO) $(AUDIT2WHYLOBJ) $(AUDIT2WHYSO) $(PYTHON) setup.py clean - -rm -rf build *~ \#* *pyc .#* + -rm -rf build ./*~ \#* ./*pyc .#* clean-rubywrap: -rm -f $(SWIGRUBYLOBJ) $(SWIGRUBYSO) clean: clean-pywrap clean-rubywrap - -rm -f $(LIBPC) $(OBJS) $(LOBJS) $(LIBA) $(LIBSO) $(TARGET) *.o *.lo *~ + -rm -f $(LIBPC) $(OBJS) $(LOBJS) $(LIBA) $(LIBSO) $(TARGET) ./*.o ./*.lo ./*~ distclean: clean rm -f $(GENERATED) $(SWIGFILES)
libselinux/utils/Makefile +1 -1
@@ -65,7 +65,7 @@ install: all install -m 755 $(TARGETS) $(DESTDIR)$(SBINDIR) clean: - rm -f $(TARGETS) *.o *~ + rm -f $(TARGETS) ./*.o ./*~ distclean: clean
libsemanage/src/Makefile +1 -1
@@ -155,7 +155,7 @@ relabel: /sbin/restorecon $(DESTDIR)$(LIBDIR)/$(LIBSO) clean: - -rm -f $(LIBPC) $(OBJS) $(LOBJS) $(LIBA) $(LIBSO) $(SWIGLOBJ) $(SWIGSO) $(SWIGRUBYSO) $(TARGET) conf-parse.c conf-parse.h conf-scan.c *.o *.lo *~ + -rm -f $(LIBPC) $(OBJS) $(LOBJS) $(LIBA) $(LIBSO) $(SWIGLOBJ) $(SWIGSO) $(SWIGRUBYSO) $(TARGET) conf-parse.c conf-parse.h conf-scan.c ./*.o ./*.lo ./*~ distclean: clean rm -f $(GENERATED) $(SWIGFILES)
libsepol/utils/Makefile +1 -1
@@ -16,7 +16,7 @@ install: all install -m 755 $(TARGETS) $(DESTDIR)$(BINDIR) clean: - -rm -f $(TARGETS) *.o + -rm -f $(TARGETS) ./*.o indent: ../../scripts/Lindent $(wildcard *.[ch])
mcstrans/Makefile +1 -1
@@ -8,7 +8,7 @@ install: $(MAKE) -C man install clean: - rm -f *~ \#* + rm -f ./*~ ./\#* $(MAKE) -C src clean $(MAKE) -C utils clean $(MAKE) -C man clean
mcstrans/man/Makefile +1 -1
@@ -26,6 +26,6 @@ install: all done clean: - -rm -f *~ \#* + -rm -f ./*~ \#* -rm -f man5/*~ man5/\#* -rm -f man8/*~ man8/\#*
mcstrans/src/Makefile +1 -1
@@ -34,5 +34,5 @@ install: all install -m 644 mcstrans.service $(DESTDIR)$(SYSTEMDDIR)/system/ clean: - -rm -f $(OBJS) $(LOBJS) $(TARGET) $(PROG) $(PROG_OBJS) *~ \#* + -rm -f $(OBJS) $(LOBJS) $(TARGET) $(PROG) $(PROG_OBJS) ./*~ \#*
mcstrans/utils/Makefile +1 -1
@@ -30,7 +30,7 @@ test: ./mlstrans-test-runner.py ../test/*.test clean: - rm -f $(TARGETS) *.o *~ \#* + rm -f $(TARGETS) ./*.o ./*~ \#* relabel:
policycoreutils/load_policy/Makefile +1 -1
@@ -26,7 +26,7 @@ install: all done clean: - -rm -f $(TARGETS) *.o + -rm -f $(TARGETS) ./*.o indent: ../../scripts/Lindent $(wildcard *.[ch])
policycoreutils/newrole/Makefile +1 -1
@@ -83,7 +83,7 @@ endif endif clean: - rm -f newrole *.o + rm -f newrole ./*.o indent: ../../scripts/Lindent $(wildcard *.[ch])
policycoreutils/po/Makefile +1 -1
@@ -123,7 +123,7 @@ refresh-po: Makefile done clean: - @rm -fv *mo *~ .depend + @rm -fv ./*mo ./*~ .depend @rm -rf tmp install: $(MOFILES)
policycoreutils/run_init/Makefile +1 -1
@@ -50,7 +50,7 @@ ifeq ($(PAMH), y) endif clean: - -rm -f $(TARGETS) *.o + -rm -f $(TARGETS) ./*.o indent: ../../scripts/Lindent $(wildcard *.[ch])
policycoreutils/secon/Makefile +1 -1
@@ -32,7 +32,7 @@ relabel: /sbin/restorecon $(DESTDIR)$(BINDIR)/secon clean: - rm -f *.o core* secon *~ *.bak + rm -f ./*.o core* secon ./*~ ./*.bak indent: ../../scripts/Lindent $(wildcard *.[ch])
policycoreutils/semodule/Makefile +1 -1
@@ -32,7 +32,7 @@ install: all relabel: clean: - -rm -f semodule *.o genhomedircon + -rm -f semodule ./*.o genhomedircon indent: ../../scripts/Lindent $(wildcard *.[ch])
policycoreutils/sestatus/Makefile +1 -1
@@ -32,7 +32,7 @@ install: all install -m 644 sestatus.conf $(DESTDIR)$(ETCDIR) clean: - rm -f sestatus *.o + rm -f sestatus ./*.o indent: ../../scripts/Lindent $(wildcard *.[ch])
policycoreutils/setfiles/Makefile +1 -1
@@ -45,7 +45,7 @@ install: all done clean: - rm -f setfiles restorecon restorecon_xattr *.o setfiles.8.man + rm -f setfiles restorecon restorecon_xattr ./*.o setfiles.8.man indent: ../../scripts/Lindent $(wildcard *.[ch])
policycoreutils/setsebool/Makefile +1 -1
@@ -32,7 +32,7 @@ install: all relabel: clean: - -rm -f setsebool *.o + -rm -f setsebool ./*.o indent: ../../scripts/Lindent $(wildcard *.[ch])
python/audit2allow/Makefile +1 -1
@@ -47,7 +47,7 @@ install: all done clean: - rm -f *~ *.o sepolgen-ifgen-attr-helper test_dummy_policy + rm -f ./*~ ./*.o sepolgen-ifgen-attr-helper test_dummy_policy indent: ../../scripts/Lindent $(wildcard *.[ch])
python/sepolgen/Makefile +1 -1
@@ -8,7 +8,7 @@ relabel: ; clean: $(MAKE) -C src $@ $(MAKE) -C tests $@ - rm -f *~ *.pyc + rm -f ./*~ ./*.pyc rm -f parser.out parsetab.py indent: ;
python/sepolgen/src/Makefile +1 -1
@@ -9,7 +9,7 @@ relabel: ; clean: $(MAKE) -C sepolgen $@ $(MAKE) -C share $@ - rm -f *~ *.pyc + rm -f ./*~ ./*.pyc rm -f parser.out parsetab.py indent: ;
python/sepolgen/src/sepolgen/Makefile +1 -1
@@ -11,5 +11,5 @@ install: all clean: rm -f parser.out parsetab.py - rm -f *~ *.pyc + rm -f ./*~ ./*.pyc rm -rf __pycache__
python/sepolgen/src/share/Makefile +1 -1
@@ -7,4 +7,4 @@ install: all install -m 644 perm_map $(DESTDIR)$(SHAREDIR) clean: - rm -f *~ + rm -f ./*~
python/sepolgen/tests/Makefile +1 -1
@@ -1,7 +1,7 @@ PYTHON ?= python3 clean: - rm -f *~ *.pyc + rm -f ./*~ ./*.pyc rm -f parser.out parsetab.py rm -f out.txt rm -f module_compile_test.fc
python/sepolicy/Makefile +1 -1
@@ -18,7 +18,7 @@ python-build: clean: $(PYTHON) setup.py clean - -rm -rf build *~ \#* *pyc .#* + -rm -rf build ./*~ \#* ./*pyc .#* sepolgen: ln -sf sepolicy sepolgen
restorecond/Makefile +1 -1
@@ -54,7 +54,7 @@ relabel: install /sbin/restorecon $(DESTDIR)$(SBINDIR)/restorecond clean: - -rm -f restorecond *.o *~ + -rm -f restorecond ./*.o ./*~ indent: ../../scripts/Lindent $(wildcard *.[ch])
sandbox/Makefile +1 -1
@@ -44,7 +44,7 @@ test: @$(PYTHON) test_sandbox.py -v clean: - -rm -f seunshare *.o *~ + -rm -f seunshare ./*.o ./*~ indent: ../../scripts/Lindent $(wildcard *.[ch])
semodule-utils/semodule_expand/Makefile +1 -1
@@ -26,7 +26,7 @@ install: all relabel: clean: - -rm -f semodule_expand *.o + -rm -f semodule_expand ./*.o indent: ../../scripts/Lindent $(wildcard *.[ch])
semodule-utils/semodule_link/Makefile +1 -1
@@ -26,7 +26,7 @@ install: all relabel: clean: - -rm -f semodule_link *.o + -rm -f semodule_link ./*.o indent: ../../scripts/Lindent $(wildcard *.[ch])
semodule-utils/semodule_package/Makefile +1 -1
@@ -28,7 +28,7 @@ install: all relabel: clean: - -rm -f semodule_package semodule_unpackage *.o + -rm -f semodule_package semodule_unpackage ./*.o indent: ../../scripts/Lindent $(wildcard *.[ch])
Signature · 1 line
2.23.0
PATCH 2/3 libselinux: generate Python glue code using "sed"
libselinux currently uses "gcc -aux-info" in order to generate glue code for its Python bindings that throws an exception when a function returns a negative integer value. This causes issues when another compiler than gcc is used (such as clang or icc), as option -aux-info is specific to gcc.
Replace "gcc -aux-info" with a command that parses the content of header files using "sed". As this is more fragile (because the declaration of functions is not normalized), add a new target to the Makefile in order to test that the new method does not produce different results with "make CC=gcc test".
When reverting commit cfe487409307 ("libselinux: mark all exported function "extern""), "make test" now fails as expected:
bash -e exception.sh test
Error ensuring that all exported functions that return an int are handled by exception.sh. Here are functions that were not found in "gcc -aux-info" but that were collected by "sed":
Here are functions in "gcc -aux-info" that may be missing "extern" in header file:
selinuxfs_exists
make: *** [Makefile:202: test] Error 1
Original thread: https://lore.kernel.org/selinux/[email protected]/T/#ma78bd7fe71fb5784387a8c0cebd867d6c02ee6e4
--- libselinux/Makefile | 1 + libselinux/src/Makefile | 5 ++++- libselinux/src/exception.sh | 38 +++++++++++++++++++++++++++++++------ 3 files changed, 37 insertions(+), 7 deletions(-)
libselinux/Makefile +1 -0
@@ -67,3 +67,4 @@ clean-rubywrap: $(MAKE) -C src clean-rubywrap $@ test: + $(MAKE) -C src test
libselinux/src/Makefile +4 -1
@@ -198,7 +198,10 @@ clean: clean-pywrap clean-rubywrap distclean: clean rm -f $(GENERATED) $(SWIGFILES) +test: + bash -e exception.sh test + indent: ../../scripts/Lindent $(filter-out $(GENERATED),$(wildcard *.[ch])) -.PHONY: all clean clean-pywrap clean-rubywrap pywrap rubywrap swigify install install-pywrap install-rubywrap distclean +.PHONY: all clean clean-pywrap clean-rubywrap pywrap rubywrap swigify install install-pywrap install-rubywrap distclean test indent
libselinux/src/exception.sh +32 -6
@@ -1,11 +1,12 @@ +#!/bin/bash -e function except() { -case $1 in +case "$1" in selinux_file_context_cmp) # ignore ;; *) echo " %exception $1 { - \$action + \$action if (result < 0) { PyErr_SetFromErrno(PyExc_OSError); SWIG_fail;
@@ -15,10 +16,35 @@ echo " ;; esac } -if ! ${CC:-gcc} -x c -c -I../include - -aux-info temp.aux < ../include/selinux/selinux.h + +if [ $# -eq 1 ] && [ "$1" = "test" ] then - # clang does not support -aux-info so fall back to gcc - gcc -x c -c -I../include - -aux-info temp.aux < ../include/selinux/selinux.h + # Ensure that "gcc -aux-info" produces the same list of functions as the sed command. + # The main difference between these way of producing the list of exported + # functions is that "gcc -aux-info" automatically inserts "extern" to all + # declarations and writes each one on a single line. + # clang does not support -aux-info, so skip the test if generating the aux file failed. + if ${CC:-gcc} -x c -c -I../include - -aux-info temp.aux < ../include/selinux/selinux.h + then + FCT_FROM_AUX="$(awk '/<stdin>.*extern int/ { print $6 }' temp.aux | sort -u)" + FCT_FROM_SED="$(sed -n 's/^extern \+int \+\([0-9A-Za-z_]\+\) *(.*$/\1/p' < ../include/selinux/selinux.h | sort -u)" + if [ "$FCT_FROM_AUX" != "$FCT_FROM_SED" ] + then + echo >&2 'Error ensuring that all exported functions that return an int are handled by exception.sh.' + echo >&2 'Here are functions that were not found in "gcc -aux-info" but that were collected by "sed":' + comm -13 <(echo "$FCT_FROM_AUX") <(echo "$FCT_FROM_SED") + echo >&2 'Here are functions in "gcc -aux-info" that may be missing "extern" in header file:' + comm -23 <(echo "$FCT_FROM_AUX") <(echo "$FCT_FROM_SED") + exit 1 + fi + fi + rm -f -- temp.aux -.o + exit fi -for i in `awk '/<stdin>.*extern int/ { print $6 }' temp.aux`; do except $i ; done + +# shellcheck disable=SC2013 +for i in $(sed -n 's/^extern \+int \+\([0-9A-Za-z_]\+\) *(.*$/\1/p' < ../include/selinux/selinux.h) +do + except "$i" +done rm -f -- temp.aux -.o
Signature · 1 line
2.23.0
Re: [PATCH 2/3] libselinux: generate Python glue code using "sed"
Quoted 15 lines · Nicolas Iooss
libselinux currently uses "gcc -aux-info" in order to generate glue code for its Python bindings that throws an exception when a function returns a negative integer value. This causes issues when another compiler than gcc is used (such as clang or icc), as option -aux-info is specific to gcc.
Replace "gcc -aux-info" with a command that parses the content of header files using "sed". As this is more fragile (because the declaration of functions is not normalized), add a new target to the
Makefilein order to test that the new method does not produce different results with "make CC=gcc test".When reverting commit
cfe487409307("libselinux: mark all exported function "extern""), "make test" now fails as expected:
Quoted 8 lines
bash -e
exception.shtest
Error ensuring that all exported functions that return an int are handled byexception.sh. Here are functions that were not found in "gcc -aux-info" but that were collected by "sed":
Here are functions in "gcc -aux-info" that may be missing "extern" in header file:
selinuxfs_exists
make: *** [Makefile:202: test] Error 1Original thread: https://lore.kernel.org/selinux/[email protected]/T/#ma78bd7fe71fb5784387a8c0cebd867d6c02ee6e4
I'm not excited about moving to a more fragile method of generating this glue code. Would it perhaps suffice for us to pre-generate the files and keep them in-tree (or package them as part of the tar file distributions) so that downstream users without gcc can just use the generated files?
Quoted 94 lines
Signed-off-by Nicolas Iooss <[email protected]>Cc Michael Shigorin <[email protected]>--- libselinux/Makefile | 1 + libselinux/src/Makefile | 5 ++++- libselinux/src/exception.sh | 38 +++++++++++++++++++++++++++++++------ 3 files changed, 37 insertions(+), 7 deletions(-)libselinux/Makefile +1
-0@@ -67,3 +67,4 @@ clean-rubywrap: $(MAKE) -C src clean-rubywrap $@ test: + $(MAKE) -C src testlibselinux/src/Makefile +4
-1@@ -198,7 +198,10 @@ clean: clean-pywrap clean-rubywrap distclean: clean rm -f $(GENERATED) $(SWIGFILES) +test: + bash -e exception.sh test + indent: ../../scripts/Lindent $(filter-out $(GENERATED),$(wildcard *.[ch])) -.PHONY: all clean clean-pywrap clean-rubywrap pywrap rubywrap swigify install install-pywrap install-rubywrap distclean +.PHONY: all clean clean-pywrap clean-rubywrap pywrap rubywrap swigify install install-pywrap install-rubywrap distclean test indentlibselinux/src/exception.sh +32
-6@@ -1,11 +1,12 @@ +#!/bin/bash -e function except() { -case $1 in +case "$1" in selinux_file_context_cmp) # ignore ;; *) echo " %exception $1 { - \$action + \$action if (result < 0) { PyErr_SetFromErrno(PyExc_OSError); SWIG_fail;@@ -15,10 +16,35 @@ echo " ;; esac } -if ! ${CC:-gcc} -x c -c -I../include - -aux-info temp.aux < ../include/selinux/selinux.h + +if [ $# -eq 1 ] && [ "$1" = "test" ] then - # clang does not support -aux-info so fall back to gcc - gcc -x c -c -I../include - -aux-info temp.aux < ../include/selinux/selinux.h + # Ensure that "gcc -aux-info" produces the same list of functions as the sed command. + # The main difference between these way of producing the list of exported + # functions is that "gcc -aux-info" automatically inserts "extern" to all + # declarations and writes each one on a single line. + # clang does not support -aux-info, so skip the test if generating the aux file failed. + if ${CC:-gcc} -x c -c -I../include - -aux-info temp.aux < ../include/selinux/selinux.h + then + FCT_FROM_AUX="$(awk '/<stdin>.*extern int/ { print $6 }' temp.aux | sort -u)" + FCT_FROM_SED="$(sed -n 's/^extern \+int \+\([0-9A-Za-z_]\+\) *(.*$/\1/p' < ../include/selinux/selinux.h | sort -u)" + if [ "$FCT_FROM_AUX" != "$FCT_FROM_SED" ] + then + echo >&2 'Error ensuring that all exported functions that return an int are handled by exception.sh.' + echo >&2 'Here are functions that were not found in "gcc -aux-info" but that were collected by "sed":' + comm -13 <(echo "$FCT_FROM_AUX") <(echo "$FCT_FROM_SED") + echo >&2 'Here are functions in "gcc -aux-info" that may be missing "extern" in header file:' + comm -23 <(echo "$FCT_FROM_AUX") <(echo "$FCT_FROM_SED") + exit 1 + fi + fi + rm -f -- temp.aux -.o + exit fi -for i in `awk '/<stdin>.*extern int/ { print $6 }' temp.aux`; do except $i ; done + +# shellcheck disable=SC2013 +for i in $(sed -n 's/^extern \+int \+\([0-9A-Za-z_]\+\) *(.*$/\1/p' < ../include/selinux/selinux.h) +do + except "$i" +done rm -f -- temp.aux -.o
PATCH 3/3 libsemanage: generate Python glue code using "sed"
In reply to Nicolas Ioosslibsemanage currently uses "gcc -aux-info" in order to generate glue code for its Python bindings that throws an exception when a function returns a negative integer value. This causes issues when another compiler than gcc is used (such as clang or icc), as option -aux-info is specific to gcc.
Replace "gcc -aux-info" with a command that parses the content of header files using "sed". As this is more fragile (because the declaration of functions is not normalized), add a new target to the Makefile in order to test that the new method does not produce different results with "make CC=gcc test".
When reverting commit b915c7a9d330 ("libsemanage: mark all exported function "extern""), "make test" now fails as expected:
bash -e exception.sh test
Error ensuring that all exported functions that return an int are handled by exception.sh. Here are functions that were not found in "gcc -aux-info" but that were collected by "sed":
Here are functions in "gcc -aux-info" that may be missing "extern" in header file:
semanage_access_check
semanage_begin_transaction
semanage_commit
semanage_connect
semanage_disconnect
semanage_get_disable_dontaudit
semanage_get_hll_compiler_path
...
make: *** [Makefile:202: test] Error 1
Original thread: https://lore.kernel.org/selinux/[email protected]/T/#ma78bd7fe71fb5784387a8c0cebd867d6c02ee6e4
--- libsemanage/Makefile | 1 + libsemanage/src/Makefile | 5 ++++- libsemanage/src/exception.sh | 34 ++++++++++++++++++++++++++++++---- 3 files changed, 35 insertions(+), 5 deletions(-)
libsemanage/Makefile +1 -0
@@ -34,4 +34,5 @@ indent: $(MAKE) -C include $@ test: all + $(MAKE) -C src test $(MAKE) -C tests test
libsemanage/src/Makefile +4 -1
@@ -160,7 +160,10 @@ clean: distclean: clean rm -f $(GENERATED) $(SWIGFILES) +test: + bash -e exception.sh test + indent: ../../scripts/Lindent $(filter-out $(GENERATED),$(wildcard *.[ch])) -.PHONY: all clean pywrap rubywrap swigify install install-pywrap install-rubywrap distclean +.PHONY: all clean pywrap rubywrap swigify install install-pywrap install-rubywrap distclean test indent
libsemanage/src/exception.sh +30 -4
@@ -1,3 +1,4 @@ +#!/bin/bash -e function except() { echo " %exception $1 {
@@ -9,10 +10,35 @@ echo " } " } -if ! ${CC:-gcc} -x c -c -I../include - -aux-info temp.aux < ../include/semanage/semanage.h + +if [ $# -eq 1 ] && [ "$1" = "test" ] then - # clang does not support -aux-info so fall back to gcc - gcc -x c -c -I../include - -aux-info temp.aux < ../include/semanage/semanage.h + # Ensure that "gcc -aux-info" produces the same list of functions as the sed command. + # The main difference between these way of producing the list of exported + # functions is that "gcc -aux-info" automatically inserts "extern" to all + # declarations and writes each one on a single line. + # clang does not support -aux-info, so skip the test if generating the aux file failed. + if ${CC:-gcc} -x c -c -I../include - -aux-info temp.aux < ../include/semanage/semanage.h + then + FCT_FROM_AUX="$(awk '/include\/semanage\/.*extern int/ { print $6 }' temp.aux | sort -u)" + FCT_FROM_SED="$(cat ../include/semanage/*.h | sed -n 's/^extern \+int \+\([0-9A-Za-z_]\+\) *(.*$/\1/p' | sort -u)" + if [ "$FCT_FROM_AUX" != "$FCT_FROM_SED" ] + then + echo >&2 'Error ensuring that all exported functions that return an int are handled by exception.sh.' + echo >&2 'Here are functions that were not found in "gcc -aux-info" but that were collected by "sed":' + comm -13 <(echo "$FCT_FROM_AUX") <(echo "$FCT_FROM_SED") + echo >&2 'Here are functions in "gcc -aux-info" that may be missing "extern" in header file:' + comm -23 <(echo "$FCT_FROM_AUX") <(echo "$FCT_FROM_SED") + exit 1 + fi + fi + rm -f -- temp.aux -.o + exit fi -for i in `awk '/extern int/ { print $6 }' temp.aux`; do except $i ; done + +# shellcheck disable=SC2013 +for i in $(cat ../include/semanage/*.h | sed -n 's/^extern \+int \+\([0-9A-Za-z_]\+\) *(.*$/\1/p') +do + except "$i" +done rm -f -- temp.aux -.o
Signature · 1 line
2.23.0
Quoted 5 lines · Nicolas Iooss
libselinux/src/exception.shcreates a file named "-.o". This file is usually removed at the end of this script, but some failures in it could left it on the filesystem. "make clean" is then supposed to remove this file, but fails instead with:
Quoted 7 lines
rm: invalid option -- '.'
Try 'rm ./-.o' to remove the file '-.o'.
Try 'rm --help' for more information.This is due to "rm -f *.o" being expanded to "rm -f -.o". Prevent this buggy expansion by using "./*.o" in the command line. While at it, do so for other patterns like "*~".
Does any other software package use this idiom for clean? I haven't seen it. I'm wondering if we aren't better off doing any/all of the following:
1) Fix exception.sh to not create files starting in "-",
2) Fix our clean targets to only delete explicitly generated object file lists; some of them at least already have $(OBJS) $(LOBJS) so why do we need the extra wildcard?
3) Maybe use $(wildcard ...)?
Quoted 422 lines
Signed-off-by Nicolas Iooss <[email protected]>--- checkpolicy/test/Makefile | 2 +- libselinux/src/Makefile | 4 ++-- libselinux/utils/Makefile | 2 +- libsemanage/src/Makefile | 2 +- libsepol/utils/Makefile | 2 +- mcstrans/Makefile | 2 +- mcstrans/man/Makefile | 2 +- mcstrans/src/Makefile | 2 +- mcstrans/utils/Makefile | 2 +- policycoreutils/load_policy/Makefile | 2 +- policycoreutils/newrole/Makefile | 2 +- policycoreutils/po/Makefile | 2 +- policycoreutils/run_init/Makefile | 2 +- policycoreutils/secon/Makefile | 2 +- policycoreutils/semodule/Makefile | 2 +- policycoreutils/sestatus/Makefile | 2 +- policycoreutils/setfiles/Makefile | 2 +- policycoreutils/setsebool/Makefile | 2 +- python/audit2allow/Makefile | 2 +- python/sepolgen/Makefile | 2 +- python/sepolgen/src/Makefile | 2 +- python/sepolgen/src/sepolgen/Makefile | 2 +- python/sepolgen/src/share/Makefile | 2 +- python/sepolgen/tests/Makefile | 2 +- python/sepolicy/Makefile | 2 +- restorecond/Makefile | 2 +- sandbox/Makefile | 2 +- semodule-utils/semodule_expand/Makefile | 2 +- semodule-utils/semodule_link/Makefile | 2 +- semodule-utils/semodule_package/Makefile | 2 +- 30 files changed, 31 insertions(+), 31 deletions(-)checkpolicy/test/Makefile +1
-1@@ -19,4 +19,4 @@ dismod: dismod.o $(LIBSEPOLA) $(CC) $(LDFLAGS) -o $@ $^ $(LDLIBS_LIBSEPOLA) clean: - -rm -f dispol dismod *.o + -rm -f dispol dismod ./*.olibselinux/src/Makefile +2
-2@@ -187,13 +187,13 @@ relabel: clean-pywrap: -rm -f $(SWIGLOBJ) $(SWIGSO) $(AUDIT2WHYLOBJ) $(AUDIT2WHYSO) $(PYTHON) setup.py clean - -rm -rf build *~ \#* *pyc .#* + -rm -rf build ./*~ \#* ./*pyc .#* clean-rubywrap: -rm -f $(SWIGRUBYLOBJ) $(SWIGRUBYSO) clean: clean-pywrap clean-rubywrap - -rm -f $(LIBPC) $(OBJS) $(LOBJS) $(LIBA) $(LIBSO) $(TARGET) *.o *.lo *~ + -rm -f $(LIBPC) $(OBJS) $(LOBJS) $(LIBA) $(LIBSO) $(TARGET) ./*.o ./*.lo ./*~ distclean: clean rm -f $(GENERATED) $(SWIGFILES)libselinux/utils/Makefile +1
-1@@ -65,7 +65,7 @@ install: all install -m 755 $(TARGETS) $(DESTDIR)$(SBINDIR) clean: - rm -f $(TARGETS) *.o *~ + rm -f $(TARGETS) ./*.o ./*~ distclean: cleanlibsemanage/src/Makefile +1
-1@@ -155,7 +155,7 @@ relabel: /sbin/restorecon $(DESTDIR)$(LIBDIR)/$(LIBSO) clean: - -rm -f $(LIBPC) $(OBJS) $(LOBJS) $(LIBA) $(LIBSO) $(SWIGLOBJ) $(SWIGSO) $(SWIGRUBYSO) $(TARGET) conf-parse.c conf-parse.h conf-scan.c *.o *.lo *~ + -rm -f $(LIBPC) $(OBJS) $(LOBJS) $(LIBA) $(LIBSO) $(SWIGLOBJ) $(SWIGSO) $(SWIGRUBYSO) $(TARGET) conf-parse.c conf-parse.h conf-scan.c ./*.o ./*.lo ./*~ distclean: clean rm -f $(GENERATED) $(SWIGFILES)libsepol/utils/Makefile +1
-1@@ -16,7 +16,7 @@ install: all install -m 755 $(TARGETS) $(DESTDIR)$(BINDIR) clean: - -rm -f $(TARGETS) *.o + -rm -f $(TARGETS) ./*.o indent: ../../scripts/Lindent $(wildcard *.[ch])mcstrans/Makefile +1
-1@@ -8,7 +8,7 @@ install: $(MAKE) -C man install clean: - rm -f *~ \#* + rm -f ./*~ ./\#* $(MAKE) -C src clean $(MAKE) -C utils clean $(MAKE) -C man cleanmcstrans/man/Makefile +1
-1@@ -26,6 +26,6 @@ install: all done clean: - -rm -f *~ \#* + -rm -f ./*~ \#* -rm -f man5/*~ man5/\#* -rm -f man8/*~ man8/\#*mcstrans/src/Makefile +1
-1@@ -34,5 +34,5 @@ install: all install -m 644 mcstrans.service $(DESTDIR)$(SYSTEMDDIR)/system/ clean: - -rm -f $(OBJS) $(LOBJS) $(TARGET) $(PROG) $(PROG_OBJS) *~ \#* + -rm -f $(OBJS) $(LOBJS) $(TARGET) $(PROG) $(PROG_OBJS) ./*~ \#*mcstrans/utils/Makefile +1
-1@@ -30,7 +30,7 @@ test: ./mlstrans-test-runner.py ../test/*.test clean: - rm -f $(TARGETS) *.o *~ \#* + rm -f $(TARGETS) ./*.o ./*~ \#* relabel:policycoreutils/load_policy/Makefile +1
-1@@ -26,7 +26,7 @@ install: all done clean: - -rm -f $(TARGETS) *.o + -rm -f $(TARGETS) ./*.o indent: ../../scripts/Lindent $(wildcard *.[ch])policycoreutils/newrole/Makefile +1
-1@@ -83,7 +83,7 @@ endif endif clean: - rm -f newrole *.o + rm -f newrole ./*.o indent: ../../scripts/Lindent $(wildcard *.[ch])policycoreutils/po/Makefile +1
-1@@ -123,7 +123,7 @@ refresh-po: Makefile done clean: - @rm -fv *mo *~ .depend + @rm -fv ./*mo ./*~ .depend @rm -rf tmp install: $(MOFILES)policycoreutils/run_init/Makefile +1
-1@@ -50,7 +50,7 @@ ifeq ($(PAMH), y) endif clean: - -rm -f $(TARGETS) *.o + -rm -f $(TARGETS) ./*.o indent: ../../scripts/Lindent $(wildcard *.[ch])policycoreutils/secon/Makefile +1
-1@@ -32,7 +32,7 @@ relabel: /sbin/restorecon $(DESTDIR)$(BINDIR)/secon clean: - rm -f *.o core* secon *~ *.bak + rm -f ./*.o core* secon ./*~ ./*.bak indent: ../../scripts/Lindent $(wildcard *.[ch])policycoreutils/semodule/Makefile +1
-1@@ -32,7 +32,7 @@ install: all relabel: clean: - -rm -f semodule *.o genhomedircon + -rm -f semodule ./*.o genhomedircon indent: ../../scripts/Lindent $(wildcard *.[ch])policycoreutils/sestatus/Makefile +1
-1@@ -32,7 +32,7 @@ install: all install -m 644 sestatus.conf $(DESTDIR)$(ETCDIR) clean: - rm -f sestatus *.o + rm -f sestatus ./*.o indent: ../../scripts/Lindent $(wildcard *.[ch])policycoreutils/setfiles/Makefile +1
-1@@ -45,7 +45,7 @@ install: all done clean: - rm -f setfiles restorecon restorecon_xattr *.o setfiles.8.man + rm -f setfiles restorecon restorecon_xattr ./*.o setfiles.8.man indent: ../../scripts/Lindent $(wildcard *.[ch])policycoreutils/setsebool/Makefile +1
-1@@ -32,7 +32,7 @@ install: all relabel: clean: - -rm -f setsebool *.o + -rm -f setsebool ./*.o indent: ../../scripts/Lindent $(wildcard *.[ch])python/audit2allow/Makefile +1
-1@@ -47,7 +47,7 @@ install: all done clean: - rm -f *~ *.o sepolgen-ifgen-attr-helper test_dummy_policy + rm -f ./*~ ./*.o sepolgen-ifgen-attr-helper test_dummy_policy indent: ../../scripts/Lindent $(wildcard *.[ch])python/sepolgen/Makefile +1
-1@@ -8,7 +8,7 @@ relabel: ; clean: $(MAKE) -C src $@ $(MAKE) -C tests $@ - rm -f *~ *.pyc + rm -f ./*~ ./*.pyc rm -f parser.out parsetab.py indent: ;python/sepolgen/src/Makefile +1
-1@@ -9,7 +9,7 @@ relabel: ; clean: $(MAKE) -C sepolgen $@ $(MAKE) -C share $@ - rm -f *~ *.pyc + rm -f ./*~ ./*.pyc rm -f parser.out parsetab.py indent: ;python/sepolgen/src/sepolgen/Makefile +1
-1@@ -11,5 +11,5 @@ install: all clean: rm -f parser.out parsetab.py - rm -f *~ *.pyc + rm -f ./*~ ./*.pyc rm -rf __pycache__python/sepolgen/src/share/Makefile +1
-1@@ -7,4 +7,4 @@ install: all install -m 644 perm_map $(DESTDIR)$(SHAREDIR) clean: - rm -f *~ + rm -f ./*~python/sepolgen/tests/Makefile +1
-1@@ -1,7 +1,7 @@ PYTHON ?= python3 clean: - rm -f *~ *.pyc + rm -f ./*~ ./*.pyc rm -f parser.out parsetab.py rm -f out.txt rm -f module_compile_test.fcpython/sepolicy/Makefile +1
-1@@ -18,7 +18,7 @@ python-build: clean: $(PYTHON) setup.py clean - -rm -rf build *~ \#* *pyc .#* + -rm -rf build ./*~ \#* ./*pyc .#* sepolgen: ln -sf sepolicy sepolgenrestorecond/Makefile +1
-1@@ -54,7 +54,7 @@ relabel: install /sbin/restorecon $(DESTDIR)$(SBINDIR)/restorecond clean: - -rm -f restorecond *.o *~ + -rm -f restorecond ./*.o ./*~ indent: ../../scripts/Lindent $(wildcard *.[ch])sandbox/Makefile +1
-1@@ -44,7 +44,7 @@ test: @$(PYTHON) test_sandbox.py -v clean: - -rm -f seunshare *.o *~ + -rm -f seunshare ./*.o ./*~ indent: ../../scripts/Lindent $(wildcard *.[ch])semodule-utils/semodule_expand/Makefile +1
-1@@ -26,7 +26,7 @@ install: all relabel: clean: - -rm -f semodule_expand *.o + -rm -f semodule_expand ./*.o indent: ../../scripts/Lindent $(wildcard *.[ch])semodule-utils/semodule_link/Makefile +1
-1@@ -26,7 +26,7 @@ install: all relabel: clean: - -rm -f semodule_link *.o + -rm -f semodule_link ./*.o indent: ../../scripts/Lindent $(wildcard *.[ch])semodule-utils/semodule_package/Makefile +1
-1@@ -28,7 +28,7 @@ install: all relabel: clean: - -rm -f semodule_package semodule_unpackage *.o + -rm -f semodule_package semodule_unpackage ./*.o indent: ../../scripts/Lindent $(wildcard *.[ch])
Quoted 19 lines · Stephen Smalley
Quoted 5 lines · Nicolas Iooss
libselinux/src/exception.shcreates a file named "-.o". This file is usually removed at the end of this script, but some failures in it could left it on the filesystem. "make clean" is then supposed to remove this file, but fails instead with:Quoted 7 lines
rm: invalid option -- '.'
Try 'rm ./-.o' to remove the file '-.o'.
Try 'rm --help' for more information.This is due to "rm -f *.o" being expanded to "rm -f -.o". Prevent this buggy expansion by using "./*.o" in the command line. While at it, do so for other patterns like "*~".
Does any other software package use this idiom for clean? I haven't seen it. I'm wondering if we aren't better off doing any/all of the following:
Quoted 5 lines
1) Fix
exception.shto not create files starting in "-",
2) Fix our clean targets to only delete explicitly generated object file lists; some of them at least already have $(OBJS) $(LOBJS) so why do we need the extra wildcard?
3) Maybe use $(wildcard ...)?
The only over software that use "./*..." or "rm -- *..." are those which handle directories with "untrusted content", ie. with files whose names may be created by an attacker. Such as threat model is not applicable on a build management system, which is why only few projects use ./* or "rm --" in "make clean".
Therefore I agree with considering that creating a file starting with "-" is a bug. I will send a patch to fix exception.sh (by adding "-o temp.o" to some commands). Thanks for your feedback. Nicolas