Skip to content

Commit f72d945

Browse files
authored
NodeUtils: do not pass stdin to group upcalls (#581)
Some commands consume stdin when they shouldn't, but we shouldn't have been giving stdin to upcalls in the first place. Reported-by: Kilian Cavalotti <[email protected]>
1 parent dde1481 commit f72d945

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

Diff for: lib/ClusterShell/NodeUtils.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@
4646
from string import Template
4747
from subprocess import Popen, PIPE
4848

49+
# compat with python 2.7, import directly above for 3.x
50+
try:
51+
from subprocess import DEVNULL
52+
except ImportError:
53+
DEVNULL = open(os.devnull, 'r')
54+
55+
# compat with python 2.7, use str directly in 3.x
4956
try:
5057
basestring
5158
except NameError:
@@ -202,8 +209,8 @@ def _upcall_read(self, cmdtpl, args=dict()):
202209
"""
203210
cmdline = Template(self.upcalls[cmdtpl]).safe_substitute(args)
204211
self.logger.debug("EXEC '%s'", cmdline)
205-
proc = Popen(cmdline, stdout=PIPE, shell=True, cwd=self.cfgdir,
206-
universal_newlines=True)
212+
proc = Popen(cmdline, stdin=DEVNULL, stdout=PIPE, shell=True,
213+
cwd=self.cfgdir, universal_newlines=True)
207214
output = proc.communicate()[0].strip()
208215
self.logger.debug("READ '%s'", output)
209216
if proc.returncode != 0:

0 commit comments

Comments
 (0)