mirror of
https://gitlab.com/apparmor/apparmor.git
synced 2025-03-04 16:35:02 +01:00
![]() Current libapparmor python bindings are very "unpythonic". Also lack ability to access "why" information in case of failure. In python when something fail the normal behaviour is exception to occur. In case of apparmor functions die silently and require user to verify returned value. And here comes second problem. In C api when return value is -1 (and the same value is returned in python API) we can access errno to get information why this occured. Unfortunately in python there is no way to access the same information. Pythonic way of accessing errno is via exception (which is never raised in python bindings currently). So the patch adds exceptions on failures. First %exception creates a wrapper that swig adds to each function listed below. Empty %exception causes that the rest of code (beside listed functions) won't be wrapped. How this works? Example on apparmor disabled system: Before: >>> LibAppArmor.aa_change_hat(hat, random.randint(1, sys.maxint)) -1 After: >>> LibAppArmor.aa_change_hat(hat, random.randint(1, sys.maxint)) Traceback (most recent call last): File "<stdin>", line 1, in <module> OSError: [Errno 22] Invalid argument so pythonic way of accessing "why": >>> try: ... LibAppArmor.aa_change_hat(hat, random.randint(1, sys.maxint)) ... except OSError, e: ... print e.errno ... 22 Signed-off-by: Arkadiusz Miśkiewicz <arekm@maven.pl> Acked-by: Steve Beattie <steve@nxnw.org> |
||
---|---|---|
.. | ||
doc | ||
include | ||
m4 | ||
src | ||
swig | ||
testsuite | ||
AUTHORS | ||
autogen.sh | ||
ChangeLog | ||
configure.ac | ||
COPYING.LGPL | ||
INSTALL | ||
libapparmor1.spec | ||
Makefile.am | ||
NEWS | ||
README |
What little documentation exists is in src/aalogparse.h. Please file bugs using https://bugs.launchpad.net/apparmor/+filebug