Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix sudo #704

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions devlib/host.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def execute(self, command, timeout=None, check_exit_code=True,
if self.unrooted:
raise TargetStableError('unrooted')
password = self._get_password()
command = "echo {} | sudo -k -p ' ' -S -- sh -c {}".format(quote(password), quote(command))
command = "echo {} | sudo -k -p '' -S -- sh -c {}".format(quote(password), quote(command))
ignore = None if check_exit_code else 'all'
try:
stdout, stderr = check_output(command, shell=True, timeout=timeout, ignore=ignore)
Expand All @@ -138,7 +138,7 @@ def background(self, command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, as
password = self._get_password()
# The sudo prompt will add a space on stderr, but we cannot filter
# it out here
command = "echo {} | sudo -k -p ' ' -S -- sh -c {}".format(quote(password), quote(command))
command = "echo {} | sudo -k -p '' -S -- sh -c {}".format(quote(password), quote(command))

# Make sure to get a new PGID so PopenBackgroundCommand() can kill
# all sub processes that could be started without troubles.
Expand Down
14 changes: 11 additions & 3 deletions devlib/target.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,9 +535,17 @@ async def check_connection(self):
"""
Check that the connection works without obvious issues.
"""
out = await self.execute.asyn('true', as_root=False)
if out.strip():
raise TargetStableError('The shell seems to not be functional and adds content to stderr: {}'.format(out))
async def check(**kwargs):
out = await self.execute.asyn('true', **kwargs)
if out:
raise TargetStableError('The shell seems to not be functional and adds content to stderr: {!r}'.format(out))

await check(as_root=False)
# If we are rooted, we usually run with sudo. Unfortunately, PAM
# modules can write random text to stdout such as:
# Your password will expire in XXX days.
if self.is_rooted:
await check(as_root=True)

def disconnect(self):
connections = self._conn.get_all_values()
Expand Down
2 changes: 1 addition & 1 deletion devlib/utils/ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
from devlib.connection import ConnectionBase, ParamikoBackgroundCommand, SSHTransferHandle


DEFAULT_SSH_SUDO_COMMAND = "sudo -k -p ' ' -S -- sh -c {}"
DEFAULT_SSH_SUDO_COMMAND = "sudo -k -p '' -S -- sh -c {}"


class _SSHEnv:
Expand Down