[apparmor] [patch] Get rid of global variable 'logger'

Christian Boltz apparmor at cboltz.de
Tue Oct 20 18:31:09 UTC 2015


Hello,

the global variable 'logger' in aa.py is only used by aa-genprof.

This patch changes aa_genprof to use the (new) logger_path() function,
and moves the code for finding the logger path to that function.

Also make the error message more helpful if logger can't be found.


[ 98-make-logger-non-global.diff ]

--- utils/aa-genprof    2015-06-25 21:32:37.420831338 +0200
+++ utils/aa-genprof    2015-10-20 20:06:34.874304017 +0200
@@ -136,7 +136,7 @@
         logmark = subprocess.check_output(['date | md5sum'], shell=True)
         logmark = logmark.decode('ascii').strip()
         logmark = re.search('^([0-9a-f]+)', logmark).groups()[0]
-        t=subprocess.call("%s -p kern.warn 'GenProf: %s'"%(apparmor.logger, logmark), shell=True)
+        t=subprocess.call("%s -p kern.warn 'GenProf: %s'"%(apparmor.logger_path(), logmark), shell=True)
 
     else:
         logmark = last_audit_entry_time()
--- utils/apparmor/aa.py        2015-10-20 19:43:26.675490318 +0200
+++ utils/apparmor/aa.py        2015-10-20 20:12:58.447357711 +0200
@@ -82,7 +82,6 @@
 repo_cfg = None
 
 parser = None
-logger = None
 profile_dir = None
 extra_profile_dir = None
 ### end our
@@ -4372,6 +4371,12 @@
 
     return None
 
+def logger_path():
+    logger = conf.find_first_file(cfg['settings']['logger']) or '/bin/logger'
+    if not os.path.isfile(logger) or not os.access(logger, os.EX_OK):
+        raise AppArmorException("Can't find logger!\nPlease make sure %s exists, or update the 'logger' path in logprof.conf." % logger)
+    return logger
+
 ######Initialisations######
 
 conf = apparmor.config.Config('ini', CONFDIR)
@@ -4392,6 +4397,3 @@
 if not os.path.isfile(parser) or not os.access(parser, os.EX_OK):
     raise AppArmorException('Can\'t find apparmor_parser')
 
-logger = conf.find_first_file(cfg['settings']['logger']) or '/bin/logger'
-if not os.path.isfile(logger) or not os.access(logger, os.EX_OK):
-    raise AppArmorException('Can\'t find logger')


Regards,

Christian Boltz
-- 
    Telefon
Gerät, das die Person am anderen Ende der Leitung bescheuert macht.
(Funktioniert in beide Richtungen)




More information about the AppArmor mailing list