Skip to contentSkip to conversation

libselinux,libsemanage: fall back to gcc in exception.sh

PATCH Applied Nicolas Iooss 3 participants 7 messages Nov 14, 2016 – Nov 15, 2016 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 libselinux,libsemanage: fall back to gcc in exception.sh

clang does not support -aux-info option. When exception.sh is run with CC=clang, use gcc to build selinuxswig_python_exception.i and semanageswig_python_exception.i.

This does not solve the issue of building libselinux and libsemanage Python wrappers on a system without gcc. However parsing the result of "gcc -aux-info" is easier than parsing the header files so stay with this command at least for now.

---
 libselinux/src/exception.sh  | 6 +++++-
 libsemanage/src/exception.sh | 6 +++++-
 2 files changed, 10 insertions(+), 2 deletions(-)
libselinux/src/exception.sh +5 -1
index a58bf3f45778..a3ff83235ced 100755
@@ -15,6 +15,10 @@ echo "
 ;;
 esac
 }
-${CC:-gcc} -x c -c -I../include - -aux-info temp.aux < ../include/selinux/selinux.h
+if ! ${CC:-gcc} -x c -c -I../include - -aux-info temp.aux < ../include/selinux/selinux.h
+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
+fi
 for i in `awk '/<stdin>.*extern int/ { print $6 }' temp.aux`; do except $i ; done 
 rm -f -- temp.aux -.o
libsemanage/src/exception.sh +5 -1
index d18959cbe85d..a4095f4f8ba6 100644
@@ -9,6 +9,10 @@ echo "
 }
 "
 }
-${CC:-gcc} -x c -c -I../include - -aux-info temp.aux < ../include/semanage/semanage.h
+if ! ${CC:-gcc} -x c -c -I../include - -aux-info temp.aux < ../include/semanage/semanage.h
+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
+fi
 for i in `awk '/extern int/ { print $6 }' temp.aux`; do except $i ; done
 rm -f -- temp.aux -.o
Signature · 1 line
2.10.2
#1 lore raw

PATCH 2/2 libselinux, libsemanage: swig: use SWIG_fail when an error occurs

Using SWIG_fail in the Python SWIG wrappers makes the wrapping function destroy/free the memory which could have been dynamically allocated before calling the wrapped function. This thus prevents possible memory leaks in the wrappers of set*con(), set*con_raw(), security_compute_*(), etc.

---
 libselinux/src/exception.sh  | 2 +-
 libsemanage/src/exception.sh | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
libselinux/src/exception.sh +1 -1
index a3ff83235ced..d6c8c71713ad 100755
@@ -8,7 +8,7 @@ echo "
   \$action 
   if (result < 0) {
      PyErr_SetFromErrno(PyExc_OSError);
-     return NULL;
+     SWIG_fail;
   }
 }
 "
libsemanage/src/exception.sh +1 -1
index a4095f4f8ba6..97bc2ae879f2 100644
@@ -4,7 +4,7 @@ echo "
   \$action
   if (result < 0) {
      PyErr_SetFromErrno(PyExc_OSError);
-     return NULL;
+     SWIG_fail;
   }
 }
 "
Signature · 1 line
2.10.2
#2 lore raw

Re: [PATCH 2/2] libselinux, libsemanage: swig: use SWIG_fail when an error occurs

Quoted 7 lines · Nicolas Iooss

Using SWIG_fail in the Python SWIG wrappers makes the wrapping function destroy/free the memory which could have been dynamically allocated before calling the wrapped function. This thus prevents possible memory leaks in the wrappers of set*con(), set*con_raw(), security_compute_*(), etc.

Thanks, applied both patches.

Quoted 32 lines
---
 libselinux/src/exception.sh  | 2 +-
 libsemanage/src/exception.sh | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
libselinux/src/exception.sh +1 -1
index a3ff83235ced..d6c8c71713ad 100755
@@ -8,7 +8,7 @@ echo "
   \$action 
   if (result < 0) {
      PyErr_SetFromErrno(PyExc_OSError);
-     return NULL;
+     SWIG_fail;
   }
 }
 "
libsemanage/src/exception.sh +1 -1
index a4095f4f8ba6..97bc2ae879f2 100644
@@ -4,7 +4,7 @@ echo "
   \$action
   if (result < 0) {
      PyErr_SetFromErrno(PyExc_OSError);
-     return NULL;
+     SWIG_fail;
   }
 }
 "
#3 lore raw

Re: [PATCH 1/2] libselinux, libsemanage: fall back to gcc in exception.sh

In reply to Nicolas Iooss

For a more long term solution, why not just give swig a header file (you can ifdef on SWIG for anything to omit), or write the interface file by hand. I ended up using a hybrid approach for one my projects (the build system is a mess):

https://bitbucket.org/miniat/0x1-miniat/src/f84cb76ab0fbe645ee9c48d30221b29283745778/vm/src/miniat_python.i?at=master&fileviewer=file-view-default

Quoted 55 lines · Nicolas Iooss

clang does not support -aux-info option. When exception.sh is run with CC=clang, use gcc to build selinuxswig_python_exception.i and semanageswig_python_exception.i.

This does not solve the issue of building libselinux and libsemanage Python wrappers on a system without gcc. However parsing the result of "gcc -aux-info" is easier than parsing the header files so stay with this command at least for now.

---
 libselinux/src/exception.sh  | 6 +++++-
 libsemanage/src/exception.sh | 6 +++++-
 2 files changed, 10 insertions(+), 2 deletions(-)
libselinux/src/exception.sh +5 -1
index a58bf3f45778..a3ff83235ced 100755
@@ -15,6 +15,10 @@ echo "
 ;;
 esac
 }
-${CC:-gcc} -x c -c -I../include - -aux-info temp.aux < ../include/selinux/selinux.h
+if ! ${CC:-gcc} -x c -c -I../include - -aux-info temp.aux < ../include/selinux/selinux.h
+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
+fi
 for i in `awk '/<stdin>.*extern int/ { print $6 }' temp.aux`; do except $i ; done
 rm -f -- temp.aux -.o
libsemanage/src/exception.sh +5 -2
index d18959cbe85d..a4095f4f8ba6 100644
@@ -9,6 +9,10 @@ echo "
 }
 "
 }
-${CC:-gcc} -x c -c -I../include - -aux-info temp.aux < ../include/semanage/semanage.h
+if ! ${CC:-gcc} -x c -c -I../include - -aux-info temp.aux < ../include/semanage/semanage.h
+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
+fi
 for i in `awk '/extern int/ { print $6 }' temp.aux`; do except $i ; done
 rm -f -- temp.aux -.o
--

2.10.2

_______________________________________________
Selinux mailing list
[email protected]
To unsubscribe, send email to [email protected].
To get help, send an email containing "help" to [email protected].

Signature · 3 lines
Respectfully,

William C Roberts
#4 lore raw

Re: [PATCH 1/2] libselinux, libsemanage: fall back to gcc in exception.sh

The SWIG wrapper already includes the header files using #include (look at the beginning of libselinux/src/selinuxswig_python.i [1] for example). The script exception.h reads the header files (through gcc -aux-info) to generate some SWIG code for almost every interface returning an integer (this code converts a negative return value to the raising of a Python OSError exception).

In SWIG documentation [2] I have not found a way to automatically apply a %exception block to all functions matched by the pattern "it returns an integer". As you seem to believe I missed something, could you please explain how you would proceed here?

Nicolas

[1]
https://github.com/SELinuxProject/selinux/blob/master/libselinux/src/selinuxswig_python.i#L11
[2] http://www.swig.org/Doc3.0/SWIGDocumentation.html

Quoted 82 lines · William Roberts

For a more long term solution, why not just give swig a header file (you can ifdef on SWIG for anything to omit), or write the interface file by hand. I ended up using a hybrid approach for one my projects (the build system is a mess):

https://bitbucket.org/miniat/0x1-miniat/src/f84cb76ab0fbe645ee9c48d30221b2
9283745778/vm/src/miniat_python.i?at=master&fileviewer=file-view-default

Quoted 20 lines · Nicolas Iooss

clang does not support -aux-info option. When exception.sh is run with CC=clang, use gcc to build selinuxswig_python_exception.i and semanageswig_python_exception.i.

This does not solve the issue of building libselinux and libsemanage Python wrappers on a system without gcc. However parsing the result of "gcc -aux-info" is easier than parsing the header files so stay with this command at least for now.

---
 libselinux/src/exception.sh  | 6 +++++-
 libsemanage/src/exception.sh | 6 +++++-
 2 files changed, 10 insertions(+), 2 deletions(-)
libselinux/src/exception.sh +0 -0
index a58bf3f45778..a3ff83235ced 100755

libselinux/src/exception.sh echo " · line 18

Quoted 4 lines
libselinux/src/exception.sh +0 -1
@@ -15,6 +15,10 @@ echo "
 ;;
 esac
 }
-${CC:-gcc} -x c -c -I../include - -aux-info temp.aux <

../include/selinux/selinux.h

libselinux/src/exception.sh echo " · line 18

Quoted 1 line
libselinux/src/exception.sh +1 -0
+if ! ${CC:-gcc} -x c -c -I../include - -aux-info temp.aux <

../include/selinux/selinux.h

libselinux/src/exception.sh echo "

Quoted 3 lines
libselinux/src/exception.sh +3 -0
+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

libselinux/src/exception.sh echo " · line 23

Quoted 2 lines
libselinux/src/exception.sh +1 -0
+fi
 for i in `awk '/<stdin>.*extern int/ { print $6 }' temp.aux`; do except

$i ; done

libsemanage/src/exception.sh echo " · line 12

Quoted 10 lines
libselinux/src/exception.sh +0 -0
 rm -f -- temp.aux -.o
libsemanage/src/exception.sh +0 -1
index d18959cbe85d..a4095f4f8ba6 100644
@@ -9,6 +9,10 @@ echo "
 }
 "
 }
-${CC:-gcc} -x c -c -I../include - -aux-info temp.aux <

../include/semanage/semanage.h

libsemanage/src/exception.sh echo " · line 12

Quoted 1 line
libsemanage/src/exception.sh +1 -0
+if ! ${CC:-gcc} -x c -c -I../include - -aux-info temp.aux <

../include/semanage/semanage.h

libsemanage/src/exception.sh echo " · line 15

Quoted 3 lines
libsemanage/src/exception.sh +3 -0
+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

Quoted 11 lines
libsemanage/src/exception.sh +1 -1
+fi
 for i in `awk '/extern int/ { print $6 }' temp.aux`; do except $i ; done
 rm -f -- temp.aux -.o
--

2.10.2

_______________________________________________
Selinux mailing list
[email protected]
To unsubscribe, send email to [email protected]. To get help, send an email containing "help" to

[email protected].

--
Respectfully,

William C Roberts

#5 lore raw

Re: [PATCH 1/2] libselinux, libsemanage: fall back to gcc in exception.sh

Quoted 10 lines · Nicolas Iooss

The SWIG wrapper already includes the header files using #include (look at the beginning of libselinux/src/selinuxswig_python.i [1] for example). The script exception.h reads the header files (through gcc -aux-info) to generate some SWIG code for almost every interface returning an integer (this code converts a negative return value to the raising of a Python OSError exception).

In SWIG documentation [2] I have not found a way to automatically apply a %exception block to all functions matched by the pattern "it returns an integer". As you seem to believe I missed something,

I don't think you did.

could you please

Quoted 1 line

explain how you would proceed here?

Yeah that script is just generating a bunch of interface code, I would just remove that script
and write it by hand. The only downfall is that you would have to add a stub if you add something
to the header file, but I don't consider that a downside, I prefer to be explicit. Especially
considering they already had to put a function in the script to skip. I don't think the script provides
much value.

Quoted 95 lines

Nicolas

[1]
https://github.com/SELinuxProject/selinux/blob/master/libselinux/src/selinuxswig_python.i#L11
[2] http://www.swig.org/Doc3.0/SWIGDocumentation.html

Quoted 83 lines · William Roberts

For a more long term solution, why not just give swig a header file (you can ifdef on SWIG for anything to omit), or write the interface file by hand. I ended up using a hybrid approach for one my projects (the build system is a mess):

https://bitbucket.org/miniat/0x1-miniat/src/f84cb76ab0fbe645ee9c48d30221b29283745778/vm/src/miniat_python.i?at=master&fileviewer=file-view-default

Quoted 58 lines · Nicolas Iooss

clang does not support -aux-info option. When exception.sh is run with CC=clang, use gcc to build selinuxswig_python_exception.i and semanageswig_python_exception.i.

This does not solve the issue of building libselinux and libsemanage Python wrappers on a system without gcc. However parsing the result of "gcc -aux-info" is easier than parsing the header files so stay with this command at least for now.

---
 libselinux/src/exception.sh  | 6 +++++-
 libsemanage/src/exception.sh | 6 +++++-
 2 files changed, 10 insertions(+), 2 deletions(-)
libselinux/src/exception.sh +0 -1
index a58bf3f45778..a3ff83235ced 100755
@@ -15,6 +15,10 @@ echo "
 ;;
 esac
 }
-${CC:-gcc} -x c -c -I../include - -aux-info temp.aux <

../include/selinux/selinux.h
+if ! ${CC:-gcc} -x c -c -I../include - -aux-info temp.aux < ../include/selinux/selinux.h

libselinux/src/exception.sh +3 -0
+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
+fi
for i in awk '/<stdin>.*extern int/ { print $6 }' temp.aux; do except
$i ; done
rm -f -- temp.aux -.o

libsemanage/src/exception.sh +0 -1
index d18959cbe85d..a4095f4f8ba6 100644
@@ -9,6 +9,10 @@ echo "
 }
 "
 }
-${CC:-gcc} -x c -c -I../include - -aux-info temp.aux <

../include/semanage/semanage.h
+if ! ${CC:-gcc} -x c -c -I../include - -aux-info temp.aux < ../include/semanage/semanage.h

libsemanage/src/exception.sh +3 -0
+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
+fi
for i in awk '/extern int/ { print $6 }' temp.aux; do except $i ;
done
rm -f -- temp.aux -.o
--
2.10.2

Quoted 6 lines

_______________________________________________
Selinux mailing list
[email protected]
To unsubscribe, send email to [email protected]. To get help, send an email containing "help" to [email protected].

--
Respectfully,

William C Roberts

Signature · 3 lines
Respectfully,

William C Roberts
#6 lore raw

Re: [PATCH 1/2] libselinux, libsemanage: fall back to gcc in exception.sh

Quoted 20 lines · William Roberts
Quoted 1 line · Nicolas Iooss

The SWIG wrapper already includes the header files using #include (look

at

Quoted 1 line

the beginning of libselinux/src/selinuxswig_python.i [1] for example).

The

Quoted 8 lines

script exception.h reads the header files (through gcc -aux-info) to generate some SWIG code for almost every interface returning an integer (this code converts a negative return value to the raising of a Python OSError exception).

In SWIG documentation [2] I have not found a way to automatically apply a %exception block to all functions matched by the pattern "it returns an integer". As you seem to believe I missed something,

I don't think you did.

could you please

Quoted 1 line

explain how you would proceed here?

Quoted 9 lines

Yeah that script is just generating a bunch of interface code, I would just remove that script
and write it by hand. The only downfall is that you would have to add a stub if you add something
to the header file, but I don't consider that a downside, I prefer to be explicit. Especially
considering they already had to put a function in the script to skip. I don't think the script provides
much value.

This kind of question is about the way maintainers want to manage the maintenance and development of the code. I understand the need to keep things simple, but how replacing the script with a "static file" (selinuxswig_python_exception.i, or its integration into selinuxswig_python.i) would keep working on the project simple or make it more complex is something I do not know.
An alternative approach would be something like projects using autotools
do: keep the script in the git tree but package releases with selinuxswig_python_exception.i (and semanage...exception.i) so that end users do not have to build it.

Nicolas