python/semanage: Fix logger class definition
PATCH 1/1 python/semanage: Fix logger class definition
Test if audit module is enabled so that logger class is defined correctly.
Fixes:
"semanage fcontext -l" fails with "OSError: Protocol not supported" when booting with audit=0
--- python/semanage/seobject.py | 2 ++ 1 file changed, 2 insertions(+)
python/semanage/seobject.py +2 -0
@@ -101,6 +101,8 @@ ftype_to_audit = {"": "any", try: import audit + #test if audit module is enabled + audit.audit_close(audit.audit_open()) class logger:
Signature · 1 line
2.14.3
Quoted 18 lines · Vit Mojzis
Test if audit module is enabled so that logger class is defined correctly.
Fixes:
"semanage fcontext -l" fails with "OSError: Protocol not supported" when booting with audit=0Signed-off-by Vit Mojzis <[email protected]>--- python/semanage/seobject.py | 2 ++ 1 file changed, 2 insertions(+)python/semanage/seobject.py +0
-0
python/semanage/seobject.py ftype_to_audit = {"": "any", · line 108
Quoted 8 lines
python/semanage/seobject.py +2
-0@@ -101,6 +101,8 @@ ftype_to_audit = {"": "any", try: import audit + #test if audit module is enabled + audit.audit_close(audit.audit_open()) class logger:
This looks good to me (Ack). For future reference, I was wondering whether audit.audit_open() returns -1 or raises an exception if it fails to open the audit log, and found the answer in audit's source code (it raises an OSError, as expected [1], so the new code is fine).
While reviewing your patch, I encountered the bare "except:" right after the definition of class logger. The exceptions which cause the use of the fail-over logger class are not explicitly written and this could cause issues, for example when someone tries to interrupt the program with Ctrl-C while the code executes. Would it be possible to replace this "except:" with "except ImportError, OSError:"? (This could be done in another patch).
Thanks,
Nicolas
[1] https://github.com/linux-audit/audit-userspace/blob/v2.8.4/bindings/swig/src/auditswig.i#L27-L33)
PATCH 1/1 python/semanage: Replace bare except with specific one
The corresponding except clause should only be used for exceptions caused by audit module error or unavailability.
--- python/semanage/seobject.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
python/semanage/seobject.py +1 -1
@@ -140,7 +140,7 @@ try: self.log_list = [] self.log_change_list = [] -except: +except OSError, ImportError: class logger: def __init__(self):
Signature · 1 line
2.14.3
Re: [PATCH] python/semanage: Replace bare except with specific one
Quoted 4 lines · Vit Mojzis
The corresponding except clause should only be used for exceptions caused by audit module error or unavailability.
Signed-off-by Vit Mojzis <[email protected]>
Thanks. I applied your two patches.
Nicolas