提交 44e11064 编写于 作者: L Lukáš Doktor

utils.process: Fix can_sudo on broken systems

When the "sudo" is present in the PATH but is broken, the
"process.system" raises OSError. Let's address this issue and report
False in such case (as sudo is unusable)
Signed-off-by: NLukáš Doktor <ldoktor@redhat.com>
上级 77cf873d
......@@ -111,11 +111,14 @@ def can_sudo(cmd=None):
except path.CmdNotFoundError:
return False
if cmd: # Am I able to run the cmd or plain sudo id?
return not system(cmd, ignore_status=True, sudo=True)
elif system_output("id -u", ignore_status=True, sudo=True).strip() == "0":
return True
else:
try:
if cmd: # Am I able to run the cmd or plain sudo id?
return not system(cmd, ignore_status=True, sudo=True)
elif system_output("id -u", ignore_status=True, sudo=True).strip() == "0":
return True
else:
return False
except OSError: # Broken sudo binary
return False
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册