From 1ffd9a15a3a09a23806be63e3a635d208ce89d3e Mon Sep 17 00:00:00 2001 From: Edwin Eefting <edwin@datux.nl> Date: Mon, 18 May 2020 20:05:50 +0200 Subject: [PATCH] input=None would read stdin from terminal, causing hangs --- bin/zfs-autobackup | 3 ++- test_executenode.py | 3 +++ test_zfsnode.py | 10 +++++++++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/bin/zfs-autobackup b/bin/zfs-autobackup index 63b358b..7145706 100755 --- a/bin/zfs-autobackup +++ b/bin/zfs-autobackup @@ -364,7 +364,8 @@ class ExecuteNode(Logger): #determine stdin if input==None: - stdin=None + #NOTE: Not None, otherwise it reads stdin from terminal! + stdin=subprocess.PIPE elif isinstance(input,str) or type(input)=='unicode': self.debug("INPUT > \n"+input.rstrip()) stdin=subprocess.PIPE diff --git a/test_executenode.py b/test_executenode.py index 0b9cc6a..f532c28 100644 --- a/test_executenode.py +++ b/test_executenode.py @@ -47,6 +47,9 @@ class TestExecuteNode(unittest2.TestCase): with self.subTest("stdin input string"): self.assertEqual(node.run(["cat"], input="test"), ["test"]) + #command that wants input, while we dont have input, shouldnt hang forever. + with self.subTest("stdin process with input=None (shouldn't hang)"): + self.assertEqual(node.run(["cat"]), []) def test_basics_local(self): node=ExecuteNode(debug_output=True) diff --git a/test_zfsnode.py b/test_zfsnode.py index 7ca2aa4..0268d0e 100644 --- a/test_zfsnode.py +++ b/test_zfsnode.py @@ -106,9 +106,17 @@ test_target1 logger=Logger() description="[Source]" node=ZfsNode("test", logger, description=description) - print(node.supported_send_options) + # -D propably always supported + self.assertIn("-D", node.supported_send_options) + def test_supportedrecvoptions(self): + logger=Logger() + description="[Source]" + #NOTE: this couldnt hang via ssh if we dont close filehandles properly. (which was a previous bug) + node=ZfsNode("test", logger, description=description, ssh_to='localhost') + self.assertIsInstance(node.supported_recv_options, list) + if __name__ == '__main__':