diff options
author | Scott Moser <smoser@ubuntu.com> | 2014-07-24 19:41:10 -0400 |
---|---|---|
committer | Scott Moser <smoser@ubuntu.com> | 2014-07-24 19:41:10 -0400 |
commit | 4b8397a510c4ff6f903e98bef50d350410f41451 (patch) | |
tree | 8fe4f85db0c1b77c9ed2bc05314bfd89605cdcfa /cloudinit | |
parent | 986ee27cff1de8afdcbe72f464afef573790d373 (diff) | |
download | vyos-cloud-init-4b8397a510c4ff6f903e98bef50d350410f41451.tar.gz vyos-cloud-init-4b8397a510c4ff6f903e98bef50d350410f41451.zip |
SeLinuxGuard: remove invalid check for sanity around restorecon, fix test
previous commit occurred because the selinux test was failing
in a schroot where there was no /etc/hosts.
Now, fix that test more correctly, and fix some bad assumptions in
the SeLinuxGuard.
Diffstat (limited to 'cloudinit')
-rw-r--r-- | cloudinit/util.py | 34 |
1 files changed, 17 insertions, 17 deletions
diff --git a/cloudinit/util.py b/cloudinit/util.py index 06039ee2..bc681f4a 100644 --- a/cloudinit/util.py +++ b/cloudinit/util.py @@ -146,23 +146,23 @@ class SeLinuxGuard(object): return False def __exit__(self, excp_type, excp_value, excp_traceback): - if self.selinux and self.selinux.is_selinux_enabled(): - path = os.path.realpath(os.path.expanduser(self.path)) - # path should be a string, not unicode - path = str(path) - do_restore = False - try: - # See if even worth restoring?? - stats = os.lstat(path) - if stat.ST_MODE in stats: - self.selinux.matchpathcon(path, stats[stat.ST_MODE]) - do_restore = True - except OSError: - pass - if do_restore: - LOG.debug("Restoring selinux mode for %s (recursive=%s)", - path, self.recursive) - self.selinux.restorecon(path, recursive=self.recursive) + if not self.selinux or not self.selinux.is_selinux_enabled(): + return + if not os.path.lexists(self.path): + return + + path = os.path.realpath(self.path) + # path should be a string, not unicode + path = str(path) + try: + stats = os.lstat(path) + self.selinux.matchpathcon(path, stats[stat.ST_MODE]) + except OSError: + return + + LOG.debug("Restoring selinux mode for %s (recursive=%s)", + path, self.recursive) + self.selinux.restorecon(path, recursive=self.recursive) class MountFailedError(Exception): |