~tyhicks/apparmor/stacking

Viewing all changes in revision 3386.

  • Committer: Christian Boltz
  • Date: 2016-02-21 20:48:57 UTC
  • Revision ID: apparmor@cboltz.de-20160221204857-jovq0nopolt2n4bz
aa.py get_output(): raise exception on non-executable or non-existing programs

If the program specified as get_output param isn't executable or doesn't
exist at all, get_output() returns with ret = -1.

Raising an exception looks like a better option, especially because
other possible exec failures already raise an exception ("Unable to
fork").

Note: get_output is only used by get_reqs() which also does the
os.access() check for x permissions (and raises an exception), so in
practise raising an exception in get_output() doesn't change anything.


This change also allows to rewrite and simplify get_output() quite a bit.


Another minor change (and fix) is in the removal of the last line. The
old code removed the last line if output contained at least two items.
This had two not-so-nice effects:
- an empty output resulted in [''] instead of []
- if a command didn't add a \n on the last line, this line was deleted
  nevertheless

The patch changes that to always remove the last line if it is empty,
which fixes both issues mentioned above.


Also add a test to ensure the exception is really raised, and adjust the
test that expects an empty stdout.


Acked-by: Kshitij Gupta <kgupta8592@gmail.com>

expand all expand all

Show diffs side-by-side

added added

removed removed

Lines of Context: