Skip to content

Commit

Permalink
driver/sshdriver: redirect /dev/null to stdin on run()
Browse files Browse the repository at this point in the history
By default, no redirection will occur. That means a command run on the
target consumes the stdin of our process. That is especially unfortunate
if we expect interactive input, such as for the ManualPowerDriver,
ManualSwitchDriver or in a REPL:

  shell.run_check("sleep 100 &")
  pidfile = "/tmp/pidfile"
  shell.run_check(f"pgrep sleep > {pidfile}")
  try:
      ssh.run(f"pwait --pidfile {pidfile}", timeout=1)
  except:
      from IPython import embed
      embed()

This example shows that not all input reaches the IPython REPL.

Fix this by redirecting /dev/null to stdin, so the command run via SSH
do not receive unexpected input and do not compete over it.

Signed-off-by: Bastian Krause <bst@pengutronix.de>
  • Loading branch information
Bastian-Krause committed Apr 3, 2024
1 parent a3c068f commit 1dbd699
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion labgrid/driver/sshdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ def _run(self, cmd, codec="utf-8", decodeerrors="strict", timeout=None):
stderr_pipe = subprocess.PIPE
try:
sub = subprocess.Popen(
complete_cmd, stdout=subprocess.PIPE, stderr=stderr_pipe
complete_cmd, stdin=subprocess.DEVNULL, stdout=subprocess.PIPE, stderr=stderr_pipe
)
except:
raise ExecutionError(
Expand Down

0 comments on commit 1dbd699

Please sign in to comment.