From c60d25f0d180bd6ebb8413bd70d47da071271083 Mon Sep 17 00:00:00 2001 From: Jarrod Johnon Date: Thu, 22 Jan 2015 11:52:50 -0500 Subject: [PATCH] Fix confetty PTY handling in oneshot mode When asked to execute a command, do not mess with the terminal in a way that would incur SIGTTOU when run in background. This means that a backgrounded confetty can actually exit rather than block waiting to be run in foreground. This won't work with running a *console* in background, but that really doesn't make any sense. --- confluent_client/bin/confetty | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/confluent_client/bin/confetty b/confluent_client/bin/confetty index cc22e16d..42e2171f 100755 --- a/confluent_client/bin/confetty +++ b/confluent_client/bin/confetty @@ -57,6 +57,7 @@ import tty exitcode = 0 consoleonly = False consolename = "" +didconsole = False target = "/" path = os.path.dirname(os.path.realpath(__file__)) path = os.path.realpath(os.path.join(path, '..', 'lib', 'python')) @@ -445,6 +446,8 @@ def fullpath_target(currpath, forcepath=False): def startconsole(nodename): global inconsole global consolename + global didconsole + didconsole = True consolename = nodename tty.setraw(sys.stdin.fileno()) currfl = fcntl.fcntl(sys.stdin.fileno(), fcntl.F_GETFL) @@ -452,12 +455,14 @@ def startconsole(nodename): inconsole = True -def quitconfetty(code=0, fullexit=False): +def quitconfetty(code=0, fullexit=False, fixterm=True): global inconsole global currconsole - currfl = fcntl.fcntl(sys.stdin.fileno(), fcntl.F_GETFL) - fcntl.fcntl(sys.stdin.fileno(), fcntl.F_SETFL, currfl ^ os.O_NONBLOCK) - termios.tcsetattr(sys.stdin.fileno(), termios.TCSANOW, oldtcattr) + global didconsole + if fixterm or didconsole: + currfl = fcntl.fcntl(sys.stdin.fileno(), fcntl.F_GETFL) + fcntl.fcntl(sys.stdin.fileno(), fcntl.F_SETFL, currfl ^ os.O_NONBLOCK) + termios.tcsetattr(sys.stdin.fileno(), termios.TCSANOW, oldtcattr) if fullexit: sys.exit(code) else: @@ -567,7 +572,7 @@ if len(shellargs) == 1 and ' ' not in shellargs[0]: # straight to node console elif shellargs: command = " ".join(shellargs) do_command(command, netserver) - quitconfetty(fullexit=True) + quitconfetty(fullexit=True, fixterm=False) while inconsole or not doexit: if inconsole: rdylist, _, _ = select.select(