From 0dcd1442c9cb2d5dbe85faed4da0bd29b9920da6 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Wed, 8 Jun 2022 10:21:08 -0400 Subject: [PATCH] Avoid nodeshell/noderun getting stuck on stdin Some applications will tend to hang on stdin if stdin is readable. Provide /dev/null to suppress that behavior. --- confluent_client/bin/noderun | 5 ++++- confluent_client/bin/nodeshell | 7 ++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/confluent_client/bin/noderun b/confluent_client/bin/noderun index d859dc4b..df0d4a77 100755 --- a/confluent_client/bin/noderun +++ b/confluent_client/bin/noderun @@ -35,9 +35,12 @@ if path.startswith('/opt'): import confluent.client as client import confluent.sortutil as sortutil +devnull = None def run(): + global devnull + devnull = open(os.devnull, 'rb') argparser = optparse.OptionParser( usage="Usage: %prog [options] ", epilog="Expressions are the same as in attributes, e.g. " @@ -133,7 +136,7 @@ def run(): def run_cmdv(node, cmdv, all, pipedesc): try: nopen = subprocess.Popen( - cmdv, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + cmdv, stdin=devnull, stdout=subprocess.PIPE, stderr=subprocess.PIPE) except OSError as e: if e.errno == 2: sys.stderr.write('{0}: Unable to find local executable file "{1}"'.format(node, cmdv[0])) diff --git a/confluent_client/bin/nodeshell b/confluent_client/bin/nodeshell index 06e1efc6..f22c1993 100755 --- a/confluent_client/bin/nodeshell +++ b/confluent_client/bin/nodeshell @@ -34,10 +34,11 @@ if path.startswith('/opt'): import confluent.client as client import confluent.sortutil as sortutil - +devnull = None def run(): - + global devnull + devnull = open(os.devnull, 'rb') argparser = optparse.OptionParser( usage="Usage: %prog [options] noderange commandexpression", epilog="Expressions are the same as in attributes, e.g. " @@ -172,7 +173,7 @@ def run(): def run_cmdv(node, cmdv, all, pipedesc): nopen = subprocess.Popen( - cmdv, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + cmdv, stdin=devnull, stdout=subprocess.PIPE, stderr=subprocess.PIPE) pipedesc[nopen.stdout] = {'node': node, 'popen': nopen, 'type': 'stdout'} pipedesc[nopen.stderr] = {'node': node, 'popen': nopen,