Fix is_root check on sudo

Add debugging and logging for is_root check.
Fix up logic so we check if sudo_user is non None
Now we can see disk info when running as root in the installer.

Signed-off-by: Ryan Harper <ryan.harper@canonical.com>
This commit is contained in:
Ryan Harper 2015-09-29 16:15:14 -05:00
parent 176e3727bc
commit ce133c6b06
2 changed files with 7 additions and 2 deletions

View File

@ -196,7 +196,9 @@ class FilesystemController(ControllerPolicy):
def show_disk_information(self, device):
""" Show disk information, requires sudo/root
"""
if not utils.is_root():
root = utils.is_root()
log.debug('show_disk_info is_root ? {}'.format(root))
if not root:
result = "hdparm requires root permission."
else:
out = utils.run_command("hdparm -i {}".format(device))

View File

@ -119,7 +119,10 @@ def is_root():
""" Returns root or if sudo user exists
"""
sudo_user = os.getenv('SUDO_USER', None)
euid = os.geteuid()
if os.geteuid() != 0 or not sudo_user:
log.debug('is_root: euid={} sudo_user={}'.format(
euid, sudo_user))
if euid != 0 or sudo_user is not None:
return False
return True